Documentation
¶
Overview ¶
Terminal output stage that turns Bubble Tea views into the fewest bytes a measured terminal needs
Index ¶
- Constants
- Variables
- func Exec(cmd *exec.Cmd, fn func(error) tea.Msg) tea.Cmd
- func JobControl() bool
- func Opening(title string) string
- func Suspend(line string) tea.Cmd
- func Title(mark string, parts ...string) string
- type Cell
- type Color
- type ColorAnswerMsg
- type Frame
- type FrameStat
- type GoneMsg
- type Identity
- type Note
- type NoteForm
- type Notifier
- type Picture
- type Pictures
- type Program
- func (p *Program) OnFrame(fn func(FrameStat))
- func (p *Program) OnPanic(fn func(any))
- func (p *Program) OnRelease(forget func() []byte, sweep func() string)
- func (p *Program) Pictures(pics Pictures)
- func (p *Program) Run() (model tea.Model, err error)
- func (p *Program) Send(msg tea.Msg)
- func (p *Program) SuspendLine(fn func() string)
- func (p *Program) Terminated() syscall.Signal
- func (p *Program) Write(b []byte) (int, error)
- type Renderer
- func (r *Renderer) Clear()
- func (r *Renderer) Err() error
- func (r *Renderer) Flush(now time.Time) time.Duration
- func (r *Renderer) Hold()
- func (r *Renderer) Loop(interval time.Duration, done <-chan struct{})
- func (r *Renderer) Release()
- func (r *Renderer) Render(v tea.View)
- func (r *Renderer) Reply(msg tea.Msg) bool
- func (r *Renderer) Resize(w, h int)
- func (r *Renderer) SetProfile(p colorprofile.Profile)
- func (r *Renderer) Show(pics Pictures)
- func (r *Renderer) Unhold()
- func (r *Renderer) Write(p []byte) (int, error)
- type Style
- type SuspendRefusedMsg
- type TerminateMsg
Constants ¶
const ( AttrBold uint8 = 1 << iota AttrFaint AttrItalic AttrBlink AttrRapidBlink AttrReverse AttrConceal AttrStrike )
Text attributes a cell carries
const ( UnderNone uint8 = iota UnderSingle UnderDouble UnderCurly UnderDotted UnderDashed )
Underline shapes
Variables ¶
var ErrTerminalGone = errors.New("tty: the terminal is gone")
Failure of a program whose terminal went away under it
Functions ¶
func Exec ¶
Runs a command on the terminal, the program paused and its screen given back, fn's message delivered after
func JobControl ¶
func JobControl() bool
Whether a shell's job control can stop and continue this process group, false for a group the kernel holds orphaned
func Opening ¶
A terminal's title opening a sentence: a name stays as its terminal writes it, words before one start with a capital
func Suspend ¶
Gives the terminal back, writes the line and stops the process group for the shell, refused without job control
func Title ¶
Title returns the title of the terminal's window and tab made of a mark and parts: the mark, then every part that says something, whole, joined by a middle dot. The terminal shows as much of the title as its tab has room for. Every escape sequence and control character is left out, so no part, such as a title a model wrote, can end the title's sequence and write one of its own.
Types ¶
type Cell ¶
One grid column, a cluster's first column holding its text and width, the rest holding width zero
type Color ¶
type Color uint32
Color packed as a kind byte over a palette index or 24 bit RGB, zero for the default
type ColorAnswerMsg ¶
What the terminal answered of the color of its background, OSC 11, or of its foreground, OSC 10, whole as it sent it: the model takes it in place of Bubble Tea's own reading of it, which scales parts of one or three hex digits wrongly and reads a part that is no number as nothing, and which the program holds back where it reads the answers itself
type FrameStat ¶
type FrameStat struct {
At time.Time
// Time the model took to build the view the frame shows
View time.Duration
// Time the renderer took to turn the view into bytes
Compose time.Duration
// Time the terminal took to accept the bytes
Write time.Duration
Bytes int
// The frame erased the whole screen and wrote it again, pixel images with it
Erased bool
}
Timing of one frame the renderer wrote to the terminal
type GoneMsg ¶
type GoneMsg struct{ Err error }
Loss of the terminal without a hangup signal, every write to it failing, that the model answers by ending the program
type Identity ¶
type Identity struct {
// Name of a terminal known by name, lower case: kitty, ghostty, wezterm, konsole, rio, vscode, iterm, mintty, hyper, foot, xterm, mlterm,
// alacritty, warp, apple, urxvt, vte, linux or dumb. Else TERM lower cased, empty where the environment names none
Name string
// tmux stands between the program and the terminal, which passes a sequence on to the terminal under it while its allow-passthrough
// option is on
Tmux bool
// GNU screen stands between them, tmux not
Screen bool
// The program runs over SSH, the terminal on another computer
Remote bool
}
The terminal a program runs in as its environment names it, and what stands between the two: the one identification of the terminal the app reads what it supports by, its images and its notifications alike
func Identify ¶
The terminal the environment names: by a specific TERM first, then by the marks of terminals that keep TERM generic, then by TERM_PROGRAM, then by marks a terminal leaves its children, which a terminal started inside another inherits, so those of a parent lose to fresher ones
type Note ¶
What a notification says: its title and one line under it, and for Warp the event it is of, stop as a reply ends and permission_request as the agent waits on the user, with the session and the folder it works in. The identity kitty keeps its parts together by
type NoteForm ¶
type NoteForm int
How a terminal shows a notification of the desktop a program asks for
const ( // It shows none, so nothing is sent NoteNone NoteForm = iota // iTerm2's OSC 9, which alpha sends every terminal: one line of text NoteOSC9 // rxvt's OSC 777 notify, which foot, WezTerm, Ghostty and the terminals of VTE take: a title and a body NoteOSC777 // kitty's OSC 99: a title and a body, each in base64 so nothing in them reads as part of the sequence NoteOSC99 )
type Notifier ¶
type Notifier struct {
Form NoteForm
Name string
Warp int
// Wrapped for tmux, which passes a sequence on to the terminal under it when its allow-passthrough option is on
Tmux bool
// Wrapped for GNU screen
Screen bool
}
The terminal a program runs in as its notifications go: the form it takes, what it is called, the version of Warp's agent protocol where Warp renders its payload, and whether tmux or screen stands between the program and it
func NotifierOf ¶
The terminal the environment names, as Identify names it, and how it shows notifications. Any terminal it does not know takes OSC 9, as alpha sends it
type Picture ¶
type Picture struct {
// X and Y are the picture's top left cell, W and H the cells it covers.
X, Y, W, H int
// ID tells pictures apart. A picture with the same ID and cells as a drawn picture shows the same pixels, so it is not drawn again.
ID uint64
// Cheap marks a picture that costs a few bytes to draw again, such as a kitty placement for a stored image. The rows under a cheap
// picture may be scrolled, and the picture is drawn again after the scroll. The rows under any other picture are never scrolled.
Cheap bool
// Feeds marks a picture that may move the cursor to the row under it when drawn. On the last row that scrolls the screen, so a picture
// that feeds is never drawn on the last row.
Feeds bool
// Draw appends the bytes that draw the picture with the cursor at its top left cell. Erase appends the bytes that take it down. Erase is
// nil when the cells written over the picture cut it, such as sixel and iTerm2 images, and the renderer erases its cells instead.
Draw, Erase func([]byte) []byte
}
Picture is an image the terminal draws by screen position over a rectangle of cells that the frame keeps blank for it. The renderer draws it with the frame that shows it, in the same write: the pictures that go are taken down before anything else, the rows under a picture that stays are never scrolled unless it is cheap to draw again, and each picture is drawn once the cells under it are written. So no frame reaches the terminal with a picture away from its cells.
type Pictures ¶
type Pictures struct {
Placed []Picture
// Swaps maps the first frame's color to the shown frame's color for each picture in kitty cells. Kitty cells identify their image by their
// color, so a picture in kitty cells moves to another frame while the composed frame's cells stay the same.
Swaps map[Color]Color
}
Pictures are what a view shows by screen position, and the colors kitty cells are written in instead of the colors the frame gives them.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a Bubble Tea program with terminal bytes, modes, size, job control and restore owned by tty.
func NewProgram ¶
Program for the model, run on the process's terminal until it quits or ctx ends
func (*Program) OnFrame ¶
Has fn told the timing of every frame written to the terminal, set before Run
func (*Program) OnPanic ¶
Has fn told the value of a panic in the model before the program reports it and ends, set before Run
func (*Program) OnRelease ¶
OnRelease sets the functions that delete the images the pictures gave the terminal. forget returns the exact bytes, which are written before the session is given back, when the program is suspended, runs a command or ends. sweep returns bytes that delete the images without knowing them, which the guard writes if the program dies. Set before Run.
func (*Program) Pictures ¶
Pictures passes the renderer the pictures that the view being composed shows by screen position, and the renderer draws them with that view. Called from the model's View, on the event loop. Nothing is drawn before the program runs.
func (*Program) Run ¶
Run runs the program until it quits, with the terminal restored before anything it wrote to stderr is shown.
func (*Program) Send ¶
Sends a message to the model, waiting until the program runs and dropping it once the program ended
func (*Program) SuspendLine ¶
Has fn say the line written to the terminal given back as a stop signal of the operating system suspends the program, as Suspend's line is for a suspend the model asks for. Called on the event loop, set before Run, none when nil
func (*Program) Terminated ¶
Signal of the operating system that ended the program, zero when it ended on its own
func (*Program) Write ¶
Writes bytes to the terminal ahead of the next frame, in the order they are written, as the text of a raw command is: what pictures hand the terminal goes this way, so what hands an image over never follows what lets it go. Nothing is written before the program runs or once it ended
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer turns views into terminal bytes for one terminal, measuring the widths it draws before trusting them.
func NewRenderer ¶
Renderer writing to the terminal, sized w by h
func (*Renderer) Clear ¶
func (r *Renderer) Clear()
Clears the terminal and repaints the whole frame at the next write
func (*Renderer) Flush ¶
Writes whatever the terminal lacks, returning how long until a probe deadline wants another write, zero for none. The bytes are worked out under the renderer's lock and written without it: a terminal slow to take a large frame holds only the frame loop, never the event loop, which hands over the next view, takes a new size or a terminal answer meanwhile without waiting
func (*Renderer) Hold ¶
func (r *Renderer) Hold()
Stops writing frames until Unhold, the terminal belonging to someone else meanwhile. A frame on its way to the terminal is written whole first, so nothing of it follows once the hold is in force
func (*Renderer) Release ¶
func (r *Renderer) Release()
Release undoes everything the session set and tells the guard nothing is left to undo, the renderer ready to enter again. A frame on its way to the terminal is written in full first. Before the alternate screen is left, every kitty placement on the screen is deleted, and so is every image the pictures gave the terminal, since a terminal may clear its images once the alternate screen is left. The pictures send their images again when they are next drawn.
func (*Renderer) Reply ¶
Takes a terminal answer, reporting whether it was one tty asked for and so is no business of the program
func (*Renderer) Resize ¶
Resize takes a new terminal size, repainting everything at the next frame. The last view's pictures lie where the old size put them, so none is drawn until a view at the new size gives its own pictures.
func (*Renderer) SetProfile ¶
func (r *Renderer) SetProfile(p colorprofile.Profile)
Sets the color profile cells are mapped into
func (*Renderer) Show ¶
Show takes the pictures that the view being composed shows by screen position. They take effect with that view, so a frame never draws them over another view's cells.
type SuspendRefusedMsg ¶
type SuspendRefusedMsg struct{}
Answer to a suspend the program refused with the terminal untouched, no shell job control holding its process group
type TerminateMsg ¶
Stop request of the operating system, an interrupt, a terminate or a hangup, that the model answers by ending the program