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, columns int, parts ...string) string
- type Cell
- type Color
- type ColorAnswerMsg
- type Frame
- type FrameStat
- type GoneMsg
- type Identity
- type Note
- type NoteForm
- type Notifier
- type Program
- func (p *Program) OnFrame(fn func(FrameStat))
- func (p *Program) OnPanic(fn func(any))
- 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) 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 of the terminal's window and tab made of a mark and parts, as alpha composes it: the mark, then the parts that say something, the first cut to the columns given with an ellipsis, joined by a middle dot. 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 anew, 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 person, 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 Program ¶
type Program struct {
// contains filtered or unexported fields
}
Bubble Tea program whose terminal bytes, modes, size, job control and restore tty owns
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) Run ¶
Runs the program until it quits, 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
}
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()
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 whole first
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) SetProfile ¶
func (r *Renderer) SetProfile(p colorprofile.Profile)
Sets the color profile cells are mapped into
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