tty

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 32 Imported by: 1 module, 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

Terminal output stage that turns Bubble Tea views into the fewest bytes a measured terminal needs

Index

Constants

View Source
const (
	AttrBold uint8 = 1 << iota
	AttrFaint
	AttrItalic
	AttrBlink
	AttrRapidBlink
	AttrReverse
	AttrConceal
	AttrStrike
)

Text attributes a cell carries

View Source
const (
	UnderNone uint8 = iota
	UnderSingle
	UnderDouble
	UnderCurly
	UnderDotted
	UnderDashed
)

Underline shapes

Variables

View Source
var ErrTerminalGone = errors.New("tty: the terminal is gone")

Failure of a program whose terminal went away under it

Functions

func Exec

func Exec(cmd *exec.Cmd, fn func(error) tea.Msg) tea.Cmd

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 Suspend

func Suspend(line string) tea.Cmd

Gives the terminal back, writes the line and stops the process group for the shell, refused without job control

Types

type Cell

type Cell struct {
	Text  string
	Width uint8
	Style Style
	Link  uint32
	Rider string
	After string
}

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

func Basic

func Basic(n uint8) Color

Basic palette entry 0 to 15

func ColorOf

func ColorOf(c color.Color) Color

Packed form of any color, keeping basic and indexed colors as palette references

func Indexed

func Indexed(n uint8) Color

Entry of the 256 color palette

func RGB

func RGB(r, g, b uint8) Color

Direct 24 bit color

func (Color) Std

func (c Color) Std() color.Color

Standard library form of the color, nil for the default

type Frame

type Frame struct {
	W, H  int
	Cells []Cell
}

Grid of cells a view asks for, rows of W columns

func (*Frame) Row

func (f *Frame) Row(y int) []Cell

Row y of the frame

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
}

Timing of one frame the renderer wrote to the terminal

func (FrameStat) Total

func (s FrameStat) Total() time.Duration

Whole time the frame took from the model's view to the last byte written

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 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

func NewProgram(ctx context.Context, model tea.Model) *Program

Program for the model, run on the process's terminal until it quits or ctx ends

func (*Program) OnFrame

func (p *Program) OnFrame(fn func(FrameStat))

Has fn told the timing of every frame written to the terminal, set before Run

func (*Program) OnPanic

func (p *Program) OnPanic(fn func(any))

Has fn told the value of a panic in the model before the program reports it and ends, set before Run

func (*Program) Run

func (p *Program) Run() (model tea.Model, err error)

Runs the program until it quits, the terminal restored before anything it wrote to stderr is shown

func (*Program) Send

func (p *Program) Send(msg tea.Msg)

Sends a message to the model, waiting until the program runs and dropping it once the program ended

func (*Program) Terminated

func (p *Program) Terminated() syscall.Signal

Signal of the operating system that ended the program, zero when it ended on its own

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

func NewRenderer(out io.Writer, w, h int) *Renderer

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) Err

func (r *Renderer) Err() error

First write error, the terminal gone when it is not nil

func (*Renderer) Flush

func (r *Renderer) Flush(now time.Time) time.Duration

Writes whatever the terminal lacks, returning how long until a probe deadline wants another write, zero for none

func (*Renderer) Hold

func (r *Renderer) Hold()

Stops writing frames until Unhold, the terminal belonging to someone else meanwhile

func (*Renderer) Loop

func (r *Renderer) Loop(interval time.Duration, done <-chan struct{})

Writes frames as they come, at most once per interval, until done closes

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

func (*Renderer) Render

func (r *Renderer) Render(v tea.View)

Takes the view to show next, the latest one winning

func (*Renderer) Reply

func (r *Renderer) Reply(msg tea.Msg) bool

Takes a terminal answer, reporting whether it was one tty asked for and so is no business of the program

func (*Renderer) Resize

func (r *Renderer) Resize(w, h int)

Takes a new terminal size, repainting everything at the next frame

func (*Renderer) SetProfile

func (r *Renderer) SetProfile(p colorprofile.Profile)

Sets the color profile cells are mapped into

func (*Renderer) Unhold

func (r *Renderer) Unhold()

Lets frames flow again, the session entered anew at the next write

func (*Renderer) Write

func (r *Renderer) Write(p []byte) (int, error)

Takes bytes another writer meant for the terminal, written ahead of the next frame, noting the queries among them

type Style

type Style struct {
	Fg, Bg, Ul Color
	Under      uint8
	Attrs      uint8
}

Colors, underline shape and attributes of a cell, comparable with ==

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

type TerminateMsg struct{ Signal syscall.Signal }

Stop request of the operating system, an interrupt, a terminate or a hangup, that the model answers by ending the program

Jump to

Keyboard shortcuts

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