Documentation
¶
Overview ¶
Package vt is SSHYard's terminal emulator: a parser of the escape sequences a VT100/xterm-compatible terminal understands and the grid of cells they draw on, with scrollback, the alternate screen, 256 colors and truecolor. It has no UI; package app draws its cells natively with MyGo's Painter.
Index ¶
- Constants
- func EncodeFocus(m Modes, focused bool) []byte
- func EncodeMouse(m Modes, ev MouseEvent) []byte
- func RuneWidth(r rune) int
- type Attr
- type Cell
- type Color
- type CursorStyle
- type Line
- type Match
- type Modes
- type MouseAction
- type MouseBtn
- type MouseEvent
- type MouseMode
- type Pos
- type Snapshot
- type Terminal
- func (t *Terminal) Cwd() string
- func (t *Terminal) CwdHost() string
- func (t *Terminal) Find(query string, caseSensitive bool) []Match
- func (t *Terminal) Generation() uint64
- func (t *Terminal) Modes() Modes
- func (t *Terminal) OffsetFor(n, current int) int
- func (t *Terminal) ResetInputModes(leaveAlt bool)
- func (t *Terminal) Resize(cols, rows int)
- func (t *Terminal) ScreenText() string
- func (t *Terminal) SetOSC52Max(n int)
- func (t *Terminal) SetScrollback(n int)
- func (t *Terminal) Size() (cols, rows int)
- func (t *Terminal) Snapshot(offset int) Snapshot
- func (t *Terminal) Text(a, b Pos) string
- func (t *Terminal) Title() string
- func (t *Terminal) WordAt(p Pos) (Pos, Pos)
- func (t *Terminal) Write(p []byte) (int, error)
- func (t *Terminal) WriteString(s string)
Constants ¶
const DefaultScrollback = 10000
DefaultScrollback is how many lines scroll back by default.
const ( // OSC52MaxDefault is the decoded size of an OSC 52 paste when no // limit was set: 1 MiB. OSC52MaxDefault = 1 << 20 )
Variables ¶
This section is empty.
Functions ¶
func EncodeFocus ¶
EncodeFocus is what a program that asked for focus events (1004) reads when the terminal gains or loses the focus, or nil.
func EncodeMouse ¶
func EncodeMouse(m Modes, ev MouseEvent) []byte
EncodeMouse is what the program reads for ev under modes m, or nil when the modes do not ask for it. The default encoding cannot say a column or row past 223: such events are dropped, as xterm does; SGR (1006) has no limit.
Types ¶
type Cell ¶
Cell is one cell of the grid. A wide character (CJK, most emoji) takes two cells: the first has Width 2, the second Width 0 and no rune. Comb holds what joins Rune in its cell: combining marks, variation selectors, emoji modifiers, and ZWJ with what it joins.
type Color ¶
type Color uint32
Color is a cell's color: the default, an entry of the 256-color palette, or a 24-bit RGB value.
const DefaultColor Color = colorDefault
DefaultColor is the terminal's default foreground or background.
type CursorStyle ¶
type CursorStyle int
CursorStyle is the cursor's shape, as DECSCUSR sets it.
const ( CursorBlock CursorStyle = iota CursorUnderline CursorBar )
type Line ¶
Line is a row of cells. Wrapped is set when the text continued on the next line because it reached the right margin.
type Modes ¶
type Modes struct {
AppCursorKeys bool // DECCKM: arrows send ESC O A
AppKeypad bool
BracketedPaste bool
CursorVisible bool
AltScreen bool
AutoWrap bool
Origin bool
Insert bool
MouseTracking bool // a mouse mode is on (9/1000/1002/1003)
Mouse MouseMode
MouseSGR bool // 1006: SGR encoding of mouse reports
FocusReport bool // 1004
}
Modes are the terminal modes the UI needs to know about.
type MouseAction ¶
type MouseAction uint8
MouseAction is what happened.
const ( MousePress MouseAction = iota MouseRelease MouseMotion )
type MouseEvent ¶
type MouseEvent struct {
Button MouseBtn
Action MouseAction
Col, Row int
Shift, Alt, Ctrl bool
}
MouseEvent is a mouse event to report to the program, at a cell of the screen (0-based).
type Pos ¶
type Pos struct{ Line, Col int }
Pos is a position in the terminal's history: Line is absolute, counting every line that ever scrolled into the scrollback, so it stays put as output arrives; Col is a cell column.
type Snapshot ¶
type Snapshot struct {
Cols, Rows int
// Lines are Rows lines from line First of the history.
Lines []Line
First int
// Cursor is where the cursor is on the screen, in Lines' coordinates;
// CursorVisible is false when the program hid it or it is scrolled
// out of view.
CursorX, CursorY int
CursorVisible bool
CursorStyle CursorStyle
// Scrollback is how many lines are above the screen; Offset how many
// of them the view is scrolled up.
Scrollback, Offset int
Modes Modes
}
Snapshot is a copy of what the terminal shows, for drawing.
type Terminal ¶
type Terminal struct {
// Reply, when set, receives what the terminal answers the program
// (device status and attributes reports). It is called with the lock
// held, so it must not call back into the terminal.
Reply func([]byte)
// OnClipboard reports an OSC 52. sel is the selection parameter
// (c, p, s or 0–7); each of those is the system clipboard. data is
// the text. query is true when the program asked to read the
// clipboard (Pd is "?"); data is then empty and nothing is answered.
// Called with the lock held, like Reply.
OnClipboard func(sel, data string, query bool)
// OnClipboardDrop reports an OSC 52 bigger than the size limit. The
// whole sequence is discarded. Called with the lock held.
OnClipboardDrop func()
// Bell, when set, is called on BEL.
Bell func()
// contains filtered or unexported fields
}
Terminal is a terminal emulator. Write feeds it the output of a program; the UI reads it with Snapshot. It is safe for concurrent use.
func (*Terminal) Cwd ¶
Cwd is the working directory the shell last reported (OSC 7 file://host/path or OSC 1337 CurrentDir=), or "" if it never did.
func (*Terminal) CwdHost ¶
CwdHost is the host the last directory report named: OSC 7's file://host/, or for OSC 1337 CurrentDir the host of the last OSC 1337 RemoteHost=user@host; "" when it named none.
func (*Terminal) Find ¶
Find returns every match of query in the history, oldest first. It ignores case unless caseSensitive. A match does not span lines.
func (*Terminal) Generation ¶
Generation increases every time the terminal changes.
func (*Terminal) OffsetFor ¶
OffsetFor returns the scroll offset that brings absolute line n into view, keeping the view still when it already is.
func (*Terminal) ResetInputModes ¶
ResetInputModes turns off what a program asked of the terminal's input (mouse and focus reports, bracketed paste, application keys), for when it went away without undoing them: its shell ended. With leaveAlt it leaves the alternate screen as well, for a new shell.
func (*Terminal) Resize ¶
Resize changes the terminal's size. Lines are cut or padded, not reflowed; when the screen shrinks, the lines above the cursor go to the scrollback, and when it grows they come back from it.
func (*Terminal) ScreenText ¶
ScreenText returns the text of the screen, one line per row, without trailing blank lines: for tests and for copying all.
func (*Terminal) SetOSC52Max ¶
SetOSC52Max sets the largest decoded OSC 52 paste to keep. Zero uses the default (1 MiB). Anything above 8 MiB is capped there.
func (*Terminal) SetScrollback ¶
SetScrollback sets how many lines scroll back.
func (*Terminal) Snapshot ¶
Snapshot returns the screen, scrolled up offset lines into the scrollback (0 is the live screen).
func (*Terminal) Text ¶
Text returns the text from a to b, inclusive of b's cell. Lines that wrapped are joined; others end with a newline.
func (*Terminal) WriteString ¶
WriteString is Write for a string.