term

package
v0.0.0-...-c1b70a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2023 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SBox_Horiz = 0x2501 //single line
	SBox_Vert  = 0x2503
	SBox_UL    = 0x250F
	SBox_UR    = 0x2513
	SBox_LL    = 0x2517
	SBox_LR    = 0x251B

	DBox_Horiz = 0x2550 //double line
	DBox_Vert  = 0x2551
	DBox_UL    = 0x2554
	DBox_UR    = 0x2557
	DBox_LL    = 0x255A
	DBox_LR    = 0x255D

	BBox_Horiz = 0x2509 //broken line
	BBox_Vert  = 0x250B
	BBox_UL    = 0x250F
	BBox_UR    = 0x2513
	BBox_LL    = 0x2517
	BBox_LR    = 0x251B

	HBox_Horiz = 0x2501 //horiz only
	HBox_Vert  = 0x20
	HBox_UL    = 0x20
	HBox_UR    = 0x20
	HBox_LL    = 0x20
	HBox_LR    = 0x20
)
View Source
const CSI = "\x1b\x5b"

Variables

This section is empty.

Functions

func CHA

func CHA(n int) string

CHA - Cursor Horizontal Absolute

func CNL

func CNL(n int) string

CNL - Cursor Next Line

func CPL

func CPL(n int) string

CPL - Cursor Previous Line

func CSIEnd

func CSIEnd() string

func CSIStart

func CSIStart() string

func CUB

func CUB(n int) string

CUB - Cursor Back

func CUD

func CUD(n int) string

CUD - Cursor Down

func CUF

func CUF(n int) string

CUF - Cursor Forward

func CUP

func CUP(c, r int) string

CUP - Cursor Position

func CUU

func CUU(n int) string

CUU - Cursor Up

func ED

func ED(n EraseType) string

ED - Erase in Display If n is 0, clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS).

func EL

func EL(n EraseType) string

EL - Erase in Line If n is 0 (or missing), clear from cursor to the end of the line. If n is 1, clear from cursor to beginning of the line. If n is 2, clear entire line. Cursor position does not change.

func GetTermios

func GetTermios(fd uintptr) *syscall.Termios

func HVP

func HVP(m, n int) string

HVP - Horizontal Vertical Position

func SD

func SD(n int) string

SD - Scroll Down

func SGR

func SGR(n ...SGRType) string

SGR - Select Graphic Rendition, other data may follow

func SU

func SU(n int) string

SU - Scroll Up

func SetRaw

func SetRaw(term *syscall.Termios)

func SetTermios

func SetTermios(fd uintptr, term *syscall.Termios)

Types

type Attribute

type Attribute uint64
const (
	ColorDefault Attribute = iota
	ColorBlack
	ColorRed
	ColorGreen
	ColorYellow
	ColorBlue
	ColorMagenta
	ColorCyan
	ColorWhite
	ColorDarkGray
	ColorLightRed
	ColorLightGreen
	ColorLightYellow
	ColorLightBlue
	ColorLightMagenta
	ColorLightCyan
	ColorLightGray
)

Cell colors, you can combine a color with multiple attributes using bitwise OR ('|').

const (
	AttrBold Attribute = 1 << (iota + 9)
	AttrBlink
	AttrHidden
	AttrDim
	AttrUnderline
	AttrCursive
	AttrReverse
)

Cell attributes, it is possible to use multiple attributes by combining them using bitwise OR ('|'). Although, colors cannot be combined. But you can combine attributes and a single color.

It's worth mentioning that some platforms don't support certain attributes. For example windows console doesn't support AttrUnderline. And on some terminals applying AttrBold to background may result in blinking text. Use them with caution and test your code on various terminals.

type EraseType

type EraseType int
const (
	EraseToEnd   EraseType = 0
	EraseToBegin EraseType = 1
	EraseAll     EraseType = 2
)

type Event

type Event struct {
	Type   EventType // one of Event* constants
	Mod    Modifier  // one of Mod* constants or 0
	Key    Key       // one of Key* constants, invalid if 'Ch' is not 0
	Ch     rune      // a unicode character
	Width  int       // width of the screen
	Height int       // height of the screen
	Err    error     // error in case if input failed
	MouseX int       // x coord of mouse
	MouseY int       // y coord of mouse
	N      int       // number of bytes written when getting a raw event
}

This type represents a term event. The 'Mod', 'Key' and 'Ch' fields are valid if 'Type' is EventKey. The 'Width' and 'Height' fields are valid if 'Type' is EventResize. The 'Err' field is valid if 'Type' is EventError.

func (*Event) String

func (ev *Event) String() string

type EventType

type EventType uint8
const (
	EventKey EventType = iota
	EventResize
	EventMouse
	EventError
	EventInterrupt
	EventRaw
	EventNone
)

type InputMode

type InputMode int
const (
	InputEsc InputMode = 1 << iota
	InputAlt
	InputMouse
	InputCurrent InputMode = 0
)

Input mode. See SetInputMode function.

type Key

type Key uint16
const (
	KeyF1 Key = 0xFFFF - iota
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF10
	KeyF11
	KeyF12
	KeyInsert
	KeyDelete
	KeyHome
	KeyEnd
	KeyPgup
	KeyPgdn
	KeyArrowUp
	KeyArrowDown
	KeyArrowLeft
	KeyArrowRight

	MouseLeft
	MouseMiddle
	MouseRight
	MouseRelease
	MouseWheelUp
	MouseWheelDown
	KeyError
)

Key constants, see Event.Key field.

const (
	KeyCtrlTilde      Key = 0x00
	KeyCtrl2          Key = 0x00
	KeyCtrlSpace      Key = 0x00
	KeyCtrlA          Key = 0x01
	KeyCtrlB          Key = 0x02
	KeyCtrlC          Key = 0x03
	KeyCtrlD          Key = 0x04
	KeyCtrlE          Key = 0x05
	KeyCtrlF          Key = 0x06
	KeyCtrlG          Key = 0x07
	KeyBackspace      Key = 0x08
	KeyCtrlH          Key = 0x08
	KeyTab            Key = 0x09
	KeyCtrlI          Key = 0x09
	KeyCtrlJ          Key = 0x0A
	KeyCtrlK          Key = 0x0B
	KeyCtrlL          Key = 0x0C
	KeyEnter          Key = 0x0D
	KeyCtrlM          Key = 0x0D
	KeyCtrlN          Key = 0x0E
	KeyCtrlO          Key = 0x0F
	KeyCtrlP          Key = 0x10
	KeyCtrlQ          Key = 0x11
	KeyCtrlR          Key = 0x12
	KeyCtrlS          Key = 0x13
	KeyCtrlT          Key = 0x14
	KeyCtrlU          Key = 0x15
	KeyCtrlV          Key = 0x16
	KeyCtrlW          Key = 0x17
	KeyCtrlX          Key = 0x18
	KeyCtrlY          Key = 0x19
	KeyCtrlZ          Key = 0x1A
	KeyEsc            Key = 0x1B
	KeyCtrlLsqBracket Key = 0x1B
	KeyCtrl3          Key = 0x1B
	KeyCtrl4          Key = 0x1C
	KeyCtrlBackslash  Key = 0x1C
	KeyCtrl5          Key = 0x1D
	KeyCtrlRsqBracket Key = 0x1D
	KeyCtrl6          Key = 0x1E
	KeyCtrl7          Key = 0x1F
	KeyCtrlSlash      Key = 0x1F
	KeyCtrlUnderscore Key = 0x1F
	KeySpace          Key = 0x20
	KeyBackspace2     Key = 0x7F
	KeyCtrl8          Key = 0x7F
)

func StringToKey

func StringToKey(s string) Key

type Modifier

type Modifier uint8
const (
	ModAlt Modifier = 1 << iota
	ModMotion
)

type OutputMode

type OutputMode int
const (
	OutputCurrent OutputMode = iota
	OutputNormal
	Output256
	Output216
	OutputGrayscale
	OutputRGB
)

Output mode. See SetOutputMode function.

type SGRType

type SGRType int
const (
	SGR_Off          SGRType = 0  // All attributes off
	SGR_Bold         SGRType = 1  // Bold
	SGR_Underline    SGRType = 4  // Underline
	SGR_Blinking     SGRType = 5  // Blinking
	SGR_Negative     SGRType = 7  // Negative image
	SGR_Invisible    SGRType = 8  // Invisible image
	SGR_BoldOff      SGRType = 22 // Bold off
	SGR_UnderlineOff SGRType = 24 // Underline off
	SGR_BlinkingOff  SGRType = 25 // Blinking off
	SGR_NegativeOff  SGRType = 27 // Negative image off
	SGR_InvisibleOff SGRType = 28 // Invisible image off
)

type Screen

type Screen struct {
	Rows int
	Cols int
	// contains filtered or unexported fields
}

func NewScreen

func NewScreen(c, r int) *Screen

func (*Screen) Blank

func (scr *Screen) Blank()

func (*Screen) Fill

func (scr *Screen) Fill(ru rune)

func (*Screen) Get

func (scr *Screen) Get(c, r int) rune

func (*Screen) GetBytes

func (scr *Screen) GetBytes() []byte

func (*Screen) Set

func (scr *Screen) Set(c, r int, ch rune)

func (*Screen) String

func (scr *Screen) String() string

type TermType

type TermType int
const (
	Web TermType = iota
	Pty
)

type Terminal

type Terminal struct {
	Kind   TermType
	Input  *bufio.Reader
	Output *bufio.Writer
	Origin *syscall.Termios
	// sigwinch       = make(chan os.Signal, 1)
	// sigio          = make(chan os.Signal, 1)
	Quit     chan int
	Contents strings.Builder
	ScrBuf   *Screen
	Conn     *websocket.Conn
	CurCol   int
	CurRow   int
	NumCol   int
	NumRow   int
}

func NewTerminal

func NewTerminal(height int, width int, kind TermType) (t *Terminal)

Init()

func (*Terminal) Clear

func (t *Terminal) Clear(fg, bg Attribute)

func (*Terminal) Close

func (t *Terminal) Close()

func (*Terminal) Flush

func (t *Terminal) Flush()

func (*Terminal) IsPty

func (t *Terminal) IsPty() bool

func (*Terminal) IsWeb

func (t *Terminal) IsWeb() bool

func (*Terminal) SetCell

func (t *Terminal) SetCell(c, r int, ch rune, fgcolor, bgcolor Attribute)

func (*Terminal) SetCursor

func (t *Terminal) SetCursor(r, c int)

func (*Terminal) SetInputMode

func (t *Terminal) SetInputMode(m InputMode)

termbox.InputAlt | termbox.InputEsc | termbox.InputMouse

func (*Terminal) SetOutputMode

func (t *Terminal) SetOutputMode(m OutputMode)

func (*Terminal) Size

func (t *Terminal) Size() (int, int)

termbox.Size()

func (*Terminal) Write

func (t *Terminal) Write(b []byte)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL