vt

package module
v0.0.0-...-fe36e8c Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 13 Imported by: 2

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

View Source
const (
	ModShift = uv.ModShift
	ModAlt   = uv.ModAlt
	ModCtrl  = uv.ModCtrl
	ModMeta  = uv.ModMeta
)

Modifier keys.

View Source
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.

View Source
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.

View Source
const DefaultScrollbackSize = 10000

DefaultScrollbackSize is the default maximum number of lines in the scrollback buffer.

Variables

View Source
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

type ApcHandler func(data []byte) bool

ApcHandler is a function that handles an APC escape sequence.

type Buffer

type Buffer struct {
	uv.Buffer
}

Buffer is a terminal cell buffer.

func (*Buffer) DeleteCell

func (b *Buffer) DeleteCell(x, y, n int, c *uv.Cell)

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

func (b *Buffer) DeleteCellRect(x, y, n int, c *uv.Cell, rect uv.Rectangle)

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

func (b *Buffer) DeleteLine(y, n int, c *uv.Cell)

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

func (b *Buffer) DeleteLineRect(y, n int, c *uv.Cell, rect uv.Rectangle)

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

func (b *Buffer) InsertCell(x, y, n int, c *uv.Cell)

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

func (b *Buffer) InsertCellRect(x, y, n int, c *uv.Cell, rect uv.Rectangle)

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

func (b *Buffer) InsertLine(y, n int, c *uv.Cell)

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

func (b *Buffer) InsertLineRect(y, n int, c *uv.Cell, rect uv.Rectangle)

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

type CellDamage struct {
	X, Y  int
	Width int
}

CellDamage represents a damaged cell.

func (CellDamage) Bounds

func (d CellDamage) Bounds() uv.Rectangle

Bounds returns the bounds of the damaged area.

type CharSet

type CharSet map[byte]string

CharSet represents a character set designator. This can be used to select a character set for G0 or G1 and others.

type CsiHandler

type CsiHandler func(params ansi.Params) bool

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 Damage

type Damage interface {
	// Bounds returns the bounds of the damaged area.
	Bounds() uv.Rectangle
}

Damage represents a damaged area.

type DcsHandler

type DcsHandler func(params ansi.Params, data []byte) bool

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

func NewEmulator(w, h int) *Emulator

NewEmulator creates a new virtual terminal emulator.

func (*Emulator) BackgroundColor

func (e *Emulator) BackgroundColor() color.Color

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) Bounds

func (e *Emulator) Bounds() uv.Rectangle

Bounds returns the bounds of the terminal.

func (*Emulator) CellAt

func (e *Emulator) CellAt(x, y int) *uv.Cell

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) Close

func (e *Emulator) Close() error

Close closes the terminal.

func (*Emulator) CursorColor

func (e *Emulator) CursorColor() color.Color

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

func (e *Emulator) CursorPosition() uv.Position

CursorPosition returns the terminal's cursor position.

func (*Emulator) Draw

func (e *Emulator) Draw(scr uv.Screen, area uv.Rectangle)

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

func (e *Emulator) ForegroundColor() color.Color

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) Height

func (e *Emulator) Height() int

Height returns the height of the terminal.

func (*Emulator) IndexedColor

func (e *Emulator) IndexedColor(i int) color.Color

IndexedColor returns a terminal's indexed color. An indexed color is a color between 0 and 255.

func (*Emulator) InputPipe

func (e *Emulator) InputPipe() io.Writer

InputPipe returns the terminal's input pipe. This can be used to send input to the terminal.

func (*Emulator) IsAltScreen

func (e *Emulator) IsAltScreen() bool

IsAltScreen returns whether the terminal is in alternate screen mode.

func (*Emulator) Paste

func (e *Emulator) Paste(text string)

Paste pastes text into the terminal. If bracketed paste mode is enabled, the text is bracketed with the appropriate escape sequences.

func (*Emulator) Read

func (e *Emulator) Read(p []byte) (n int, err error)

Read reads data from the terminal input buffer.

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

func (e *Emulator) Render() string

Render renders a snapshot of the terminal screen as a string with styles and links encoded as ANSI escape codes.

func (*Emulator) Resize

func (e *Emulator) Resize(width int, height int)

Resize resizes the terminal.

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

func (e *Emulator) ScrollbackCellAt(x, y int) *uv.Cell

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

func (e *Emulator) ScrollbackLen() int

ScrollbackLen returns the number of lines in the scrollback buffer.

func (*Emulator) SendKey

func (e *Emulator) SendKey(k uv.KeyEvent)

SendKey returns the default key map.

func (*Emulator) SendKeys

func (e *Emulator) SendKeys(keys ...uv.KeyEvent)

SendKeys sends multiple keys to the terminal.

func (*Emulator) SendMouse

func (e *Emulator) SendMouse(m Mouse)

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) SendText

func (e *Emulator) SendText(text string)

SendText sends arbitrary text to the terminal.

func (*Emulator) SetBackgroundColor

func (e *Emulator) SetBackgroundColor(c color.Color)

SetBackgroundColor sets the terminal's background color.

func (*Emulator) SetCallbacks

func (e *Emulator) SetCallbacks(cb Callbacks)

SetCallbacks sets the terminal's callbacks.

func (*Emulator) SetCell

func (e *Emulator) SetCell(x, y int, c *uv.Cell)

SetCell sets the current focused screen cell at the given x, y position.

func (*Emulator) SetCursorColor

func (e *Emulator) SetCursorColor(c color.Color)

SetCursorColor sets the terminal's cursor color.

func (*Emulator) SetDefaultBackgroundColor

func (e *Emulator) SetDefaultBackgroundColor(c color.Color)

SetDefaultBackgroundColor sets the terminal's default background color.

func (*Emulator) SetDefaultCursorColor

func (e *Emulator) SetDefaultCursorColor(c color.Color)

SetDefaultCursorColor sets the terminal's default cursor color.

func (*Emulator) SetDefaultForegroundColor

func (e *Emulator) SetDefaultForegroundColor(c color.Color)

SetDefaultForegroundColor sets the terminal's default foreground color.

func (*Emulator) SetForegroundColor

func (e *Emulator) SetForegroundColor(c color.Color)

SetForegroundColor sets the terminal's foreground color.

func (*Emulator) SetIndexedColor

func (e *Emulator) SetIndexedColor(i int, c color.Color)

SetIndexedColor sets a terminal's indexed color. The index must be between 0 and 255.

func (*Emulator) SetLogger

func (e *Emulator) SetLogger(l Logger)

SetLogger sets the terminal's logger.

func (*Emulator) SetScrollbackSize

func (e *Emulator) SetScrollbackSize(maxLines int)

SetScrollbackSize sets the maximum number of lines in the scrollback buffer.

func (*Emulator) String

func (e *Emulator) String() string

String returns a string representation of the underlying screen buffer.

func (*Emulator) Touched

func (e *Emulator) Touched() []*uv.LineData

Touched returns the touched lines in the current screen buffer.

func (*Emulator) Width

func (e *Emulator) Width() int

Width returns the width of the terminal.

func (*Emulator) WidthMethod

func (e *Emulator) WidthMethod() uv.WidthMethod

WidthMethod returns the width method used by the terminal.

func (*Emulator) Write

func (e *Emulator) Write(p []byte) (n int, err error)

Write writes data to the terminal output buffer.

func (*Emulator) WriteString

func (e *Emulator) WriteString(s string) (n int, err error)

WriteString writes a string to the terminal output buffer.

type EscHandler

type EscHandler func() bool

EscHandler is a function that handles an ESC escape sequence.

type KeyMod

type KeyMod = uv.KeyMod

KeyMod represents a key modifier.

type KeyPressEvent

type KeyPressEvent = uv.KeyPressEvent

KeyPressEvent represents a key press event.

type Logger

type Logger interface {
	Printf(format string, v ...any)
}

Logger represents a logger interface.

type Mouse

type Mouse = uv.MouseEvent

Mouse represents a mouse event.

type MouseButton

type MouseButton = uv.MouseButton

MouseButton represents the button that was pressed during a mouse message.

type MouseClick

type MouseClick = uv.MouseClickEvent

MouseClick represents a mouse click event.

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 MouseWheel

type MouseWheel = uv.MouseWheelEvent

MouseWheel represents a mouse wheel event.

type MoveDamage

type MoveDamage struct {
	Src, Dst uv.Rectangle
}

MoveDamage represents a moved area. The area is moved from the source to the destination.

type OscHandler

type OscHandler func(data []byte) bool

OscHandler is a function that handles an OSC escape sequence.

type PmHandler

type PmHandler func(data []byte) bool

PmHandler is a function that handles a PM escape sequence.

type RectDamage

type RectDamage uv.Rectangle

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.

func (RectDamage) X

func (d RectDamage) X() int

X returns the x-coordinate of the damaged area.

func (RectDamage) Y

func (d RectDamage) Y() int

Y returns the y-coordinate 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.

func (*SafeEmulator) Write

func (se *SafeEmulator) Write(data []byte) (int, error)

Write writes data to the emulator in a concurrency-safe manner.

type Screen

type Screen struct {
	// contains filtered or unexported fields
}

Screen represents a virtual terminal screen.

func NewScreen

func NewScreen(w, h int) *Screen

NewScreen creates a new screen.

func (*Screen) Bounds

func (s *Screen) Bounds() uv.Rectangle

Bounds returns the bounds of the screen.

func (*Screen) CellAt

func (s *Screen) CellAt(x int, y int) *uv.Cell

CellAt returns the cell at the given x, y position.

func (*Screen) Clear

func (s *Screen) Clear()

Clear clears the screen with blank cells.

func (*Screen) ClearArea

func (s *Screen) ClearArea(area uv.Rectangle)

ClearArea clears the given area.

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) Cursor

func (s *Screen) Cursor() Cursor

Cursor returns the cursor.

func (*Screen) CursorPosition

func (s *Screen) CursorPosition() (x, y int)

CursorPosition returns the cursor position.

func (*Screen) DeleteCell

func (s *Screen) DeleteCell(n int)

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

func (s *Screen) DeleteLine(n int) bool

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) Fill

func (s *Screen) Fill(c *uv.Cell)

Fill fills the screen or part of it.

func (*Screen) FillArea

func (s *Screen) FillArea(c *uv.Cell, area uv.Rectangle)

FillArea fills the given area with the given cell.

func (*Screen) Height

func (s *Screen) Height() int

Height returns the height of the screen.

func (*Screen) HideCursor

func (s *Screen) HideCursor()

HideCursor hides the cursor.

func (*Screen) InsertCell

func (s *Screen) InsertCell(n int)

InsertCell inserts n blank characters at the cursor position pushing out cells to the right and out of the screen.

func (*Screen) InsertLine

func (s *Screen) InsertLine(n int) bool

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) Resize

func (s *Screen) Resize(width int, height int)

Resize resizes the screen.

func (*Screen) RestoreCursor

func (s *Screen) RestoreCursor()

RestoreCursor restores the cursor.

func (*Screen) SaveCursor

func (s *Screen) SaveCursor()

SaveCursor saves the cursor.

func (*Screen) ScrollDown

func (s *Screen) ScrollDown(n int)

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

func (s *Screen) ScrollRegion() uv.Rectangle

ScrollRegion returns the scroll region.

func (*Screen) ScrollUp

func (s *Screen) ScrollUp(n int)

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) SetCell

func (s *Screen) SetCell(x, y int, c *uv.Cell)

SetCell sets the cell at the given x, y position.

func (*Screen) SetScrollback

func (s *Screen) SetScrollback(sb *Scrollback)

SetScrollback sets the screen's scrollback buffer. Pass nil to disable scrollback.

func (*Screen) SetScrollbackSize

func (s *Screen) SetScrollbackSize(maxLines int)

SetScrollbackSize sets the maximum number of lines in the scrollback buffer.

func (*Screen) ShowCursor

func (s *Screen) ShowCursor()

ShowCursor shows the cursor.

func (*Screen) Touched

func (s *Screen) Touched() []*uv.LineData

Touched returns touched lines in the screen buffer.

func (*Screen) Width

func (s *Screen) Width() int

Width returns the width of the screen.

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

type ScrollDamage struct {
	uv.Rectangle
	Dx, Dy int
}

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

type SosHandler func(data []byte) bool

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.

Directories

Path Synopsis
examples module

Jump to

Keyboard shortcuts

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