Documentation
¶
Overview ¶
Package vt provides a virtual terminal implementation. SKIP: Fix typecheck errors - function signature mismatches and undefined types
Package vt is a virtual terminal emulator that can be used to emulate a modern terminal application.
Index ¶
- Constants
- Variables
- type ApcHandler
- type Buffer
- func (b *Buffer) DeleteCell(x, y, n int, c *uv.Cell)
- func (b *Buffer) DeleteCellRect(x, y, n int, c *uv.Cell, rect uv.Rectangle)
- func (b *Buffer) DeleteLine(y, n int, c *uv.Cell)
- func (b *Buffer) DeleteLineRect(y, n int, c *uv.Cell, rect uv.Rectangle)
- func (b *Buffer) InsertCell(x, y, n int, c *uv.Cell)
- func (b *Buffer) InsertCellRect(x, y, n int, c *uv.Cell, rect uv.Rectangle)
- func (b *Buffer) InsertLine(y, n int, c *uv.Cell)
- func (b *Buffer) InsertLineRect(y, n int, c *uv.Cell, rect uv.Rectangle)
- type Callbacks
- type CcHandler
- type CellDamage
- type CharSet
- type CsiHandler
- type Cursor
- type CursorStyle
- type Damage
- type DcsHandler
- type Emulator
- func (e *Emulator) BackgroundColor() color.Color
- func (e *Emulator) Blur()
- func (e *Emulator) Bounds() uv.Rectangle
- func (e *Emulator) CellAt(x, y int) *uv.Cell
- func (e *Emulator) ClearScrollback()
- func (e *Emulator) Close() error
- func (e *Emulator) CursorColor() color.Color
- func (e *Emulator) CursorPosition() uv.Position
- func (e *Emulator) Draw(scr uv.Screen, area uv.Rectangle)
- func (e *Emulator) Focus()
- func (e *Emulator) ForegroundColor() color.Color
- func (e *Emulator) Height() int
- func (e *Emulator) IndexedColor(i int) color.Color
- func (e *Emulator) InputPipe() io.Writer
- func (e *Emulator) IsAltScreen() bool
- func (e *Emulator) Paste(text string)
- func (e *Emulator) Read(p []byte) (n int, err error)
- func (h *Emulator) RegisterApcHandler(handler ApcHandler)
- func (h *Emulator) RegisterCsiHandler(cmd int, handler CsiHandler)
- func (h *Emulator) RegisterDcsHandler(cmd int, handler DcsHandler)
- func (h *Emulator) RegisterEscHandler(cmd int, handler EscHandler)
- func (h *Emulator) RegisterOscHandler(cmd int, handler OscHandler)
- func (h *Emulator) RegisterPmHandler(handler PmHandler)
- func (h *Emulator) RegisterSosHandler(handler SosHandler)
- func (e *Emulator) Render() string
- func (e *Emulator) Resize(width int, height int)
- func (e *Emulator) Scrollback() *Scrollback
- func (e *Emulator) ScrollbackCellAt(x, y int) *uv.Cell
- func (e *Emulator) ScrollbackLen() int
- func (e *Emulator) SendKey(k uv.KeyEvent)
- func (e *Emulator) SendKeys(keys ...uv.KeyEvent)
- func (e *Emulator) SendMouse(m Mouse)
- func (e *Emulator) SendText(text string)
- func (e *Emulator) SetBackgroundColor(c color.Color)
- func (e *Emulator) SetCallbacks(cb Callbacks)
- func (e *Emulator) SetCell(x, y int, c *uv.Cell)
- func (e *Emulator) SetCursorColor(c color.Color)
- func (e *Emulator) SetDefaultBackgroundColor(c color.Color)
- func (e *Emulator) SetDefaultCursorColor(c color.Color)
- func (e *Emulator) SetDefaultForegroundColor(c color.Color)
- func (e *Emulator) SetForegroundColor(c color.Color)
- func (e *Emulator) SetIndexedColor(i int, c color.Color)
- func (e *Emulator) SetLogger(l Logger)
- func (e *Emulator) SetScrollbackSize(maxLines int)
- func (e *Emulator) String() string
- func (e *Emulator) Touched() []*uv.LineData
- func (e *Emulator) Width() int
- func (e *Emulator) WidthMethod() uv.WidthMethod
- func (e *Emulator) Write(p []byte) (n int, err error)
- func (e *Emulator) WriteString(s string) (n int, err error)
- type EscHandler
- type KeyMod
- type KeyPressEvent
- type Logger
- type Mouse
- type MouseButton
- type MouseClick
- type MouseMotion
- type MouseRelease
- type MouseWheel
- type MoveDamage
- type OscHandler
- type PmHandler
- type RectDamage
- type SafeEmulator
- func (se *SafeEmulator) BackgroundColor() color.Color
- func (se *SafeEmulator) CellAt(x, y int) *uv.Cell
- func (se *SafeEmulator) ClearScrollback()
- func (se *SafeEmulator) CursorColor() color.Color
- func (se *SafeEmulator) CursorPosition() uv.Position
- func (se *SafeEmulator) Draw(s uv.Screen, a uv.Rectangle)
- func (se *SafeEmulator) ForegroundColor() color.Color
- func (se *SafeEmulator) Height() int
- func (se *SafeEmulator) IndexedColor(index int) color.Color
- func (se *SafeEmulator) IsAltScreen() bool
- func (se *SafeEmulator) Paste(text string)
- func (se *SafeEmulator) Read(p []byte) (int, error)
- func (h SafeEmulator) RegisterApcHandler(handler ApcHandler)
- func (h SafeEmulator) RegisterCsiHandler(cmd int, handler CsiHandler)
- func (h SafeEmulator) RegisterDcsHandler(cmd int, handler DcsHandler)
- func (h SafeEmulator) RegisterEscHandler(cmd int, handler EscHandler)
- func (h SafeEmulator) RegisterOscHandler(cmd int, handler OscHandler)
- func (h SafeEmulator) RegisterPmHandler(handler PmHandler)
- func (h SafeEmulator) RegisterSosHandler(handler SosHandler)
- func (se *SafeEmulator) Render() string
- func (se *SafeEmulator) Resize(w, h int)
- func (se *SafeEmulator) Scrollback() *Scrollback
- func (se *SafeEmulator) ScrollbackCellAt(x, y int) *uv.Cell
- func (se *SafeEmulator) ScrollbackLen() int
- func (se *SafeEmulator) SendKey(key uv.KeyEvent)
- func (se *SafeEmulator) SendMouse(mouse uv.MouseEvent)
- func (se *SafeEmulator) SendText(text string)
- func (se *SafeEmulator) SetBackgroundColor(color color.Color)
- func (se *SafeEmulator) SetCell(x, y int, cell *uv.Cell)
- func (se *SafeEmulator) SetCursorColor(color color.Color)
- func (se *SafeEmulator) SetForegroundColor(color color.Color)
- func (se *SafeEmulator) SetIndexedColor(index int, color color.Color)
- func (se *SafeEmulator) SetScrollbackSize(maxLines int)
- func (se *SafeEmulator) Touched() []*uv.LineData
- func (se *SafeEmulator) Width() int
- func (se *SafeEmulator) Write(data []byte) (int, error)
- type Screen
- func (s *Screen) Bounds() uv.Rectangle
- func (s *Screen) CellAt(x int, y int) *uv.Cell
- func (s *Screen) Clear()
- func (s *Screen) ClearArea(area uv.Rectangle)
- func (s *Screen) ClearTouched()
- func (s *Screen) ClearWithScrollback()
- func (s *Screen) Cursor() Cursor
- func (s *Screen) CursorPosition() (x, y int)
- func (s *Screen) DeleteCell(n int)
- func (s *Screen) DeleteLine(n int) bool
- func (s *Screen) Fill(c *uv.Cell)
- func (s *Screen) FillArea(c *uv.Cell, area uv.Rectangle)
- func (s *Screen) Height() int
- func (s *Screen) HideCursor()
- func (s *Screen) InsertCell(n int)
- func (s *Screen) InsertLine(n int) bool
- func (s *Screen) Reset()
- func (s *Screen) Resize(width int, height int)
- func (s *Screen) RestoreCursor()
- func (s *Screen) SaveCursor()
- func (s *Screen) ScrollDown(n int)
- func (s *Screen) ScrollRegion() uv.Rectangle
- func (s *Screen) ScrollUp(n int)
- func (s *Screen) Scrollback() *Scrollback
- func (s *Screen) SetCell(x, y int, c *uv.Cell)
- func (s *Screen) SetScrollback(sb *Scrollback)
- func (s *Screen) SetScrollbackSize(maxLines int)
- func (s *Screen) ShowCursor()
- func (s *Screen) Touched() []*uv.LineData
- func (s *Screen) Width() int
- type ScreenDamage
- type ScrollDamage
- type Scrollback
- func (s *Scrollback) CellAt(x, y int) *uv.Cell
- func (s *Scrollback) Clear()
- func (s *Scrollback) Len() int
- func (s *Scrollback) Line(index int) uv.Line
- func (s *Scrollback) Lines() []uv.Line
- func (s *Scrollback) MaxLines() int
- func (s *Scrollback) Push(line uv.Line)
- func (s *Scrollback) PushN(buf *uv.RenderBuffer, y, n int)
- func (s *Scrollback) SetMaxLines(maxLines int)
- type SosHandler
- type Terminal
Constants ¶
const ( ModShift = uv.ModShift ModAlt = uv.ModAlt ModCtrl = uv.ModCtrl ModMeta = uv.ModMeta )
Modifier keys.
const ( KeyExtended = uv.KeyExtended KeyUp = uv.KeyUp KeyDown = uv.KeyDown KeyRight = uv.KeyRight KeyLeft = uv.KeyLeft KeyBegin = uv.KeyBegin KeyFind = uv.KeyFind KeyInsert = uv.KeyInsert KeyDelete = uv.KeyDelete KeySelect = uv.KeySelect KeyPgUp = uv.KeyPgUp KeyPgDown = uv.KeyPgDown KeyHome = uv.KeyHome KeyEnd = uv.KeyEnd KeyKpEnter = uv.KeyKpEnter KeyKpEqual = uv.KeyKpEqual KeyKpMultiply = uv.KeyKpMultiply KeyKpPlus = uv.KeyKpPlus KeyKpComma = uv.KeyKpComma KeyKpMinus = uv.KeyKpMinus KeyKpDecimal = uv.KeyKpDecimal KeyKpDivide = uv.KeyKpDivide KeyKp0 = uv.KeyKp0 KeyKp1 = uv.KeyKp1 KeyKp2 = uv.KeyKp2 KeyKp3 = uv.KeyKp3 KeyKp4 = uv.KeyKp4 KeyKp5 = uv.KeyKp5 KeyKp6 = uv.KeyKp6 KeyKp7 = uv.KeyKp7 KeyKp8 = uv.KeyKp8 KeyKp9 = uv.KeyKp9 KeyKpSep = uv.KeyKpSep KeyKpUp = uv.KeyKpUp KeyKpDown = uv.KeyKpDown KeyKpLeft = uv.KeyKpLeft KeyKpRight = uv.KeyKpRight KeyKpPgUp = uv.KeyKpPgUp KeyKpPgDown = uv.KeyKpPgDown KeyKpHome = uv.KeyKpHome KeyKpEnd = uv.KeyKpEnd KeyKpInsert = uv.KeyKpInsert KeyKpDelete = uv.KeyKpDelete KeyKpBegin = uv.KeyKpBegin KeyF1 = uv.KeyF1 KeyF2 = uv.KeyF2 KeyF3 = uv.KeyF3 KeyF4 = uv.KeyF4 KeyF5 = uv.KeyF5 KeyF6 = uv.KeyF6 KeyF7 = uv.KeyF7 KeyF8 = uv.KeyF8 KeyF9 = uv.KeyF9 KeyF10 = uv.KeyF10 KeyF11 = uv.KeyF11 KeyF12 = uv.KeyF12 KeyF13 = uv.KeyF13 KeyF14 = uv.KeyF14 KeyF15 = uv.KeyF15 KeyF16 = uv.KeyF16 KeyF17 = uv.KeyF17 KeyF18 = uv.KeyF18 KeyF19 = uv.KeyF19 KeyF20 = uv.KeyF20 KeyF21 = uv.KeyF21 KeyF22 = uv.KeyF22 KeyF23 = uv.KeyF23 KeyF24 = uv.KeyF24 KeyF25 = uv.KeyF25 KeyF26 = uv.KeyF26 KeyF27 = uv.KeyF27 KeyF28 = uv.KeyF28 KeyF29 = uv.KeyF29 KeyF30 = uv.KeyF30 KeyF31 = uv.KeyF31 KeyF32 = uv.KeyF32 KeyF33 = uv.KeyF33 KeyF34 = uv.KeyF34 KeyF35 = uv.KeyF35 KeyF36 = uv.KeyF36 KeyF37 = uv.KeyF37 KeyF38 = uv.KeyF38 KeyF39 = uv.KeyF39 KeyF40 = uv.KeyF40 KeyF41 = uv.KeyF41 KeyF42 = uv.KeyF42 KeyF43 = uv.KeyF43 KeyF44 = uv.KeyF44 KeyF45 = uv.KeyF45 KeyF46 = uv.KeyF46 KeyF47 = uv.KeyF47 KeyF48 = uv.KeyF48 KeyF49 = uv.KeyF49 KeyF50 = uv.KeyF50 KeyF51 = uv.KeyF51 KeyF52 = uv.KeyF52 KeyF53 = uv.KeyF53 KeyF54 = uv.KeyF54 KeyF55 = uv.KeyF55 KeyF56 = uv.KeyF56 KeyF57 = uv.KeyF57 KeyF58 = uv.KeyF58 KeyF59 = uv.KeyF59 KeyF60 = uv.KeyF60 KeyF61 = uv.KeyF61 KeyF62 = uv.KeyF62 KeyF63 = uv.KeyF63 KeyCapsLock = uv.KeyCapsLock KeyScrollLock = uv.KeyScrollLock KeyNumLock = uv.KeyNumLock KeyPrintScreen = uv.KeyPrintScreen KeyPause = uv.KeyPause KeyMenu = uv.KeyMenu KeyMediaPlay = uv.KeyMediaPlay KeyMediaPause = uv.KeyMediaPause KeyMediaPlayPause = uv.KeyMediaPlayPause KeyMediaReverse = uv.KeyMediaReverse KeyMediaStop = uv.KeyMediaStop KeyMediaFastForward = uv.KeyMediaFastForward KeyMediaRewind = uv.KeyMediaRewind KeyMediaNext = uv.KeyMediaNext KeyMediaPrev = uv.KeyMediaPrev KeyMediaRecord = uv.KeyMediaRecord KeyLowerVol = uv.KeyLowerVol KeyRaiseVol = uv.KeyRaiseVol KeyMute = uv.KeyMute KeyLeftShift = uv.KeyLeftShift KeyLeftAlt = uv.KeyLeftAlt KeyLeftCtrl = uv.KeyLeftCtrl KeyLeftSuper = uv.KeyLeftSuper KeyLeftHyper = uv.KeyLeftHyper KeyLeftMeta = uv.KeyLeftMeta KeyRightShift = uv.KeyRightShift KeyRightAlt = uv.KeyRightAlt KeyRightCtrl = uv.KeyRightCtrl KeyRightSuper = uv.KeyRightSuper KeyRightHyper = uv.KeyRightHyper KeyRightMeta = uv.KeyRightMeta KeyIsoLevel3Shift = uv.KeyIsoLevel3Shift KeyIsoLevel5Shift = uv.KeyIsoLevel5Shift KeyBackspace = uv.KeyBackspace KeyTab = uv.KeyTab KeyEnter = uv.KeyEnter KeyReturn = uv.KeyReturn KeyEscape = uv.KeyEscape KeyEsc = uv.KeyEsc KeySpace = uv.KeySpace )
Key codes.
const ( MouseNone = uv.MouseNone MouseLeft = uv.MouseLeft MouseMiddle = uv.MouseMiddle MouseRight = uv.MouseRight MouseWheelUp = uv.MouseWheelUp MouseWheelDown = uv.MouseWheelDown MouseWheelLeft = uv.MouseWheelLeft MouseWheelRight = uv.MouseWheelRight MouseBackward = uv.MouseBackward MouseForward = uv.MouseForward MouseButton10 = uv.MouseButton10 MouseButton11 = uv.MouseButton11 )
Mouse event buttons
This is based on X11 mouse button codes.
1 = left button 2 = middle button (pressing the scroll wheel) 3 = right button 4 = turn scroll wheel up 5 = turn scroll wheel down 6 = push scroll wheel left 7 = push scroll wheel right 8 = 4th button (aka browser backward button) 9 = 5th button (aka browser forward button) 10 11
Other buttons are not supported.
const DefaultScrollbackSize = 10000
DefaultScrollbackSize is the default maximum number of lines in the scrollback buffer.
Variables ¶
var ( UK = CharSet{ '$': "£", } SpecialDrawing = CharSet{ '`': "◆", 'a': "▒", 'b': "␉", 'c': "␌", 'd': "␍", 'e': "␊", 'f': "°", 'g': "±", 'h': "", 'i': "␋", 'j': "┘", 'k': "┐", 'l': "┌", 'm': "└", 'n': "┼", 'o': "⎺", 'p': "⎻", 'q': "─", 'r': "⎼", 's': "⎽", 't': "├", 'u': "┤", 'v': "┴", 'w': "┬", 'x': "│", 'y': "⩽", 'z': "⩾", '{': "π", '|': "≠", '}': "£", '~': "·", } )
Character sets.
Functions ¶
This section is empty.
Types ¶
type ApcHandler ¶
ApcHandler is a function that handles an APC escape sequence.
type Buffer ¶
Buffer is a terminal cell buffer.
func (*Buffer) DeleteCell ¶
DeleteCell deletes cells at the given position, with the given optional cell, within the specified rectangles. If no rectangles are specified, it deletes cells in the entire buffer. This follows terminal ansi.DCH behavior.
func (*Buffer) DeleteCellRect ¶
DeleteCellRect deletes cells at the given position, with the given optional cell, within the rectangle bounds. Only cells within the rectangle's bounds are affected, following terminal ansi.DCH behavior.
func (*Buffer) DeleteLine ¶
DeleteLine deletes n lines at the given line position, with the given optional cell, within the specified rectangles. If no rectangles are specified, it deletes lines in the entire buffer.
func (*Buffer) DeleteLineRect ¶
DeleteLineRect deletes lines at the given line position, with the given optional cell, within the rectangle bounds. Only cells within the rectangle's bounds are affected. Lines are shifted up within the bounds and new blank lines are created at the bottom. This follows terminal ansi.DL behavior.
func (*Buffer) InsertCell ¶
InsertCell inserts new cells at the given position, with the given optional cell, within the specified rectangles. If no rectangles are specified, it inserts cells in the entire buffer. This follows terminal ansi.ICH behavior.
func (*Buffer) InsertCellRect ¶
InsertCellRect inserts new cells at the given position, with the given optional cell, within the rectangle bounds. Only cells within the rectangle's bounds are affected, following terminal ansi.ICH behavior.
func (*Buffer) InsertLine ¶
InsertLine inserts n lines at the given line position, with the given optional cell, within the specified rectangles. If no rectangles are specified, it inserts lines in the entire buffer. Only cells within the rectangle's horizontal bounds are affected. Lines are pushed out of the rectangle bounds and lost. This follows terminal ansi.IL behavior. It returns the pushed out lines.
func (*Buffer) InsertLineRect ¶
InsertLineRect inserts new lines at the given line position, with the given optional cell, within the rectangle bounds. Only cells within the rectangle's horizontal bounds are affected. Lines are pushed out of the rectangle bounds and lost. This follows terminal ansi.IL behavior.
type Callbacks ¶
type Callbacks struct {
// Bell callback. When set, this function is called when a bell character is
// received.
Bell func()
// Title callback. When set, this function is called when the terminal title
// changes.
Title func(string)
// IconName callback. When set, this function is called when the terminal
// icon name changes.
IconName func(string)
// AltScreen callback. When set, this function is called when the alternate
// screen is activated or deactivated.
AltScreen func(bool)
// CursorPosition callback. When set, this function is called when the cursor
// position changes.
CursorPosition func(old, new uv.Position) //nolint:predeclared,revive
// CursorVisibility callback. When set, this function is called when the
// cursor visibility changes.
CursorVisibility func(visible bool)
// CursorStyle callback. When set, this function is called when the cursor
// style changes.
CursorStyle func(style CursorStyle, blink bool)
// CursorColor callback. When set, this function is called when the cursor
// color changes. Nil indicates the default terminal color.
CursorColor func(color color.Color)
// BackgroundColor callback. When set, this function is called when the
// background color changes. Nil indicates the default terminal color.
BackgroundColor func(color color.Color)
// ForegroundColor callback. When set, this function is called when the
// foreground color changes. Nil indicates the default terminal color.
ForegroundColor func(color color.Color)
// WorkingDirectory callback. When set, this function is called when the
// current working directory changes.
WorkingDirectory func(string)
// EnableMode callback. When set, this function is called when a mode is
// enabled.
EnableMode func(mode ansi.Mode)
// DisableMode callback. When set, this function is called when a mode is
// disabled.
DisableMode func(mode ansi.Mode)
}
Callbacks represents a set of callbacks for a terminal.
type CcHandler ¶
type CcHandler func() bool
CcHandler is a function that handles a control character.
type CellDamage ¶
CellDamage represents a damaged cell.
func (CellDamage) Bounds ¶
func (d CellDamage) Bounds() uv.Rectangle
Bounds returns the bounds of the damaged area.
type CharSet ¶
CharSet represents a character set designator. This can be used to select a character set for G0 or G1 and others.
type CsiHandler ¶
CsiHandler is a function that handles a CSI escape sequence.
type Cursor ¶
type Cursor struct {
Pen uv.Style
Link uv.Link
uv.Position
Style CursorStyle
Steady bool // Not blinking
Hidden bool
}
Cursor represents a cursor in a terminal.
type CursorStyle ¶
type CursorStyle int
CursorStyle represents a cursor style.
const ( CursorBlock CursorStyle = iota CursorUnderline CursorBar )
Cursor styles.
type DcsHandler ¶
DcsHandler is a function that handles a DCS escape sequence.
type Emulator ¶
type Emulator struct {
// contains filtered or unexported fields
}
Emulator represents a virtual terminal emulator.
func NewEmulator ¶
NewEmulator creates a new virtual terminal emulator.
func (*Emulator) BackgroundColor ¶
BackgroundColor returns the terminal's background color. This returns nil if the background color is not set which means the outer terminal color is used.
func (*Emulator) Blur ¶
func (e *Emulator) Blur()
Blur sends the terminal a blur event if focus events mode is enabled. This is the opposite of [Focus].
func (*Emulator) CellAt ¶
CellAt returns the current focused screen cell at the given x, y position. It returns nil if the cell is out of bounds.
func (*Emulator) ClearScrollback ¶
func (e *Emulator) ClearScrollback()
ClearScrollback clears the scrollback buffer.
func (*Emulator) CursorColor ¶
CursorColor returns the terminal's cursor color. This returns nil if the cursor color is not set which means the outer terminal color is used.
func (*Emulator) CursorPosition ¶
CursorPosition returns the terminal's cursor position.
func (*Emulator) Draw ¶
Draw implements the uv.Drawable interface.
func (*Emulator) Focus ¶
func (e *Emulator) Focus()
Focus sends the terminal a focus event if focus events mode is enabled. This is the opposite of [Blur].
func (*Emulator) ForegroundColor ¶
ForegroundColor returns the terminal's foreground color. This returns nil if the foreground color is not set which means the outer terminal color is used.
func (*Emulator) IndexedColor ¶
IndexedColor returns a terminal's indexed color. An indexed color is a color between 0 and 255.
func (*Emulator) InputPipe ¶
InputPipe returns the terminal's input pipe. This can be used to send input to the terminal.
func (*Emulator) IsAltScreen ¶
IsAltScreen returns whether the terminal is in alternate screen mode.
func (*Emulator) Paste ¶
Paste pastes text into the terminal. If bracketed paste mode is enabled, the text is bracketed with the appropriate escape sequences.
func (*Emulator) RegisterApcHandler ¶
func (h *Emulator) RegisterApcHandler(handler ApcHandler)
RegisterApcHandler registers an APC escape sequence handler.
func (*Emulator) RegisterCsiHandler ¶
func (h *Emulator) RegisterCsiHandler(cmd int, handler CsiHandler)
RegisterCsiHandler registers a CSI escape sequence handler.
func (*Emulator) RegisterDcsHandler ¶
func (h *Emulator) RegisterDcsHandler(cmd int, handler DcsHandler)
RegisterDcsHandler registers a DCS escape sequence handler.
func (*Emulator) RegisterEscHandler ¶
func (h *Emulator) RegisterEscHandler(cmd int, handler EscHandler)
RegisterEscHandler registers an ESC escape sequence handler.
func (*Emulator) RegisterOscHandler ¶
func (h *Emulator) RegisterOscHandler(cmd int, handler OscHandler)
RegisterOscHandler registers an OSC escape sequence handler.
func (*Emulator) RegisterPmHandler ¶
func (h *Emulator) RegisterPmHandler(handler PmHandler)
RegisterPmHandler registers a PM escape sequence handler.
func (*Emulator) RegisterSosHandler ¶
func (h *Emulator) RegisterSosHandler(handler SosHandler)
RegisterSosHandler registers an SOS escape sequence handler.
func (*Emulator) Render ¶
Render renders a snapshot of the terminal screen as a string with styles and links encoded as ANSI escape codes.
func (*Emulator) Scrollback ¶
func (e *Emulator) Scrollback() *Scrollback
Scrollback returns the scrollback buffer for the main screen. Returns nil if the terminal is in alternate screen mode, as the alternate screen typically doesn't use scrollback.
func (*Emulator) ScrollbackCellAt ¶
ScrollbackCellAt returns the cell at the given position in the scrollback buffer. x is the column, y is the line index (0 = oldest line in scrollback). Returns nil if position is out of bounds.
func (*Emulator) ScrollbackLen ¶
ScrollbackLen returns the number of lines in the scrollback buffer.
func (*Emulator) SendMouse ¶
SendMouse sends a mouse event to the terminal. This can be any kind of mouse events such as MouseClick, MouseRelease, MouseWheel, or MouseMotion.
func (*Emulator) SetBackgroundColor ¶
SetBackgroundColor sets the terminal's background color.
func (*Emulator) SetCallbacks ¶
SetCallbacks sets the terminal's callbacks.
func (*Emulator) SetCursorColor ¶
SetCursorColor sets the terminal's cursor color.
func (*Emulator) SetDefaultBackgroundColor ¶
SetDefaultBackgroundColor sets the terminal's default background color.
func (*Emulator) SetDefaultCursorColor ¶
SetDefaultCursorColor sets the terminal's default cursor color.
func (*Emulator) SetDefaultForegroundColor ¶
SetDefaultForegroundColor sets the terminal's default foreground color.
func (*Emulator) SetForegroundColor ¶
SetForegroundColor sets the terminal's foreground color.
func (*Emulator) SetIndexedColor ¶
SetIndexedColor sets a terminal's indexed color. The index must be between 0 and 255.
func (*Emulator) SetScrollbackSize ¶
SetScrollbackSize sets the maximum number of lines in the scrollback buffer.
func (*Emulator) WidthMethod ¶
func (e *Emulator) WidthMethod() uv.WidthMethod
WidthMethod returns the width method used by the terminal.
type EscHandler ¶
type EscHandler func() bool
EscHandler is a function that handles an ESC escape sequence.
type KeyPressEvent ¶
type KeyPressEvent = uv.KeyPressEvent
KeyPressEvent represents a key press event.
type MouseButton ¶
type MouseButton = uv.MouseButton
MouseButton represents the button that was pressed during a mouse message.
type MouseMotion ¶
type MouseMotion = uv.MouseMotionEvent
MouseMotion represents a mouse motion event.
type MouseRelease ¶
type MouseRelease = uv.MouseReleaseEvent
MouseRelease represents a mouse release event.
type MoveDamage ¶
MoveDamage represents a moved area. The area is moved from the source to the destination.
type OscHandler ¶
OscHandler is a function that handles an OSC escape sequence.
type RectDamage ¶
RectDamage represents a damaged rectangle.
func (RectDamage) Bounds ¶
func (d RectDamage) Bounds() uv.Rectangle
Bounds returns the bounds of the damaged area.
func (RectDamage) Height ¶
func (d RectDamage) Height() int
Height returns the height of the damaged area.
func (RectDamage) Width ¶
func (d RectDamage) Width() int
Width returns the width of the damaged area.
type SafeEmulator ¶
type SafeEmulator struct {
*Emulator
// contains filtered or unexported fields
}
SafeEmulator is a wrapper around an Emulator that adds concurrency safety.
func NewSafeEmulator ¶
func NewSafeEmulator(w, h int) *SafeEmulator
NewSafeEmulator creates a new SafeEmulator instance.
func (*SafeEmulator) BackgroundColor ¶
func (se *SafeEmulator) BackgroundColor() color.Color
BackgroundColor returns the background color in a concurrency-safe manner.
func (*SafeEmulator) CellAt ¶
func (se *SafeEmulator) CellAt(x, y int) *uv.Cell
CellAt retrieves a cell from the emulator in a concurrency-safe manner.
func (*SafeEmulator) ClearScrollback ¶
func (se *SafeEmulator) ClearScrollback()
ClearScrollback clears the scrollback buffer in a concurrency-safe manner.
func (*SafeEmulator) CursorColor ¶
func (se *SafeEmulator) CursorColor() color.Color
CursorColor returns the cursor color in a concurrency-safe manner.
func (*SafeEmulator) CursorPosition ¶
func (se *SafeEmulator) CursorPosition() uv.Position
CursorPosition returns the cursor position in a concurrency-safe manner.
func (*SafeEmulator) Draw ¶
func (se *SafeEmulator) Draw(s uv.Screen, a uv.Rectangle)
Draw draws the emulator's content onto a given surface in a concurrency-safe manner.
func (*SafeEmulator) ForegroundColor ¶
func (se *SafeEmulator) ForegroundColor() color.Color
ForegroundColor returns the foreground color in a concurrency-safe manner.
func (*SafeEmulator) Height ¶
func (se *SafeEmulator) Height() int
Height returns the height of the emulator in a concurrency-safe manner.
func (*SafeEmulator) IndexedColor ¶
func (se *SafeEmulator) IndexedColor(index int) color.Color
IndexedColor retrieves an indexed color in a concurrency-safe manner.
func (*SafeEmulator) IsAltScreen ¶
func (se *SafeEmulator) IsAltScreen() bool
IsAltScreen returns whether in alternate screen mode in a concurrency-safe manner.
func (*SafeEmulator) Paste ¶
func (se *SafeEmulator) Paste(text string)
Paste pastes text into the emulator in a concurrency-safe manner.
func (*SafeEmulator) Read ¶
func (se *SafeEmulator) Read(p []byte) (int, error)
Read reads data from the emulator in a concurrency-safe manner.
func (SafeEmulator) RegisterApcHandler ¶
func (h SafeEmulator) RegisterApcHandler(handler ApcHandler)
RegisterApcHandler registers an APC escape sequence handler.
func (SafeEmulator) RegisterCsiHandler ¶
func (h SafeEmulator) RegisterCsiHandler(cmd int, handler CsiHandler)
RegisterCsiHandler registers a CSI escape sequence handler.
func (SafeEmulator) RegisterDcsHandler ¶
func (h SafeEmulator) RegisterDcsHandler(cmd int, handler DcsHandler)
RegisterDcsHandler registers a DCS escape sequence handler.
func (SafeEmulator) RegisterEscHandler ¶
func (h SafeEmulator) RegisterEscHandler(cmd int, handler EscHandler)
RegisterEscHandler registers an ESC escape sequence handler.
func (SafeEmulator) RegisterOscHandler ¶
func (h SafeEmulator) RegisterOscHandler(cmd int, handler OscHandler)
RegisterOscHandler registers an OSC escape sequence handler.
func (SafeEmulator) RegisterPmHandler ¶
func (h SafeEmulator) RegisterPmHandler(handler PmHandler)
RegisterPmHandler registers a PM escape sequence handler.
func (SafeEmulator) RegisterSosHandler ¶
func (h SafeEmulator) RegisterSosHandler(handler SosHandler)
RegisterSosHandler registers an SOS escape sequence handler.
func (*SafeEmulator) Render ¶
func (se *SafeEmulator) Render() string
Render renders the emulator's current state in a concurrency-safe manner.
func (*SafeEmulator) Resize ¶
func (se *SafeEmulator) Resize(w, h int)
Resize resizes the emulator in a concurrency-safe manner.
func (*SafeEmulator) Scrollback ¶
func (se *SafeEmulator) Scrollback() *Scrollback
Scrollback returns the scrollback buffer in a concurrency-safe manner.
func (*SafeEmulator) ScrollbackCellAt ¶
func (se *SafeEmulator) ScrollbackCellAt(x, y int) *uv.Cell
ScrollbackCellAt returns a cell from the scrollback buffer in a concurrency-safe manner.
func (*SafeEmulator) ScrollbackLen ¶
func (se *SafeEmulator) ScrollbackLen() int
ScrollbackLen returns the number of lines in the scrollback buffer in a concurrency-safe manner.
func (*SafeEmulator) SendKey ¶
func (se *SafeEmulator) SendKey(key uv.KeyEvent)
SendKey sends a key event to the emulator in a concurrency-safe manner.
func (*SafeEmulator) SendMouse ¶
func (se *SafeEmulator) SendMouse(mouse uv.MouseEvent)
SendMouse sends a mouse event to the emulator in a concurrency-safe manner.
func (*SafeEmulator) SendText ¶
func (se *SafeEmulator) SendText(text string)
SendText sends text input to the emulator in a concurrency-safe manner.
func (*SafeEmulator) SetBackgroundColor ¶
func (se *SafeEmulator) SetBackgroundColor(color color.Color)
SetBackgroundColor sets the background color in a concurrency-safe manner.
func (*SafeEmulator) SetCell ¶
func (se *SafeEmulator) SetCell(x, y int, cell *uv.Cell)
SetCell sets a cell in the emulator in a concurrency-safe manner.
func (*SafeEmulator) SetCursorColor ¶
func (se *SafeEmulator) SetCursorColor(color color.Color)
SetCursorColor sets the cursor color in a concurrency-safe manner.
func (*SafeEmulator) SetForegroundColor ¶
func (se *SafeEmulator) SetForegroundColor(color color.Color)
SetForegroundColor sets the foreground color in a concurrency-safe manner.
func (*SafeEmulator) SetIndexedColor ¶
func (se *SafeEmulator) SetIndexedColor(index int, color color.Color)
SetIndexedColor sets an indexed color in a concurrency-safe manner.
func (*SafeEmulator) SetScrollbackSize ¶
func (se *SafeEmulator) SetScrollbackSize(maxLines int)
SetScrollbackSize sets the scrollback buffer size in a concurrency-safe manner.
func (*SafeEmulator) Touched ¶
func (se *SafeEmulator) Touched() []*uv.LineData
Touched returns the touched lines in a concurrency-safe manner.
func (*SafeEmulator) Width ¶
func (se *SafeEmulator) Width() int
Width returns the width of the emulator in a concurrency-safe manner.
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
Screen represents a virtual terminal screen.
func (*Screen) ClearTouched ¶
func (s *Screen) ClearTouched()
ClearTouched clears the touched state.
func (*Screen) ClearWithScrollback ¶
func (s *Screen) ClearWithScrollback()
ClearWithScrollback saves all non-empty lines to scrollback before clearing. This is used for operations like ED 2 (erase screen) where content should be preserved in history.
func (*Screen) CursorPosition ¶
CursorPosition returns the cursor position.
func (*Screen) DeleteCell ¶
DeleteCell deletes n cells at the cursor position moving cells to the left. This has no effect if the cursor is outside the scroll region.
func (*Screen) DeleteLine ¶
DeleteLine deletes n lines at the cursor position Y coordinate. Only operates if cursor is within scroll region. Lines below cursor Y are moved up, with blank lines inserted at the bottom of scroll region. If scrollback is enabled and cursor is at top of scroll region, lines are saved to the scrollback buffer before deletion. It returns true if the operation was successful.
func (*Screen) InsertCell ¶
InsertCell inserts n blank characters at the cursor position pushing out cells to the right and out of the screen.
func (*Screen) InsertLine ¶
InsertLine inserts n blank lines at the cursor position Y coordinate. Only operates if cursor is within scroll region. Lines below cursor Y are moved down, with those past bottom margin being discarded. It returns true if the operation was successful.
func (*Screen) Reset ¶
func (s *Screen) Reset()
Reset resets the screen. It clears the screen, sets the cursor to the top left corner, reset the cursor styles, and resets the scroll region.
func (*Screen) ScrollDown ¶
ScrollDown scrolls the content down n lines within the given region. Lines scrolled past the bottom margin are lost. This is equivalent to ansi.SD which moves the cursor to top margin and performs a ansi.IL operation.
func (*Screen) ScrollRegion ¶
ScrollRegion returns the scroll region.
func (*Screen) ScrollUp ¶
ScrollUp scrolls the content up n lines within the given region. Lines scrolled past the top margin are lost. This is equivalent to ansi.SU which moves the cursor to the top margin and performs a ansi.DL operation.
func (*Screen) Scrollback ¶
func (s *Screen) Scrollback() *Scrollback
Scrollback returns the screen's scrollback buffer.
func (*Screen) SetScrollback ¶
func (s *Screen) SetScrollback(sb *Scrollback)
SetScrollback sets the screen's scrollback buffer. Pass nil to disable scrollback.
func (*Screen) SetScrollbackSize ¶
SetScrollbackSize sets the maximum number of lines in the scrollback buffer.
type ScreenDamage ¶
type ScreenDamage struct {
Width, Height int
}
ScreenDamage represents a damaged screen.
func (ScreenDamage) Bounds ¶
func (d ScreenDamage) Bounds() uv.Rectangle
Bounds returns the bounds of the damaged area.
type ScrollDamage ¶
ScrollDamage represents a scrolled area. The area is scrolled by the given deltas.
type Scrollback ¶
type Scrollback struct {
// contains filtered or unexported fields
}
Scrollback represents a scrollback buffer that stores lines scrolled off the screen.
func NewScrollback ¶
func NewScrollback(maxLines int) *Scrollback
NewScrollback creates a new scrollback buffer with the given maximum number of lines.
func (*Scrollback) CellAt ¶
func (s *Scrollback) CellAt(x, y int) *uv.Cell
CellAt returns the cell at the given position in the scrollback buffer. x is the column, y is the line index (0 = oldest). Returns nil if position is out of bounds.
func (*Scrollback) Clear ¶
func (s *Scrollback) Clear()
Clear removes all lines from the scrollback buffer.
func (*Scrollback) Len ¶
func (s *Scrollback) Len() int
Len returns the number of lines in the scrollback buffer.
func (*Scrollback) Line ¶
func (s *Scrollback) Line(index int) uv.Line
Line returns the line at the given index. Index 0 is the oldest line, Len()-1 is the most recent. Returns nil if index is out of bounds.
func (*Scrollback) Lines ¶
func (s *Scrollback) Lines() []uv.Line
Lines returns all lines in the scrollback buffer. Index 0 is the oldest line.
func (*Scrollback) MaxLines ¶
func (s *Scrollback) MaxLines() int
MaxLines returns the maximum number of lines the scrollback buffer can hold.
func (*Scrollback) Push ¶
func (s *Scrollback) Push(line uv.Line)
Push adds a line to the scrollback buffer. If the buffer is full, the oldest line is removed.
func (*Scrollback) PushN ¶
func (s *Scrollback) PushN(buf *uv.RenderBuffer, y, n int)
PushN adds n lines from the buffer starting at line y to the scrollback.
func (*Scrollback) SetMaxLines ¶
func (s *Scrollback) SetMaxLines(maxLines int)
SetMaxLines sets the maximum number of lines in the scrollback buffer. If the current number of lines exceeds the new maximum, oldest lines are removed.
type SosHandler ¶
SosHandler is a function that handles an SOS escape sequence.
type Terminal ¶
type Terminal interface {
BackgroundColor() color.Color
Blur()
Bounds() uv.Rectangle
CellAt(x int, y int) *uv.Cell
ClearScrollback()
Close() error
CursorColor() color.Color
CursorPosition() uv.Position
Draw(scr uv.Screen, area uv.Rectangle)
Focus()
ForegroundColor() color.Color
Height() int
IndexedColor(i int) color.Color
InputPipe() io.Writer
IsAltScreen() bool
Paste(text string)
Read(p []byte) (n int, err error)
RegisterApcHandler(handler ApcHandler)
RegisterCsiHandler(cmd int, handler CsiHandler)
RegisterDcsHandler(cmd int, handler DcsHandler)
RegisterEscHandler(cmd int, handler EscHandler)
RegisterOscHandler(cmd int, handler OscHandler)
RegisterPmHandler(handler PmHandler)
RegisterSosHandler(handler SosHandler)
Render() string
Resize(width int, height int)
Scrollback() *Scrollback
ScrollbackCellAt(x, y int) *uv.Cell
ScrollbackLen() int
SendKey(k uv.KeyEvent)
SendKeys(keys ...uv.KeyEvent)
SendMouse(m Mouse)
SendText(text string)
SetBackgroundColor(c color.Color)
SetCallbacks(cb Callbacks)
SetCell(x int, y int, c *uv.Cell)
SetCursorColor(c color.Color)
SetDefaultBackgroundColor(c color.Color)
SetDefaultCursorColor(c color.Color)
SetDefaultForegroundColor(c color.Color)
SetForegroundColor(c color.Color)
SetIndexedColor(i int, c color.Color)
SetLogger(l Logger)
SetScrollbackSize(maxLines int)
String() string
Touched() []*uv.LineData
Width() int
WidthMethod() uv.WidthMethod
Write(p []byte) (n int, err error)
WriteString(s string) (n int, err error)
}
Terminal represents a virtual terminal interface.