Documentation
¶
Overview ¶
Package terminal is a terminal for Golet's native UI: a view that runs a shell, or any program, in a pseudo-terminal, with the terminal emulator of Ghostty, libghostty-vt, and draws it with package ui.
term, err := terminal.New(terminal.Options{})
...
golet.NewWindow(golet.WindowOptions{Title: "Terminal", Content: ui.View(func(c ui.Frame) {
terminal.View(c, term).Fill()
})})
It does what terminals do: colors, styles and Unicode (wide characters, emoji, grapheme clusters), the scrollback with reflow on resize, the alternate screen of full-screen programs, the keyboard as legacy sequences or the Kitty keyboard protocol, mouse reporting, bracketed paste, focus reports, synchronized output, hyperlinks (OSC 8), titles, the working directory (OSC 7) and the clipboard (OSC 52, OSC 5522), which programs write through by default and read as Options.ClipboardRead allows. Selecting with the pointer copies as Ghostty does: a drag selects cells, a double click words and a triple click lines; Option (macOS) or Alt drags a rectangle.
libghostty-vt is a native library loaded at run time, with no cgo: `golet build` and `golet dev` put the build this package binds into the app, and programs run without them, as with `go run` and `go test`, download it once into the user's cache. See LibraryPath.
Index ¶
- func GhosttyThemes() []string
- func LibraryPath() (string, error)
- func Load() error
- func View(c *ui.Context, t *Terminal) ui.Element
- type Action
- type Clear
- type ClipboardAccess
- type ClipboardRequest
- type CopyOnSelect
- type CopySource
- type CursorStyle
- type Font
- type Keybind
- type Mirror
- type Options
- type Padding
- type PaddingColor
- type PasteProgress
- type PasteStatus
- type RightClickAction
- type SearchStatus
- type Terminal
- func (t *Terminal) ClearScreen() bool
- func (t *Terminal) ClearScrollback()
- func (t *Terminal) Close() error
- func (t *Terminal) Dir() string
- func (t *Terminal) Done() <-chan struct{}
- func (t *Terminal) EndSearch()
- func (t *Terminal) ExitCode() int
- func (t *Terminal) Feed(data []byte)
- func (t *Terminal) History() []byte
- func (t *Terminal) HoveredLink() (link string, path bool, at ui.Rect)
- func (t *Terminal) NewMirror() (*Mirror, error)
- func (t *Terminal) Paste(text string)
- func (t *Terminal) PasteData(d transfer.Data)
- func (t *Terminal) Resize(cols, rows int)
- func (t *Terminal) ResizePixels(cols, rows, cellWidth, cellHeight int)
- func (t *Terminal) Search(text string)
- func (t *Terminal) SearchNext()
- func (t *Terminal) SearchPrevious()
- func (t *Terminal) SearchStatus() SearchStatus
- func (t *Terminal) Send(data []byte)
- func (t *Terminal) SetCopyOnSelect(c CopyOnSelect)
- func (t *Terminal) SetFont(f Font)
- func (t *Terminal) SetMinimumContrast(ratio float32)
- func (t *Terminal) SetTheme(theme, dark *Theme)
- func (t *Terminal) Size() (cols, rows int)
- func (t *Terminal) Snapshot() []byte
- func (t *Terminal) Text() string
- func (t *Terminal) Title() string
- func (t *Terminal) UseTheme(theme *Theme)
- type Theme
- type Zoom
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GhosttyThemes ¶
func GhosttyThemes() []string
GhosttyThemes returns the names GhosttyTheme takes, sorted: those of the user's theme files and of the themes Ghostty ships.
func LibraryPath ¶
LibraryPath returns the libghostty-vt the terminal loads, the first of:
- the file $GOLET_GHOSTTY_VT names;
- the one among the app's resources (golet.PathResources), where `golet build` and `golet dev` put it, signed with the app on macOS;
- the one next to the executable;
- the one in the user's cache, where the CLI downloads it (<cache>/golet/natives/<sha256>/), which programs that are not packaged apps, as under `go run` and `go test`, download there when it is missing, checking its SHA-256.
Packaged apps never download it: build them with the CLI.
func Load ¶
func Load() error
Load loads libghostty-vt, once, from LibraryPath. New calls it; call it earlier to report a missing library before showing a terminal.
func View ¶
View shows the terminal in a window of native UI, and takes its keyboard input once it has the focus, which a click gives it. Size it like any element, as with Fill or Grow; its size sets the terminal's, in cells of the font. A terminal shows in one view at a time.
A key goes, in order, to a shortcut of the window or an element around the view (and on macOS to the menus' key equivalents), to Options.OnKey, to the terminal's keybinds (Options.Keybinds, over DefaultKeybinds: Command+C and Command+V copy and paste on macOS, as do Control+Shift+C and Control+Shift+V elsewhere), and to the program. Other Command keys on macOS never reach the program, and go to the app's shortcuts. The Edit menu's roles copy, paste and select all too. The wheel scrolls the scrollback unless the program takes the mouse, and zooms with Control held (Command on macOS; Options.OnZoom). Hold Shift to select while a program takes the mouse, and Command (Control elsewhere) to underline a link and open it on click: a hyperlink (OSC 8), a URL printed as text, or a file path with Options.OpenLink.
Types ¶
type Action ¶
type Action int
Action is what a key bound to it does (Keybind), as an action of Ghostty's keybind option.
const ( // ActionNone unbinds a key, which then goes to the program, as // Ghostty's unbind. ActionNone Action = iota // ActionIgnore takes the key and does nothing, as Ghostty's ignore. ActionIgnore // ActionCopy copies the selection, as copy_to_clipboard. It does // something only with a selection, and when Performable it also lets // go of it, so that the key's next press reaches the program, as // Windows Terminal's Control+C. ActionCopy // ActionPaste pastes the clipboard, as paste_from_clipboard: as the // view's Paste does (see Options.OnPaste). It does something only when // the clipboard holds something. ActionPaste // ActionSelectAll selects the scrollback and the screen, as // select_all. ActionSelectAll // ActionClearScreen clears the scrollback and the screen above the // cursor's line, which moves to the top, as clear_screen (and Kitty's // clear_terminal to_cursor). It does nothing on a full-screen // program's screen (the alternate screen), which it would break. ActionClearScreen // ActionIncreaseFontSize, ActionDecreaseFontSize and // ActionResetFontSize zoom a step in or out, or back to the font's // size, as increase_font_size:1, decrease_font_size:1 and // reset_font_size (see Options.OnZoom). ActionIncreaseFontSize ActionDecreaseFontSize ActionResetFontSize // ActionScrollPageUp, ActionScrollPageDown, ActionScrollToTop and // ActionScrollToBottom scroll the scrollback, as scroll_page_up, // scroll_page_down, scroll_to_top and scroll_to_bottom. They do // nothing on a full-screen program's screen, which has none. ActionScrollPageUp ActionScrollPageDown ActionScrollToTop ActionScrollToBottom )
type Clear ¶ added in v0.1.8
type Clear int
Clear is what the user clears (Options.OnClear).
const ( // ClearScreen clears the scrollback and the screen above the cursor's // line (ActionClearScreen and the context menu's Clear, // Terminal.ClearScreen). ClearScreen Clear = iota // ClearScrollback clears the scrollback (Terminal.ClearScrollback). // // Deprecated: the context menu's Clear, which asked it as Clear // Scrollback, clears as ActionClearScreen does: OnClear is asked // ClearScreen. ClearScrollback )
type ClipboardAccess ¶
type ClipboardAccess int
ClipboardAccess is what programs get when they read the clipboard (Options.ClipboardRead).
const ( // ClipboardDeny refuses a read: an empty clipboard for OSC 52, an // EPERM status for the Kitty protocol's OSC 5522. It is the zero // value, so reads stay refused until an app opts in. ClipboardDeny ClipboardAccess = iota // ClipboardAllow answers a read with what the clipboard holds. ClipboardAllow // ClipboardAsk asks the app first: Options.OnClipboardRequest when // set, else the terminal's own prompt in the view. ClipboardAsk // ClipboardForward leaves OSC 52 reads to the terminals that show // this one's Mirror frames, which pass them on: the terminal answering // is theirs, with their clipboard and their policy. This one answers // nothing, and refuses the Kitty protocol's reads (OSC 5522). ClipboardForward )
type ClipboardRequest ¶
type ClipboardRequest struct {
// Mimes are the MIME types the program asked for, in order of
// preference; empty when it asked only for what is available.
Mimes []string
// List tells that it asked for the types available (the Kitty
// protocol's targets listing), which is answered without asking.
List bool
// Primary is the selection clipboard of X11 (OSC 52's "s"/"p").
Primary bool
// Text is what the clipboard held as text when the request was seen,
// for a prompt about it.
Text string
// contains filtered or unexported fields
}
ClipboardRequest is a program's read of the clipboard that the app is asked about (Options.OnClipboardRequest).
func (*ClipboardRequest) Allow ¶
func (r *ClipboardRequest) Allow()
Allow answers the request with what the clipboard holds.
type CopyOnSelect ¶
type CopyOnSelect int
CopyOnSelect is where a selection is copied as it ends (Options.CopyOnSelect).
const ( // CopyOnSelectNone copies nothing, as Ghostty's none. CopyOnSelectNone CopyOnSelect = iota // CopyOnSelectClipboard copies to the clipboard, as Ghostty's // clipboard. CopyOnSelectClipboard )
type CopySource ¶
type CopySource int
CopySource is what copied text to the clipboard (Options.OnCopy).
const ( // CopyUser is the user's copy: ActionCopy's keys, the context menu's // Copy, or a secondary click that copies (RightClickCopy, // RightClickCopyOrPaste). CopyUser CopySource = iota // CopySelect is a selection Options.CopyOnSelect copied as it ended, // or as Select All made it. CopySelect // CopyProgram is a program's write to the clipboard (OSC 52). CopyProgram )
type CursorStyle ¶
type CursorStyle int
CursorStyle is the shape of the cursor.
const ( CursorBlock CursorStyle = iota CursorBar CursorUnderline )
type Font ¶
type Font struct {
// Family is the font family, a comma-separated list as
// ui.Element.Font takes it, to which ui.RegisterFont adds the app's
// own fonts: "monospace", the system's, when empty.
Family string
// Size is the size in DIPs: 13 when zero.
Size float32
// Weight is how heavy text is, from 100 (thin) to 900 (black), of the
// weights the family has: 400 when zero. Bold text is 300 heavier, and
// at least 700.
Weight int
// Features turn OpenType features of the font on and off by tag, as
// Ghostty's font-feature: "ss01" or "+ss01" turns one on, "calt=0" or
// "-calt" off, and "cv05=2" picks an alternate. Coding fonts make
// most of their ligatures with calt, and the others with liga.
Features []string
// LineHeight is the height of rows, as a multiple of the font's own
// line height: 1 when zero, and 1.2 rows 20% taller, as Ghostty's
// adjust-cell-height = 20%. Text is centered in its row.
LineHeight float32
// Thicken draws text with a thicker stroke, as Ghostty's font-thicken:
// on macOS, with Core Text's font smoothing at its strongest, whatever
// the text's color and the system's setting. It changes nothing on
// Linux and Windows.
Thicken bool
}
Font is the font of a terminal's text, with what Ghostty's font options set.
type Keybind ¶
Keybind binds a key, with exactly Mods held, to an action, as a line of Ghostty's keybind option: the view does the action instead of sending the key to the program. Key follows the keyboard layout, as ui.Key does.
Performable, as Ghostty's performable: prefix, takes the key only when the action does something: Control+C copies a selection, and without one goes on to the program, which it interrupts. A key the action leaves goes on as if unbound.
func DefaultKeybinds ¶
func DefaultKeybinds() []Keybind
DefaultKeybinds returns the keys a terminal binds unless Options.NoDefaultKeybinds, which are Ghostty's of the platform:
- on macOS, Command+C copies and Command+V pastes, Command+A selects all, Command+K clears the screen, Command+= (and +) and Command+- zoom, and Command+0 zooms back; Command+Home, End, Page Up and Page Down scroll, as do Shift+Page Up and Page Down;
- elsewhere, Control+Shift+C and Control+Insert copy, Control+Shift+V and Shift+Insert paste, Control+Shift+A selects all, Control+= (and +), Control+- and Control+0 zoom, and Shift+Page Up and Page Down scroll, as do Shift+Home and End on Linux;
- on Windows, also Windows Terminal's: Control+C copies when there is a selection (performable), Control+V pastes when the clipboard holds something (performable), Control+Shift+K clears the screen, and Control+Shift+Home, End, Page Up and Page Down scroll.
The keys that clear the screen and scroll are performable: a full-screen program, as an editor, gets them.
type Mirror ¶
type Mirror struct {
// contains filtered or unexported fields
}
Mirror frames what a terminal shows for another terminal to show, as a server that keeps a session's terminal sends its clients: Frame returns the VT sequences that bring a terminal showing the frames before to what this one shows now. The other terminal, as one whose Conn reads the frames, then shows this one's screen and scrollback cell for cell, with its cursor and the modes that change what it sends (the cursor keys', the keyboard protocols', the mouse's, bracketed paste), and never lays out a program's output itself: it cannot come to show something else, as a terminal fed the program's output from a snapshot can.
Frames draw rows where they are, and rows that scroll off pass through the other terminal's screen in order, so that its scrollback is this one's: rows this one's limit lets go of stay there, under its own limit. Soft wraps stay soft. The first frame, and a frame after the screen took another size, start the other terminal over. A frame does not come while a program holds a synchronized update (mode 2026), for up to a second, as the view's frames do not: Frame then reports that one is due.
Programs' writes to the clipboard (OSC 52) go on to the other terminal of each Mirror, and their reads with ClipboardForward to one of them, the first to frame, for it to answer.
Frames read the terminal as its view does, which takes the terminal's record of what changed since it last read it: a terminal a view shows too would not repaint all that changed. A Mirror is for a terminal no view shows, as a server's; many Mirrors of one terminal are fine.
type Options ¶
type Options struct {
// Command is the program the terminal runs and its arguments. Empty
// runs the user's shell as a login shell, as terminal apps do: $SHELL,
// else /bin/zsh on macOS and /bin/sh elsewhere; PowerShell on Windows.
Command []string
// Dir is the working directory of the program: the user's home
// directory when empty.
Dir string
// Env adds to the environment of the program, as "KEY=value". The
// terminal sets TERM=xterm-256color and COLORTERM=truecolor, and LANG
// to a UTF-8 locale when no locale is set, as when the app starts from
// the Finder.
Env []string
// Conn connects the terminal to something other than a program, such
// as a remote shell: what the terminal reads from it shows, and what
// is typed is written to it. Command, Dir and Env are then ignored. A
// Conn with a method Resize(cols, rows int) error is told the size;
// one with ResizePixels(cols, rows, cellWidth, cellHeight int) error
// is told it with the size of a cell in pixels instead, which the
// other end needs to answer a program's size queries and to read
// pointer reports in pixels (mode 1016) as this terminal sends them.
// A Conn with UseTheme(theme *Theme) error is told the colors the view
// shows, for the other end to answer a program's questions about them
// (Terminal.UseTheme).
Conn io.ReadWriteCloser
// ResizeByConn leaves the size of the screen to whoever reads Conn:
// the view tells Conn the size it fits, with its Resize, and the
// screen takes a size only as Terminal.Resize sets it. A client of a
// server that keeps the session's terminal, as a multiplexer's, calls
// Resize where the server's output says the server resized, so that
// its screen lays out each byte at the size the server's did. Resized
// at once, as the view resizes it otherwise, the screen would lay out
// at the new size the output the program wrote for the one before,
// which the server laid out at that one: a line would wrap here and
// not there, and the program's next redraw, which moves the cursor
// from where it thinks it is, would land elsewhere, as the server's
// screen would show to the next client attaching.
ResizeByConn bool
// Font is the font of the text: the system's monospaced font at 13
// DIPs when zero.
Font Font
// Theme sets the colors, and DarkTheme those in dark windows when set,
// as Ghostty's theme = light:…,dark:… does (GhosttyTheme returns
// Ghostty's themes). Without either, the terminal follows the window's
// light or dark appearance, with LightTheme and DarkTheme. Until a
// view shows the terminal, or UseTheme gives it other colors, programs
// asking its colors get Theme's.
Theme, DarkTheme *Theme
// Cursor is the shape of the cursor, which programs may change, and
// NoBlink keeps it from blinking unless a program asks it to.
Cursor CursorStyle
NoBlink bool
// Scrollback is about how many bytes of output the terminal keeps above
// the screen: 10 MB when zero, none when negative.
Scrollback int
// OptionAsAlt makes Option on macOS the Alt key of programs (Meta),
// rather than the key that types accented letters and symbols.
OptionAsAlt bool
// CopyOnSelect copies what the pointer selects as the selection
// ends, and what Select All selects: CopyOnSelectClipboard to the
// clipboard, as Ghostty's copy-on-select = clipboard. Ghostty's
// primary, the selection clipboard of Linux, is not there: ui has
// none. SetCopyOnSelect changes it.
CopyOnSelect CopyOnSelect
// Keybinds bind keys to actions over DefaultKeybinds, as Ghostty's
// keybind option: a binding replaces the defaults of its key and
// modifiers, and one to ActionNone unbinds them, so that the program
// gets the key. NoDefaultKeybinds starts from none, as Ghostty's
// keybind = clear. OnKey sees keys first; see View.
Keybinds []Keybind
NoDefaultKeybinds bool
// RightClick is what a secondary click does, as Ghostty's
// right-click-action: show the context menu when zero. A program that
// takes the mouse gets the click instead, unless Shift is held.
RightClick RightClickAction
// NoClipboardWrite keeps programs from writing to the clipboard (OSC
// 52, OSC 5522), as Ghostty's clipboard-write = deny. Writes go
// through unless it is set; reads are governed by ClipboardRead.
NoClipboardWrite bool
// ClipboardRead is what programs get when they read the clipboard
// (OSC 52 with "?", OSC 5522): ClipboardDeny by default, so reads
// stay refused — refused with EPERM for OSC 5522 — until an app opts
// in, where Ghostty asks by default: a terminal that can ask needs a
// view, and one nobody shows leaves reads pending. What a paste
// offered a program is answered whatever the policy (see PasteData).
ClipboardRead ClipboardAccess
// Transparent leaves the terminal's background undrawn, so that what
// is under the view shows through, as the window's material or an
// element's translucent background, as Ghostty's background-opacity
// does: cells with a background color of their own still draw it, and
// so does the terminal a background a program set (OSC 11).
// Give the theme the background the view shows on, which the text
// under a block cursor takes.
Transparent bool
// Padding is the room around the grid, in DIPs, across (X) and down
// (Y), as Ghostty's window-padding-x and window-padding-y: 6 across
// and 4 down when zero; a negative value leaves none.
Padding Padding
// PaddingColor is what the padding shows, as Ghostty's
// window-padding-color: the background (PaddingBackground, the zero
// value), or the backgrounds of the cells nearest to it
// (PaddingExtend, PaddingExtendAlways), so that a full-screen
// program's colors reach the edges of the view.
PaddingColor PaddingColor
// MinimumContrast is the least contrast text has with its background,
// as Ghostty's minimum-contrast: a WCAG ratio from 1 (none, as when
// zero) to 21 (black on white). Text with less, as a program's light
// gray on a light theme, darkens or lightens as little as reaches it,
// keeping its hue. SetMinimumContrast changes it.
MinimumContrast float32
// ImageLimit is the most bytes the images programs show take (the
// Kitty graphics protocol), as Ghostty's image-storage-limit: 320 MB
// when zero; a negative limit refuses images, for programs to show
// something else.
ImageLimit int64
// OnTitle, OnExit, OnBell and OnNotify run on a goroutine of the
// terminal when a program sets the title, when the program (or Conn)
// ends, when it rings the bell, and when it asks for a desktop
// notification (OSC 9, OSC 777). Calls to the terminal are safe in
// them.
OnTitle func(title string)
OnExit func(code int)
OnBell func()
OnNotify func(title, body string)
// OnPasteStatus tells how a paste goes that a program reads itself
// (mode 5522, see PasteData), on a goroutine of the terminal: offered,
// then sending as the program reads, then sent; or not taken when the
// program has not read it 5 seconds after the offer was written, as a
// program that does not read pastes, or one far away over a slow link.
// A paste of no text to a program that reads neither the clipboard nor
// bracketed pastes, which pastes nothing, tells PasteNoText. An app
// shows a large image's progress, or why nothing pasted, this way.
OnPasteStatus func(p PasteProgress)
// OnClipboardRequest asks the app before a program reads the
// clipboard, when ClipboardRead is ClipboardAsk; without it the
// terminal draws its own prompt in the view. It runs on the main
// thread, with what the program asked for; Allow or Deny answers the
// request, in the hook or later and from any goroutine, and the first
// of them wins. A request the hook leaves unanswered stays pending,
// as does a read of a terminal no view shows.
OnClipboardRequest func(req ClipboardRequest)
// OnCopy runs on the main thread after the terminal writes text to the
// clipboard: the user's copy (ActionCopy's keys, the context menu, a
// secondary click), a selection Options.CopyOnSelect copied, or a
// program's (OSC 52), as by tells. An app may say so, as Ghostty's
// app-notifications = clipboard-copy does with a toast.
OnCopy func(text string, by CopySource)
// OnSearch runs on the main thread as the status of the search
// changes (Terminal.Search): as matches are found and selected, and
// once the search ends, with a zero status. A find bar shows its
// "1 of 3" this way.
OnSearch func(s SearchStatus)
// OpenLink takes what a Command+click (Control+click elsewhere)
// opens: a hyperlink (OSC 8), a URL printed as text, or, only with
// OpenLink set, a file path printed as text (absolute, ~/, ./ or ../,
// one with a slash, or a file name with a :line), as printed, a
// :line:col suffix included; a relative one is the program's, as of
// Dir. It runs on the main thread and reports whether it opened the
// link; a hyperlink or a URL it leaves, or every one when it is nil,
// opens with the system (Context.OpenURL), and a path it leaves does
// nothing.
OpenLink func(link string) bool
// OnPaste sees a paste of the clipboard (ActionPaste's keys, a Paste
// menu item, a secondary click with RightClickPaste) before the
// program gets it, on the main thread, with every format the
// clipboard holds, read as the paste starts. It reports whether it
// took the paste; a paste taken sends nothing, as when an app uploads
// the clipboard's files or image (d.Files, transfer.PNG) for a remote
// program, then pastes their paths with Paste.
OnPaste func(d transfer.Data) bool
// OnKey sees a key press before Keybinds and before the terminal
// encodes it, on the main thread, and reports whether it took the key;
// a key taken sends nothing, neither the text it types nor its
// release. Unlike a shortcut of an element around the view, which runs
// with the next frame, it keeps its place among the keys typed after
// it, as does what it sends with Send. A key that only types text may
// come as its text alone, as on Linux, which OnKey does not see.
OnKey func(mods ui.Modifiers, key ui.Key) bool
// OnScroll sees the wheel scroll the view by whole rows, negative up,
// before the terminal scrolls its scrollback, on the main thread, and
// reports whether it took the scroll; a scroll taken moves nothing. It
// is not asked while a program takes the wheel: as the mouse, unless
// Shift is held, or, on a full-screen program's screen, as arrow keys
// (alternate scroll, which "\x1b[?1007l" turns off). It suits a Conn
// whose history lives at the other end, as a remote multiplexer
// streaming only its screen.
OnScroll func(rows int) bool
// OnZoom sees a zoom, on the main thread: the wheel with Control held
// (Command on macOS), before OnScroll and a program that takes the
// mouse, or a key bound to a font size action. It reports whether it
// took the zoom, as an app that sizes all its text at once does; a
// zoom it leaves, or every one without it, changes the terminal's font
// size, a DIP a step, as Ghostty's increase_font_size:1 does, and back
// to Font's size on a reset. Returning true from every zoom turns
// zooming off.
OnZoom func(z Zoom) bool
// OnClear sees the user's clear on the main thread, before the
// terminal clears: ClearScreen for ActionClearScreen's keys and the
// context menu's Clear. It reports
// whether it took the clear; a clear taken clears nothing here. A
// terminal that shows a server's (see Mirror) takes it, for the
// server's terminal to clear (Terminal.ClearScreen), which the next
// frame shows: cleared here
// alone, the server's frames, drawn from a screen still full, would
// bring rows back wrong. It is not asked on a full-screen program's
// screen, which ActionClearScreen leaves alone.
OnClear func(c Clear) bool
}
Options configure a terminal.
type Padding ¶
type Padding struct{ X, Y float32 }
Padding is the room around a terminal's grid, in DIPs (Options.Padding).
type PaddingColor ¶
type PaddingColor int
PaddingColor is what the padding around a terminal's grid shows (Options.PaddingColor), as Ghostty's window-padding-color.
const ( // PaddingBackground shows the terminal's background, or nothing when // it is Transparent. PaddingBackground PaddingColor = iota // PaddingExtend extends the backgrounds of the cells nearest to the // padding into it: a row's beside it, the top and the bottom rows' // above and below the grid, as Ghostty's extend: those of rows whose // every cell has a background of its own, as a full-screen program // painting its own background has, so that a shell's highlights, a // program's tabs or the box it draws keep to their cells. A lone // character in inverse video, as a program draws its own cursor, // keeps its background in its cell. PaddingExtend // PaddingExtendAlways extends the backgrounds of every row's cells // nearest to the padding, as Ghostty's extend-always, but for a lone // character in inverse video's. PaddingExtendAlways )
type PasteProgress ¶
type PasteProgress struct {
Status PasteStatus
// Sent and Total count the bytes of the reply written to the program,
// encoded as the protocol sends them (base64 and its packets), for
// PasteSending and PasteSent: Total is known once the program reads.
Sent, Total int64
}
PasteProgress is how a paste a program reads itself goes (OnPasteStatus).
type PasteStatus ¶
type PasteStatus int
PasteStatus is how a paste a program reads itself goes (OnPasteStatus).
const ( // PasteOffered: the program was told what the paste holds. PasteOffered PasteStatus = iota // PasteSending: the program reads it, and Sent of Total went so far. PasteSending // PasteSent: all of it went. PasteSent // PasteNotTaken: the program has not read it 5 seconds after it was // offered. It may still, as long as no other paste comes. PasteNotTaken // PasteNoText: the paste had no text, as only an image, and the // program reads neither the clipboard nor bracketed pastes (mode // 2004), so nothing was pasted. A program that takes bracketed // pastes gets an empty one. PasteNoText )
type RightClickAction ¶
type RightClickAction int
RightClickAction is what a secondary click does (Options.RightClick), as Ghostty's right-click-action.
const ( // RightClickContextMenu shows the context menu: Copy, Paste, Select // All and Clear. RightClickContextMenu RightClickAction = iota // RightClickPaste lets go of the selection and pastes. RightClickPaste // RightClickCopy copies the selection and lets go of it. RightClickCopy // RightClickCopyOrPaste copies the selection and lets go of it, or // pastes when there is none, as Windows Terminal's secondary click. RightClickCopyOrPaste // RightClickIgnore does nothing. RightClickIgnore )
type SearchStatus ¶ added in v0.1.8
type SearchStatus struct {
// Text is what the search looks for: "" when none goes.
Text string
// Total counts the matches found so far, on the screen that shows: a
// full-screen program's, or the main screen's with its scrollback.
// Selected is the selected match's place among them, 1 the newest, as
// a find bar's "1 of 3"; 0 when none is.
Total, Selected int
// Searching tells that the search has more of the scrollback to go
// through: Total may grow.
Searching bool
}
SearchStatus is how a search of the terminal goes (Terminal.Search, Options.OnSearch).
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal is a terminal emulator and the program it runs. Its methods are safe from any goroutine.
func New ¶
New makes a terminal running opts.Command, or connected to opts.Conn. The program starts once a view shows the terminal, at the size of the view, or half a second later at 80×24 when none does.
func (*Terminal) ClearScreen ¶ added in v0.1.8
ClearScreen clears the scrollback and the screen above the cursor's line, which moves to the top, as ActionClearScreen does and Kitty's clear_terminal to_cursor: the prompt the shell shows stays, and the shell, which moves its cursor from where it is, goes on drawing there. A full-screen program's screen, which this would break, is left alone, as in Ghostty; it reports whether it cleared. A server calls it for a window that shows its terminal (Options.OnClear).
func (*Terminal) ClearScrollback ¶ added in v0.1.8
func (t *Terminal) ClearScrollback()
ClearScrollback clears the scrollback, leaving the screen as it is.
func (*Terminal) Close ¶
Close closes the terminal: the program is hung up (SIGHUP), or Conn closed, and the terminal frees its memory. A view of it then shows nothing.
func (*Terminal) Dir ¶
Dir returns the working directory the shell reported (OSC 7, which the shells of macOS report), or "".
func (*Terminal) Done ¶
func (t *Terminal) Done() <-chan struct{}
Done is closed once the program exited (or Conn ended).
func (*Terminal) EndSearch ¶ added in v0.1.8
func (t *Terminal) EndSearch()
EndSearch ends the search, and its highlights.
func (*Terminal) ExitCode ¶
ExitCode returns the exit code of the program once it exited: 128 plus the signal's number for a program a signal killed, -1 for one that could not start.
func (*Terminal) History ¶
History returns what the terminal shows as rows of VT sequences, for a terminal that takes the session over, as after the program that wrote them ended: the scrollback and the screen down to the cursor's row, or to the last row with something on it when that is above, without the cursor and the modes. Fed to a terminal of the same width, it leaves the cursor below what it shows, for the next program to start under it, not over it. A full-screen program's screen has no history: History returns nothing while the alternate screen shows.
func (*Terminal) HoveredLink ¶ added in v0.1.8
HoveredLink returns the link Command (Control elsewhere) is held over in the view, which a click opens and which shows underlined, as Options.OpenLink takes it; whether it is a file path; and the rectangle of its cells in DIPs, relative to the view. It returns "" over no link, or while no view shows the terminal. An app shows a preview of a link with it, over the view: read it in the view function, after View.
func (*Terminal) NewMirror ¶
NewMirror returns a Mirror of the terminal, whose first frame starts the other terminal over. Close frees it.
func (*Terminal) Paste ¶
Paste pastes text, as PasteData does: bracketed when the program asks (mode 2004), so that it does not run as commands as it would typed, or offered to a program that reads the clipboard itself (mode 5522), which reads it as text/plain.
func (*Terminal) PasteData ¶
PasteData pastes data, as the paste keys paste the clipboard. A program that reads the clipboard itself (mode 5522, the Kitty clipboard protocol, as programs that take images do) is offered d's formats as MIME types (a file list as text/uri-list) and reads those it wants, even over SSH; any other gets d's text (transfer.Text), bracketed when it asks (mode 2004). With no text but other formats, as only an image, a program that asks for bracketed pastes gets an empty one, as VS Code's terminal sends, and any other nothing.
The terminal keeps a snapshot of d until the program reads it or another paste comes, and answers only that read: other terminals showing the same program, as other windows on a session, stay silent. A representation made with transfer.Lazy is read only when the program asks for it, on a goroutine of the terminal while it processes the program's output: its provider must not call the terminal nor wait on the main thread.
func (*Terminal) Resize ¶
Resize sets the size of the screen in cells, for a terminal no view shows, as one a server keeps for a session while no window does: a view sets the size of the terminal it shows.
func (*Terminal) ResizePixels ¶ added in v0.1.8
ResizePixels is Resize with the size of a cell in pixels, for a terminal no view shows that stands for one that does, as a server's for the window showing its session: programs asking the size in pixels get it, and it is what pointer reports in pixels (mode 1016) count in. A zero cell size keeps the one before.
func (*Terminal) Search ¶ added in v0.1.8
Search searches the screen and the scrollback for text, as Ghostty's find does, and highlights the matches (Theme.Search) as they are found, following the output that comes; the newest match is selected and shown, scrolling to it. Matching is exact but for the case of ASCII letters, which it ignores. Searching for the text searched already keeps the selected match; "" ends the search, as EndSearch. A view drives the search, which goes on in the frames that show the terminal.
func (*Terminal) SearchNext ¶ added in v0.1.8
func (t *Terminal) SearchNext()
SearchNext selects the next match of the search toward older output, up the screen and into the scrollback, wrapping around past the oldest, and unless it shows scrolls it to the middle of the view, clear of a find bar over an edge; SearchPrevious goes the other way.
func (*Terminal) SearchPrevious ¶ added in v0.1.8
func (t *Terminal) SearchPrevious()
func (*Terminal) SearchStatus ¶ added in v0.1.8
func (t *Terminal) SearchStatus() SearchStatus
SearchStatus returns how the search goes.
func (*Terminal) SetCopyOnSelect ¶
func (t *Terminal) SetCopyOnSelect(c CopyOnSelect)
SetCopyOnSelect changes where a selection is copied as it ends, as Options.CopyOnSelect, as when the user changes a setting.
func (*Terminal) SetFont ¶
SetFont changes the font, as Options.Font, and the size a reset zooms back to; the font takes its size, as zooming did not happen.
func (*Terminal) SetMinimumContrast ¶ added in v0.1.8
SetMinimumContrast changes the least contrast of text with its background, as Options.MinimumContrast.
func (*Terminal) Snapshot ¶
Snapshot returns what the terminal shows as escape sequences: its scrollback and screen with their styles, the cursor and the modes programs set. Fed to a new terminal of the same size, it shows the same, as a terminal attaching again to a session a server keeps.
func (*Terminal) Text ¶
Text returns the text of the screen and its scrollback, with the lines a program's long output wrapped joined.
func (*Terminal) UseTheme ¶ added in v0.1.8
UseTheme gives a terminal no view shows the colors of one that does, as a server's for the window showing its session: programs asking the colors (OSC 4, 10, 11, 12), or whether they are dark (CSI ? 996 n), get them. A view's own theme takes over in a terminal it shows.
type Theme ¶
type Theme struct {
Foreground, Background ui.Color
// Cursor colors the cursor: the foreground when zero. CursorText
// colors the text under a block cursor: the background when zero.
Cursor, CursorText ui.Color
// Selection highlights the selected text: the foreground, a third
// opaque, when zero. SelectionText colors the selected text: its own
// colors when zero.
Selection, SelectionText ui.Color
// Search highlights the matches of a search (Terminal.Search) and
// SearchText colors their text, as Ghostty's search-background and
// search-foreground; SearchSelected and SearchSelectedText the selected
// match, as search-selected-background and search-selected-foreground.
// Ghostty's colors when zero: a light amber and a light orange, under
// black text.
Search, SearchText, SearchSelected, SearchSelectedText ui.Color
// Palette holds the 16 colors of programs: black, red, green, yellow,
// blue, magenta, cyan and white, then their bright kinds.
Palette [16]ui.Color
}
Theme is the colors of a terminal, which programs may change (OSC 4, 10, 11, 12) until the terminal resets. GhosttyTheme returns Ghostty's themes.
func DarkTheme ¶
func DarkTheme() *Theme
DarkTheme returns the colors of terminals in dark windows: the window's background and text, with Visual Studio Code's palette.
func GhosttyTheme ¶
GhosttyTheme returns a theme of Ghostty's by its name, as Ghostty's theme option takes it ("Catppuccin Mocha", "Dracula", "Rose Pine Dawn"…): a theme file of the user's in Ghostty's themes directory ($XDG_CONFIG_HOME/ghostty/themes, ~/.config/ghostty/themes by default), else one of the themes Ghostty ships, which the plugin carries, of any case; or the theme file a path names. Each call returns a new Theme.
func LightTheme ¶
func LightTheme() *Theme
LightTheme returns the colors of terminals in light windows: the window's background and text, with Visual Studio Code's palette.
func ParseGhosttyTheme ¶
ParseGhosttyTheme reads a theme in Ghostty's format, Ghostty's configuration's lines that set colors:
palette = 0=#45475a … palette = 15=#a6adc8 background = #1e1e2e foreground = #cdd6f4 cursor-color = #f5e0dc cursor-text = #1e1e2e selection-background = #f5e0dc selection-foreground = #1e1e2e
Colors are in hex (#rgb, #rrggbb, rrggbb…). Other lines of Ghostty's configuration are ignored, as are the palette's colors past the 16th, and the colors set to cell-foreground or cell-background, which the terminal then picks itself (see Theme). The colors a theme leaves out are those of DarkTheme, or LightTheme when its background is light.
type Zoom ¶
type Zoom struct {
// Steps is how many steps, larger positive: a notch of the wheel
// rolled up, or a press of a key bound to ActionIncreaseFontSize, is
// 1. A trackpad's moves add up to notches.
Steps int
// Reset asks for the size of Font back (ActionResetFontSize).
Reset bool
}
Zoom is a change of the font's size the user asks for (Options.OnZoom).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
libbuild
command
Libbuild builds libghostty-vt for every platform Golet supports from Ghostty's sources at a commit, with Zig (the version Ghostty asks for), and writes golet-plugin.json, which names the files and their SHA-256 for the CLI and the terminal package, and ghostty_themes.go, the themes that Ghostty ships:
|
Libbuild builds libghostty-vt for every platform Golet supports from Ghostty's sources at a commit, with Zig (the version Ghostty asks for), and writes golet-plugin.json, which names the files and their SHA-256 for the CLI and the terminal package, and ghostty_themes.go, the themes that Ghostty ships: |
|
library
Package library finds libghostty-vt for the terminal plugin: next to the app, in the user's cache, or downloaded there, as golet-plugin.json names it.
|
Package library finds libghostty-vt for the terminal plugin: next to the app, in the user's cache, or downloaded there, as golet-plugin.json names it. |
|
pty
Package pty runs processes in pseudo-terminals, in pure Go: /dev/ptmx on macOS and Linux, ConPTY on Windows.
|
Package pty runs processes in pseudo-terminals, in pure Go: /dev/ptmx on macOS and Linux, ConPTY on Windows. |
|
vt
Package vt binds libghostty-vt, the terminal emulator of Ghostty, which it loads at run time through purego: no cgo.
|
Package vt binds libghostty-vt, the terminal emulator of Ghostty, which it loads at run time through purego: no cgo. |