vt

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vt binds libghostty-vt, Ghostty's terminal emulator, through purego on native targets and an embedded WebAssembly module in a browser: no cgo. Native structs mirror its C ABI; the browser marshals the separate guest memory. Both validate the library's type manifest before use.

Nothing here is safe for concurrent use: callers serialize the calls on a Terminal and on what is made from it.

Index

Constants

View Source
const (
	ButtonNone   = 0
	ButtonLeft   = 1
	ButtonRight  = 2
	ButtonMiddle = 3
	WheelUp      = 4
	WheelDown    = 5
	WheelLeft    = 6
	WheelRight   = 7
)

Mouse buttons: 1 left, 2 right, 3 middle, 4 and 5 the wheel up and down, 6 and 7 left and right.

View Source
const (
	UnderlineNone = iota
	UnderlineSingle
	UnderlineDouble
	UnderlineCurly
	UnderlineDotted
	UnderlineDashed
)

Underline styles.

View Source
const Supported = true

Supported reports whether the platform can load the library.

Variables

This section is empty.

Functions

func EncodeFocus

func EncodeFocus(gained bool) []byte

EncodeFocus returns the report of the terminal gaining or losing the focus (mode 1004).

func EncodePaste

func EncodePaste(text string, bracketed bool) []byte

EncodePaste returns text as the program reads a paste: bracketed (mode 2004), or with newlines as carriage returns, and without the control characters that could run commands.

func Load

func Load(path string) error

Load loads the library at path. Only the first call loads one: later calls report how it went, whatever their path.

func Loaded

func Loaded() bool

Loaded reports whether Load succeeded.

func PasteIsSafe

func PasteIsSafe(text string) bool

PasteIsSafe reports whether pasting text cannot run a command by itself.

Types

type Cell

type Cell struct {
	// Codepoint is the first character, 0 for none. Grapheme reports a
	// cluster; CellGraphemes returns the whole cluster, Codepoint included.
	Codepoint rune
	Grapheme  bool
	// Style identifies the cell's style (CellStyle) among the row's
	// cells: 0 is the default.
	Style     uint16
	Wide      Wide
	Hyperlink bool
	// Background is the color of a cell without text whose background
	// a program filled, when HasBackground; Palette tells that it is
	// the palette's color of index Background.R.
	Background    RGB
	HasBackground bool
	Palette       bool
}

Cell is a cell of a row.

type ClipboardAnswer

type ClipboardAnswer int

ClipboardAnswer is how the ClipboardRead effect answers a program's read of the clipboard.

const (
	// ClipboardRefused has the library refuse the read itself: an empty
	// OSC 52 reply, an EPERM status for the Kitty protocol's OSC 5522,
	// which the binding drops, as the read of a terminal that is not the
	// one to answer. It is the zero value.
	ClipboardRefused ClipboardAnswer = iota
	// ClipboardAnswered answers the read with ClipboardReply.Contents
	// now, which the library encodes as it returns.
	ClipboardAnswered
	// ClipboardDeferred holds the library's refusal back and answers the
	// read later with Terminal.AnswerClipboard, which needs a
	// ClipboardReply carrying a DeferredClipboardRead.
	ClipboardDeferred
)

type ClipboardRead

type ClipboardRead struct {
	// Mimes are the types asked for, in order of preference; List asks
	// for the types available.
	Mimes []string
	List  bool
	// Primary is the selection clipboard of X11.
	Primary bool
	// Granted tells that the program holds the terminal's permission, as
	// when it reads what a paste offered it.
	Granted bool
	// CanRemember tells that the program asked with a password (the one
	// a paste event gave it, with its name): a terminal that pasted
	// knows it — Granted says so — and one that does not never can, and
	// leaves the read to the one it is for.
	CanRemember bool
}

ClipboardRead is a program's request to read the clipboard.

type ClipboardReply

type ClipboardReply struct {
	Contents  map[string][]byte
	Available []string
	// Deferred is the read to answer later, with ClipboardDeferred.
	Deferred *DeferredClipboardRead
}

ClipboardReply answers a ClipboardRead: Contents by MIME type, of the types asked for, and Available when the list was asked for. Without contents the read is refused. A deferred read carries Deferred instead.

type Color

type Color struct {
	Kind  uint8 // 0 none, 1 palette, 2 RGB
	Index uint8
	RGB   RGB
}

Color is the color of a style: none (the default), an index of the palette, or an RGB color.

type Colors

type Colors struct {
	Background, Foreground RGB
	// Cursor is the cursor's color when HasCursor is set; it takes the
	// text's otherwise.
	Cursor    RGB
	HasCursor bool
	Palette   [256]RGB
}

Colors are the colors of a frame: those programs set, else the defaults.

type Cursor

type Cursor struct {
	// InView reports that the cursor is in the viewport, at column X of
	// row Y; WideTail that it is on the second half of a wide character.
	InView   bool
	X, Y     int
	WideTail bool
	// Visible reports that programs show the cursor, Blinking that it
	// blinks, Password that the program reads a password.
	Visible, Blinking, Password bool
	Style                       CursorStyle
}

Cursor is the cursor of a frame.

type CursorStyle

type CursorStyle int32

CursorStyle is the shape of the cursor.

const (
	CursorBar CursorStyle = iota
	CursorBlock
	CursorUnderline
	CursorBlockHollow
)

type DeferredClipboardRead

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

DeferredClipboardRead is a read the embedder answers after its effect returned (ClipboardDeferred). The binding fills it as the library writes the refusal it holds back: kitty tells that the read came by the Kitty clipboard protocol (OSC 5522) rather than OSC 52; for OSC 52, prefix is the reply's beginning ("\x1b]52;" with the selector and its ";") and terminator how the request ended; refusal is what the library wrote to refuse the read (the empty OSC 52 reply, or the EPERM packet), which a denial writes again; mimes, list and primary are what the program asked for, and id is the id of a Kitty protocol read, echoed in its answer. Pass it to Terminal.AnswerClipboard.

type Dirty

type Dirty int32

Dirty is how much of a frame changed.

const (
	Clean Dirty = iota
	Partial
	Full
)

type Effects

type Effects struct {
	// WritePTY answers the program, as to a query of the cursor's
	// position. p is only valid during the call.
	WritePTY func(p []byte)
	Bell     func()
	// TitleChanged and PwdChanged tell that Title or Pwd changed.
	TitleChanged func()
	PwdChanged   func()
	// RenderHold tells that the program started or ended a synchronized
	// update (mode 2026), during which the screen should not show.
	RenderHold func(held bool)
	// Clipboard writes text to the clipboard (OSC 52), and reports
	// whether it did. primary is the selection clipboard of X11.
	Clipboard func(text string, primary bool) bool
	// ClipboardRead answers a program's read of the clipboard (OSC 52
	// with "?", the Kitty clipboard protocol's OSC 5522): the contents of
	// the MIME types asked for, and the types available when the program
	// asks for the list. ClipboardAnswered writes the reply, encoded, to
	// WritePTY in one call as ClipboardRead returns; ClipboardRefused
	// refuses it (an empty OSC 52 reply, EPERM for OSC 5522), and the
	// EPERM is dropped, so that a terminal that is not the one to answer
	// stays silent; ClipboardDeferred holds the refusal back and answers
	// later through Terminal.AnswerClipboard, for a terminal that must
	// ask the user first.
	ClipboardRead func(req ClipboardRead) (reply ClipboardReply, answer ClipboardAnswer)
	// Size reports the size of the screen in cells and of a cell in
	// pixels, for size reports.
	Size func() (cols, rows, cellWidth, cellHeight int)
	// Dark reports whether the colors are dark, for color scheme reports.
	Dark func() bool
	// Notify shows a desktop notification (OSC 9, OSC 777).
	Notify func(title, body string)
	// Progress reports the progress of the program (OSC 9;4): state is
	// 0 to remove it, 1 to set it to progress (0 to 100), 2 for an error,
	// 3 for indeterminate progress and 4 paused.
	Progress func(state, progress int)
}

Effects are what a terminal asks of its embedder while it processes output, all optional. They run during Terminal.Write, which they must not call.

type Geometry

type Geometry struct {
	Columns, CellWidth, PadLeft, Height int
}

Geometry is the grid in pixels, for drags.

type Gesture

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

Gesture turns presses and drags of the pointer into selections as Ghostty does: a click and a drag select cells, a double click words and a triple click lines, and dragging past the top or the bottom asks to scroll.

func NewGesture

func NewGesture(interval uint64, distance float64) (*Gesture, error)

NewGesture makes a gesture: repeated clicks count within interval nanoseconds of each other and distance pixels.

func (*Gesture) Autoscroll

func (g *Gesture) Autoscroll(t *Terminal) int

Autoscroll reports whether a drag past an edge asks to scroll up (-1) or down (1).

func (*Gesture) Drag

func (g *Gesture) Drag(t *Terminal, ref GridRef, x, y float64, geo Geometry, rect bool) (Selection, bool)

Drag moves the pressed pointer to cell ref at x, y pixels, selecting a rectangle when rect is set.

func (*Gesture) Dragged

func (g *Gesture) Dragged(t *Terminal) bool

Dragged reports whether the pointer moved to another cell since it was pressed.

func (*Gesture) Free

func (g *Gesture) Free(t *Terminal)

Free frees the gesture, which belongs to t (nil if it was never used).

func (*Gesture) Press

func (g *Gesture) Press(t *Terminal, ref GridRef, x, y float64, ns uint64) (Selection, bool)

Press presses the pointer on cell ref at x, y pixels, at time ns of a monotonic clock. A double or triple click selects at once.

func (*Gesture) Release

func (g *Gesture) Release(t *Terminal, ref *GridRef)

Release releases the pointer over cell ref, or outside the grid when ref is nil.

func (*Gesture) Reset

func (g *Gesture) Reset(t *Terminal)

Reset forgets the gesture's clicks.

func (*Gesture) Tick

func (g *Gesture) Tick(t *Terminal, col, row int, x, y float64, geo Geometry, rect bool) (Selection, bool)

Tick continues a drag past an edge after the viewport scrolled, with the pointer at x, y pixels over column col of row row of the viewport.

type GridRef

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

GridRef is a GhosttyGridRef: a cell of the terminal, valid until the terminal next changes.

type Image

type Image struct {
	ID            uint32
	Width, Height int
	Format        ImageFormat
	// Pixels are the image's, decoded; Generation changes when they do.
	Pixels     []byte
	Generation uint64
}

Image is an image of the Kitty graphics protocol.

type ImageFormat

type ImageFormat int32

ImageFormat is how an image's pixels are laid out (GhosttyKittyImageFormat).

const (
	ImageRGB       ImageFormat = 0
	ImageRGBA      ImageFormat = 1
	ImageGrayAlpha ImageFormat = 3
	ImageGray      ImageFormat = 4
)

Image formats: PNG is decoded to RGBA as an image arrives.

type Key

type Key int32

Key is a GhosttyKey: a key by its place on the keyboard, as the W3C's KeyboardEvent.code names them.

const (
	KeyUnidentified Key = iota
	KeyBackquote
	KeyBackslash
	KeyBracketLeft
	KeyBracketRight
	KeyComma
	KeyDigit0
	KeyDigit1
	KeyDigit2
	KeyDigit3
	KeyDigit4
	KeyDigit5
	KeyDigit6
	KeyDigit7
	KeyDigit8
	KeyDigit9
	KeyEqual
	KeyIntlBackslash
	KeyIntlRo
	KeyIntlYen
	KeyA
	KeyB
	KeyC
	KeyD
	KeyE
	KeyF
	KeyG
	KeyH
	KeyI
	KeyJ
	KeyK
	KeyL
	KeyM
	KeyN
	KeyO
	KeyP
	KeyQ
	KeyR
	KeyS
	KeyT
	KeyU
	KeyV
	KeyW
	KeyX
	KeyY
	KeyZ
	KeyMinus
	KeyPeriod
	KeyQuote
	KeySemicolon
	KeySlash
	KeyAltLeft
	KeyAltRight
	KeyBackspace
	KeyCapsLock
	KeyContextMenu
	KeyControlLeft
	KeyControlRight
	KeyEnter
	KeyMetaLeft
	KeyMetaRight
	KeyShiftLeft
	KeyShiftRight
	KeySpace
	KeyTab
	KeyConvert
	KeyKanaMode
	KeyNonConvert
	KeyDelete
	KeyEnd
	KeyHelp
	KeyHome
	KeyInsert
	KeyPageDown
	KeyPageUp
	KeyArrowDown
	KeyArrowLeft
	KeyArrowRight
	KeyArrowUp
)

Keys, in the order of GhosttyKey.

const (
	KeyEscape Key = KeyArrowUp + 1 + 41 + iota
	KeyF1
)

KeyEscape and the function keys follow the 41 keys of the numpad.

type KeyAction

type KeyAction int32

KeyAction is what happened to a key.

const (
	KeyRelease KeyAction = iota
	KeyPress
	KeyRepeat
)

type KeyEncoder

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

KeyEncoder encodes keys as the terminal's modes ask: legacy sequences, xterm's modifyOtherKeys or the Kitty keyboard protocol.

func NewKeyEncoder

func NewKeyEncoder() (*KeyEncoder, error)

NewKeyEncoder makes a key encoder.

func (*KeyEncoder) Encode

func (e *KeyEncoder) Encode(k KeyEvent) []byte

Encode returns the bytes the program reads for k, valid until the next call; nil for keys that send nothing.

func (*KeyEncoder) Free

func (e *KeyEncoder) Free()

Free frees the encoder.

func (*KeyEncoder) Sync

func (e *KeyEncoder) Sync(t *Terminal, optionAsAlt bool)

Sync takes the terminal's modes, and whether Option is Alt on macOS.

type KeyEvent

type KeyEvent struct {
	Action KeyAction
	Key    Key
	Mods   Mods
	// Consumed are the modifiers that made Text, as Shift an "A".
	Consumed Mods
	// Text is what the key types, without what Ctrl or Alt change; empty
	// for keys that type nothing.
	Text string
	// Unshifted is the character the key types without modifiers.
	Unshifted rune
	// Composing tells that an input method is composing.
	Composing bool
}

KeyEvent is a key to encode for the program.

type Mode

type Mode uint16

Mode is a GhosttyMode: a DEC private mode, or an ANSI one with bit 15.

const (
	ModeCursorKeys     Mode = 1
	ModeCursorVisible  Mode = 25
	ModeFocusEvent     Mode = 1004
	ModeAltScroll      Mode = 1007
	ModeBracketedPaste Mode = 2004
	// ModePasteEvents has a paste tell the program what the clipboard
	// holds, which it reads itself (the Kitty clipboard protocol).
	ModePasteEvents Mode = 5522
	ModeSyncOutput  Mode = 2026
	ModeGraphemes   Mode = 2027
	// ModeColorScheme has the terminal tell the program when its colors
	// go from light to dark or back (CSI ? 997 ; 1 n for dark, 2 light).
	ModeColorScheme Mode = 2031
)

Modes.

type Mods

type Mods uint16

Mods are modifier keys (GhosttyMods): Shift, Ctrl, Alt and Super.

const (
	ModShift Mods = 1 << iota
	ModCtrl
	ModAlt
	ModSuper
)

type MouseAction

type MouseAction int32

MouseAction is what the pointer did.

const (
	MousePress MouseAction = iota
	MouseRelease
	MouseMotion
)

type MouseEncoder

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

MouseEncoder encodes pointer events in the format and for the events the program asked for.

func NewMouseEncoder

func NewMouseEncoder() (*MouseEncoder, error)

NewMouseEncoder makes a mouse encoder.

func (*MouseEncoder) Encode

func (m *MouseEncoder) Encode(action MouseAction, button int, mods Mods, x, y float32) []byte

Encode returns the bytes the program reads for a pointer event at x, y pixels, valid until the next call; nil when it asked for no such event.

func (*MouseEncoder) Free

func (m *MouseEncoder) Free()

Free frees the encoder.

func (*MouseEncoder) Sync

func (m *MouseEncoder) Sync(t *Terminal, width, height, cellWidth, cellHeight, padLeft, padTop int, pressed bool)

Sync takes the terminal's mouse modes, the geometry of the screen in pixels, and whether a button is held.

type Placement

type Placement struct {
	ImageID, ID uint32
	// Virtual tells that the placement shows through the cells of Unicode
	// placeholders rather than where it is placed.
	Virtual bool
	// Col and Row are its top left cell on the screen, Row negative when
	// its top scrolled off; Visible tells that some of it shows.
	Col, Row int
	Visible  bool
	// XOffset and YOffset place it within its first cell, in pixels;
	// Width and Height are the pixels it takes on the screen, Cols and Rows
	// the cells.
	XOffset, YOffset int
	Width, Height    int
	Cols, Rows       int
	// SrcX, SrcY, SrcW and SrcH are the part of the image it shows, in the
	// image's pixels.
	SrcX, SrcY, SrcW, SrcH int
	// Z orders it: below the cells' backgrounds when below -1<<30, below
	// the text when negative, above it otherwise.
	Z int32
	// Params are the placement as a program asked for it: offsets, the
	// part of the image and the cells, 0 for what the image gives.
	ParamCols, ParamRows                       int
	ParamSrcX, ParamSrcY, ParamSrcW, ParamSrcH int
}

Placement is where a program placed an image (Kitty graphics), as the screen shows it now.

type RGB

type RGB struct{ R, G, B uint8 }

RGB is a GhosttyColorRgb.

type RenderState

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

RenderState is a GhosttyRenderState: what a frame draws of a terminal, copied from it by an update, with the rows that changed since the last frame marked dirty.

func NewRenderState

func NewRenderState() (*RenderState, error)

NewRenderState makes an empty render state.

func (*RenderState) BeginUpdate

func (r *RenderState) BeginUpdate(t *Terminal) error

BeginUpdate copies the terminal's state, the only step that needs the terminal; EndUpdate finishes the update without it.

func (*RenderState) CellGraphemes

func (r *RenderState) CellGraphemes(x int, buf []rune) []rune

CellGraphemes appends the codepoints of cell x of the row RowCells read to buf.

func (*RenderState) CellStyle

func (r *RenderState) CellStyle(x int) Style

CellStyle returns the style of cell x of the row RowCells read.

func (*RenderState) Clean

func (r *RenderState) Clean()

Clean marks everything drawn.

func (*RenderState) Colors

func (r *RenderState) Colors() Colors

Colors returns the colors of the frame.

func (*RenderState) Cursor

func (r *RenderState) Cursor() Cursor

Cursor returns the cursor of the frame.

func (*RenderState) Dirty

func (r *RenderState) Dirty() Dirty

Dirty reports how much changed since the last Clean.

func (*RenderState) EndUpdate

func (r *RenderState) EndUpdate()

EndUpdate finishes the update BeginUpdate started.

func (*RenderState) Free

func (r *RenderState) Free()

Free frees the render state.

func (*RenderState) NextRow

func (r *RenderState) NextRow() bool

NextRow moves to the next row, and reports whether there is one.

func (*RenderState) RowCells

func (r *RenderState) RowCells() []Cell

RowCells returns the cells of the row, valid until the next update.

func (*RenderState) RowDirty

func (r *RenderState) RowDirty() bool

RowDirty reports whether the row changed since the last Clean.

func (*RenderState) RowID

func (r *RenderState) RowID() RowID

RowID returns the identity of the row, which it keeps as it scrolls.

func (*RenderState) RowPrompt

func (r *RenderState) RowPrompt() RowPrompt

RowPrompt returns how the row belongs to a shell's prompt.

func (*RenderState) RowSelection

func (r *RenderState) RowSelection() (start, end int, ok bool)

RowSelection returns the selected columns of the row, from start to end inclusive.

func (*RenderState) RowWrapped

func (r *RenderState) RowWrapped() bool

RowWrapped reports whether the row soft-wraps into the next.

func (*RenderState) Rows

func (r *RenderState) Rows()

Rows starts going through the rows of the frame, top to bottom, with NextRow.

func (*RenderState) Size

func (r *RenderState) Size() (cols, rows int)

Size returns the size of the viewport in cells.

func (*RenderState) Update

func (r *RenderState) Update(t *Terminal) error

Update updates the render state from the terminal in one step.

type Result

type Result int32

Result is a GhosttyResult other than GHOSTTY_SUCCESS.

const (
	OutOfMemory Result = -1
	Invalid     Result = -2
	OutOfSpace  Result = -3
	NoValue     Result = -4
	IOError     Result = -5
	Exceeded    Result = -6
	Rejected    Result = -7
)

func (Result) Error

func (r Result) Error() string

type RowID

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

RowID identifies a row across render state updates (a GhosttyRenderStateRowId).

type RowPrompt

type RowPrompt int32

RowPrompt is how a row belongs to a shell's prompt, which the shell marks with OSC 133 (shell integration).

const (
	NoPrompt RowPrompt = iota
	// PromptStart is the row a prompt starts on (OSC 133;A).
	PromptStart
	// PromptContinuation is a row the prompt or its input goes on over:
	// one a long command wraps onto, or a prompt's next line.
	PromptContinuation
)

type Scrollbar

type Scrollbar struct {
	Total, Offset, Len uint64
}

Scrollbar is a GhosttyTerminalScrollbar: the rows of the screen and its scrollback, the first row of the viewport and how many rows it shows.

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

Search searches a terminal, its scrollback included, for text, as Ghostty's find does: matches follow the screen as it changes, and the screens as programs switch them. Matching is exact but for ASCII letters, whose case it ignores.

func NewSearch

func NewSearch(t *Terminal) (*Search, error)

NewSearch makes a search of t, which looks for nothing until SetText. Selecting a match scrolls nothing: the caller shows it where it likes.

func (*Search) Feed

func (s *Search) Feed()

Feed reads what changed of the terminal, a bounded amount at a time.

func (*Search) Free

func (s *Search) Free()

Free frees the search, before or after its terminal.

func (*Search) Select

func (s *Search) Select(back bool) bool

Select selects the next match toward older output, or toward newer output when back, wrapping around. It reports whether there was a match.

func (*Search) Selected

func (s *Search) Selected() (int, bool)

Selected returns the index of the selected match, 0 the newest, and reports whether one is.

func (*Search) SelectedMatch

func (s *Search) SelectedMatch() (Selection, bool)

SelectedMatch returns the selected match.

func (*Search) SetText

func (s *Search) SetText(text string)

SetText searches for text from scratch, or keeps the matches when it is the text searched already; "" searches for nothing.

func (*Search) Status

func (s *Search) Status() SearchStatus

Status returns how far the search went.

func (*Search) Tick

func (s *Search) Tick() SearchStatus

Tick makes a bounded amount of progress, without the terminal.

func (*Search) Total

func (s *Search) Total() int

Total returns how many matches the search found so far.

func (*Search) ViewportMatches

func (s *Search) ViewportMatches(buf []Selection) []Selection

ViewportMatches returns the matches on the pages the viewport shows, as of the last Feed, in buf's memory when it has room.

type SearchStatus

type SearchStatus int32

SearchStatus is how far a search went (GhosttySearchStatus).

const (
	// SearchRunning: Tick makes progress.
	SearchRunning SearchStatus = iota
	// SearchFeedRequired: Feed must read the terminal first.
	SearchFeedRequired
	// SearchComplete: the search caught up with the terminal as of the
	// last Feed.
	SearchComplete
)

type Selection

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

Selection is a GhosttySelection: two cells of the terminal, inclusive, valid until the terminal next changes.

func (*Selection) Ends

func (s *Selection) Ends() (start, end *GridRef)

Ends returns the cells a selection starts and ends at.

type Style

type Style struct {
	FG, BG, UnderlineColor                                                  Color
	Bold, Italic, Faint, Blink, Inverse, Invisible, Strikethrough, Overline bool
	Underline                                                               int
}

Style is how a cell's text shows.

func (Style) SGR

func (s Style) SGR() string

SGR returns the SGR sequence that sets the style from none.

type TermColors

type TermColors struct {
	Foreground, Background, Cursor          RGB
	HasForeground, HasBackground, HasCursor bool
	Palette                                 [256]RGB
}

TermColors are a terminal's colors; a color neither a program set nor a default gave is not Has.

type Terminal

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

Terminal is a GhosttyTerminal: the screen, its scrollback, the cursor and the modes, which the output of programs changes.

func NewTerminal

func NewTerminal(cols, rows int, effects Effects) (*Terminal, error)

NewTerminal makes a terminal of cols columns and rows rows.

func (*Terminal) Activity

func (t *Terminal) Activity() uint64

Activity returns a token that changes when the scrollback may compress.

func (*Terminal) AltScreen

func (t *Terminal) AltScreen() bool

AltScreen reports whether the alternate screen shows, as in full-screen programs.

func (*Terminal) AnswerClipboard

func (t *Terminal) AnswerClipboard(d *DeferredClipboardRead, allowed bool, contents map[string][]byte, available []string)

AnswerClipboard answers a read that the ClipboardRead effect deferred (ClipboardDeferred): allowed serves contents by MIME type, and available for the types listing (OSC 5522's "."), while denied writes the refusal the library wrote for the read and the binding held back. It is safe from any goroutine, and contents and available are not retained after it returns.

func (*Terminal) AtBottom

func (t *Terminal) AtBottom() bool

AtBottom reports whether the viewport follows the active screen, rather than showing the scrollback.

func (*Terminal) CellAt

func (t *Terminal) CellAt(x, y int) (GridRef, bool)

CellAt returns the cell at column x of row y of the viewport.

func (*Terminal) CellIsInput

func (t *Terminal) CellIsInput(ref GridRef) bool

CellIsInput reports whether OSC 133 marks a cell as shell input.

func (*Terminal) CellWide

func (t *Terminal) CellWide(ref GridRef) Wide

CellWide reports whether ref holds a character or a wide-character spacer.

func (*Terminal) Colors

func (t *Terminal) Colors(defaults bool) TermColors

Colors returns the colors programs see: those they set (OSC 4, 10, 11, 12) over the defaults, or with defaults the defaults alone.

func (*Terminal) Compress

func (t *Terminal) Compress() bool

Compress compresses some of the scrollback, as when the terminal is idle, and reports whether more is left to compress.

func (*Terminal) Cursor

func (t *Terminal) Cursor() (x, y int)

Cursor returns the cursor's column and row in the active screen, the bottom of the scrollback.

func (*Terminal) CursorAtPrompt

func (t *Terminal) CursorAtPrompt() bool

CursorAtPrompt reports whether OSC 133 places the cursor in the current shell prompt or input. Alternate-screen programs never qualify.

func (*Terminal) CursorInInput

func (t *Terminal) CursorInInput() bool

CursorInInput reports an active OSC 133 command-input phase at the cursor.

func (*Terminal) ExtendSelection

func (t *Terminal) ExtendSelection(ref GridRef) bool

ExtendSelection moves the selection's logical end to ref, keeping its original anchor even for a reversed selection. Read a fresh snapshot: grid references cannot be kept across output, scrolling or resizing.

func (*Terminal) Free

func (t *Terminal) Free()

Free frees the terminal.

func (t *Terminal) Hyperlink(ref GridRef) string

Hyperlink returns the URI of the hyperlink (OSC 8) of a cell, or "".

func (*Terminal) Image

func (t *Terminal) Image(id uint32) (Image, bool)

Image returns an image, its pixels copied; false when there is no such image or its pixels have yet to arrive.

func (*Terminal) ImageGeneration

func (t *Terminal) ImageGeneration(id uint32) uint64

ImageGeneration returns the generation of an image, 0 when there is no such image or its pixels have yet to arrive.

func (*Terminal) KittyKeyboardFlags

func (t *Terminal) KittyKeyboardFlags() int

KittyKeyboardFlags returns the flags of the kitty keyboard protocol programs set.

func (*Terminal) Mode

func (t *Terminal) Mode(m Mode) bool

Mode reports whether a mode is set.

func (*Terminal) ModifyOtherKeys

func (t *Terminal) ModifyOtherKeys() bool

ModifyOtherKeys reports whether xterm's modifyOtherKeys mode 2 is on (CSI > 4 ; 2 m). The library tells it in no GhosttyTerminalData, but a key encoder takes it from the terminal with the other modes: without the Kitty keyboard protocol, Ctrl+P is CSI 27 ; 5 ; 112 ~ in mode 2, and ^P otherwise.

func (*Terminal) MouseShape

func (t *Terminal) MouseShape() int

MouseShape returns the pointer shape a program asked for (OSC 22), a GhosttyMouseShape.

func (*Terminal) MouseTracking

func (t *Terminal) MouseTracking() bool

MouseTracking reports whether a program asked for mouse events.

func (*Terminal) PasteEvent

func (t *Terminal) PasteEvent(mimes []string) bool

PasteEvent tells the program what the clipboard offers a paste, by the MIME types, for it to read what it wants (mode 5522, the Kitty clipboard protocol); the program's reads come to Effects.ClipboardRead, granted. The event goes to the program through Effects.WritePTY. It reports whether the event was sent: it is not when the mode is not set or the terminal has no ClipboardRead, when the paste is the embedder's to encode (EncodePaste).

func (*Terminal) Placements

func (t *Terminal) Placements(fn func(Placement))

Placements calls fn with each placement of the screen that shows.

func (*Terminal) Pwd

func (t *Terminal) Pwd() string

Pwd returns the working directory the shell reported (OSC 7), as it reported it: a file URL, or a path.

func (*Terminal) Reset

func (t *Terminal) Reset()

Reset resets the terminal fully (RIS).

func (*Terminal) Resize

func (t *Terminal) Resize(cols, rows, cellWidth, cellHeight int) error

Resize sets the size of the screen in cells, and of a cell in pixels.

func (*Terminal) Row

func (t *Terminal) Row(y int) (prompt RowPrompt, wrap bool)

Row returns how row y of the viewport belongs to a shell's prompt, and whether it soft-wraps into the next.

func (*Terminal) RowText

func (t *Terminal) RowText(y int) (text []rune, cols []int)

RowText returns the text of row y of the viewport, and the column of each of its runes.

func (*Terminal) ScreenCellAt

func (t *Terminal) ScreenCellAt(x, y int) (GridRef, bool)

ScreenCellAt is CellAt in the rows of the screen and its scrollback, 0 the oldest, as ScreenRow numbers them.

func (*Terminal) ScreenRow

func (t *Terminal) ScreenRow(ref *GridRef) (int, bool)

ScreenRow returns the row of a cell among those of the screen and its scrollback, 0 the oldest, as ScrollToRow takes it.

func (*Terminal) ScreenRowText

func (t *Terminal) ScreenRowText(y int) (text []rune, cols []int)

ScreenRowText is RowText for a row of the screen and its scrollback.

func (*Terminal) ScreenRowWraps

func (t *Terminal) ScreenRowWraps(y int) bool

ScreenRowWraps reports whether row y of the screen and its scrollback soft-wraps into the next.

func (*Terminal) ScrollBy

func (t *Terminal) ScrollBy(rows int)

func (*Terminal) ScrollToBottom

func (t *Terminal) ScrollToBottom()

func (*Terminal) ScrollToRow

func (t *Terminal) ScrollToRow(row int)

func (*Terminal) ScrollToTop

func (t *Terminal) ScrollToTop()

ScrollToTop, ScrollToBottom, ScrollBy and ScrollToRow move the viewport: to the top of the scrollback, to the active screen, by rows (negative up), or to show row first.

func (*Terminal) ScrollbackRows

func (t *Terminal) ScrollbackRows() int

ScrollbackRows returns how many rows the scrollback holds.

func (*Terminal) Scrollbar

func (t *Terminal) Scrollbar() Scrollbar

Scrollbar returns where the viewport is in the scrollback.

func (*Terminal) SelectAll

func (t *Terminal) SelectAll() (Selection, bool)

SelectAll returns a selection of everything, scrollback included.

func (*Terminal) SelectionText

func (t *Terminal) SelectionText() (string, bool)

SelectionText returns the text of the selection, with soft-wrapped lines joined and trailing spaces trimmed, as Ghostty copies it.

func (*Terminal) SetColors

func (t *Terminal) SetColors(fg, bg RGB, cursor *RGB, palette *[256]RGB)

SetColors sets the default colors, which programs may change: the foreground, the background, the cursor's (nil for the text's) and the palette of 256 colors (nil for Ghostty's).

func (*Terminal) SetDefaultCursor

func (t *Terminal) SetDefaultCursor(s CursorStyle, blink bool)

SetDefaultCursor sets the cursor that programs reset to (DECSCUSR 0).

func (*Terminal) SetImageLimit

func (t *Terminal) SetImageLimit(bytes uint64)

SetImageLimit sets how many bytes the images of the Kitty graphics protocol may take, zero refusing them (and deleting those there are).

func (*Terminal) SetMode

func (t *Terminal) SetMode(m Mode, v bool)

SetMode sets a mode.

func (*Terminal) SetModeDefault

func (t *Terminal) SetModeDefault(m Mode, v bool)

SetModeDefault sets a mode, and the value a reset restores.

func (*Terminal) SetResizePullBack

func (t *Terminal) SetResizePullBack(v bool)

SetResizePullBack sets whether growing the screen pulls rows back from the scrollback, which a pseudo-terminal keeping its own screen, as Windows' ConPTY, cannot follow.

func (*Terminal) SetScrollback

func (t *Terminal) SetScrollback(n int)

SetScrollback limits the scrollback to about n bytes.

func (*Terminal) SetSelection

func (t *Terminal) SetSelection(s *Selection)

SetSelection selects s, or nothing when s is nil.

func (*Terminal) SetTerminfoName

func (t *Terminal) SetTerminfoName(name string)

SetTerminfoName sets the name of the terminfo entry the terminal reports (XTGETTCAP TN).

func (*Terminal) Size

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

Size returns the size of the screen in cells.

func (*Terminal) Text

func (t *Terminal) Text() string

Text returns the text of the screen and its scrollback, with soft-wrapped lines joined and trailing spaces trimmed.

func (*Terminal) Title

func (t *Terminal) Title() string

Title returns the title programs set (OSC 0, OSC 2).

func (*Terminal) VT

func (t *Terminal) VT() []byte

VT returns the terminal's state as escape sequences, which restore it in a terminal of the same size: the scrollback and the screen with their styles and hyperlinks, then the modes, the scrolling region, the tab stops, the working directory, the keyboard's flags and the cursor. The palette is left out, as the terminal it restores in has colors of its own.

func (*Terminal) ViewportPoint

func (t *Terminal) ViewportPoint(ref *GridRef) (x, y int, shown bool)

ViewportPoint returns the column and the row of the viewport of a cell, and reports whether the viewport shows it.

func (*Terminal) Write

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

Write processes output of the program.

type Wide

type Wide uint8

Wide is how wide a cell's character is.

const (
	Narrow Wide = iota
	// WideChar takes this cell and the next, a SpacerTail.
	WideChar
	SpacerTail
	// SpacerHead ends a soft-wrapped row before a wide character that did
	// not fit.
	SpacerHead
)

Jump to

Keyboard shortcuts

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