Documentation
¶
Overview ¶
Package render is the cell-diffing renderer behind the root package's default renderer. Cells.Frame turns a view, either lines of styled text or a GridSource drawn directly, into a grid of cells, compares it with the previous frame and emits only the escape sequences and text needed to repaint the cells that changed. It performs no terminal I/O itself: callers write the bytes it returns.
Index ¶
- func AppendSGR(dst []byte, from, to Style) []byte
- func BidiLine(line string, m ansi.Measurer) string
- func KittyDelete(id uint32) string
- type Cells
- func (c *Cells) Frame(in Frame) (string, Stats, bool)
- func (c *Cells) GridRows() int
- func (c *Cells) Invalidate()
- func (c *Cells) PatchedRows() []bool
- func (c *Cells) Reason() string
- func (c *Cells) SetNoCache(v bool)
- func (c *Cells) SetNoPatch(v bool)
- func (c *Cells) Valid() bool
- func (c *Cells) Width() int
- type Frame
- type Glyph
- type GridSource
- type RowFallback
- type Stats
- type Style
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendSGR ¶
AppendSGR appends the SGR bytes that take the terminal from pen from to pen to (nothing when the SGR state is equal). Links are not part of SGR and are ignored.
func BidiLine ¶
BidiLine returns line with its characters in visual order per the Unicode Bidirectional Algorithm (UAX #9), taking the paragraph direction from the first strong character, for terminals that draw text in logical order. Each character keeps its own style and hyperlink, and a character at an odd level that has an exact mirror image (a bracket) is replaced by it.
A line with no right-to-left or formatting character, and a line the cell parser declines (graphics, malformed escapes), is returned unchanged, byte for byte. The reordering is for display only; the caller keeps the logical text.
func KittyDelete ¶
KittyDelete returns the kitty graphics command that deletes every placement of image id and frees its data, with the terminal's reply suppressed.
Types ¶
type Cells ¶
type Cells struct {
// contains filtered or unexported fields
}
func (*Cells) Frame ¶
Frame draws in.Lines (padded to in.Max rows) as the change from the previous frame. ok is false when this frame must be drawn by the line renderer instead; nothing has been recorded then, and Reason says why. With in.LazyFit the lines are not yet fitted to the terminal: this fits each one it cannot show to be unchanged in width with in.FitLine, in place.
func (*Cells) Invalidate ¶
func (c *Cells) Invalidate()
Invalidate drops the previous frame, so the next Frame redraws every row.
func (*Cells) PatchedRows ¶
PatchedRows reports, per row of the last frame, whether it was patched rather than parsed. For tests.
func (*Cells) Reason ¶
Reason is why the last Frame fell back to the line renderer, a slug such as "control_character"; "" when it did not.
func (*Cells) SetNoCache ¶
SetNoCache makes every row be parsed every frame. For tests and benchmarks.
func (*Cells) SetNoPatch ¶
SetNoPatch stops rows being patched from the previous frame. For tests.
type Frame ¶
type Frame struct {
Lines []string // the view, one string per row
Max int // rows to draw: max(len(Lines), rows of the previous frame)
LazyFit bool // Lines are not yet fitted to Width; see Cells.Frame
Width, Height int // terminal size; Height <= 0 when unknown
PrevRows int // rows the caller recorded for the previous frame; 0 for none
RegionTop func() string // moves the cursor to the top of the live region
FitLine func(string) string
Measurer ansi.Measurer // how the terminal draws grapheme clusters; zero follows the process default
// Grid, when non-nil, is drawn instead of Lines: GridRows rows of Width
// columns, with no string parsed. Rows past GridRows (up to Max) are blank.
Grid GridSource
GridRows int
}
Frame is one frame for Cells.Frame.
type Glyph ¶
Glyph is one parsed cell: a head cell carries its cluster text and width (1 or 2); the continuation cell of a wide cluster has Width 0 and no Text.
func ParseGlyphs ¶
ParseGlyphs parses one view line (no newline) into cells with the same rules the cell renderer applies, measuring widths with m. ok is false, with the renderer's fallback slug in reason, when the line uses something the grid cannot represent. Trailing blank cells are kept.
type GridSource ¶
type GridSource interface {
// Cell returns the cell at column x of row y: its cluster text ("" for the
// continuation of a wide cluster), its width (0, 1 or 2) and its style.
Cell(x, y int) (text string, width uint8, st Style)
}
GridSource is a grid of cells that Cells.Frame draws without parsing a string: the entry point for models that draw cells directly.
type RowFallback ¶
type RowFallback struct {
Row int // 0-based row of the frame
Reason string // slug, for example "control_character"
}
RowFallback names a row drawn with the line strategy and why.
type Stats ¶
type Stats struct {
Rows, Changed int
Full bool
// Fallbacks lists the rows drawn with the line strategy this frame (rows
// the grid could not represent) and why; nil when there were none. The
// slice is reused by the next Frame.
Fallbacks []RowFallback
}
Stats describes a drawn frame, for the frame log.