Documentation
¶
Index ¶
- func AssertBufferAreaEq(buf *Buffer, area layout.Rect, expected []string) error
- func AssertBufferEq(expected, actual *Buffer) error
- func AssertCellStyle(buf *Buffer, x, y uint16, fg, bg style.Color, mod style.Modifier) error
- func BufferToString(buf *Buffer) string
- func RuneWidth(r rune) int
- func StringWidth(s string) int
- func StringWidthTruncated(s string, maxBytes int) int
- type Buffer
- func (b *Buffer) CellAt(x, y uint16) *Cell
- func (b *Buffer) Clear()
- func (b *Buffer) Diff(previous *Buffer) []CellDiff
- func (b *Buffer) DiffInto(previous *Buffer, dst []CellDiff) []CellDiff
- func (b *Buffer) DiffIter(previous *Buffer) DiffIter
- func (b *Buffer) IndexOf(x, y uint16) int
- func (b *Buffer) Resize(area layout.Rect)
- func (b *Buffer) SetCell(x, y uint16, symbol string, sty style.Style)
- func (b *Buffer) SetLine(x, y uint16, s string, sty style.Style)
- func (b *Buffer) SetString(x, y uint16, s string, sty style.Style)
- func (b *Buffer) SetStringn(x, y uint16, s string, maxWidth uint16, sty style.Style) uint16
- type Cell
- type CellDiff
- type CellDiffOption
- type DiffIter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertBufferAreaEq ¶
AssertBufferAreaEq asserts that the given area of the buffer matches the expected content. The expected content is a slice of strings where each string represents a row. Only the symbol is checked, not the style.
func AssertBufferEq ¶
AssertBufferEq asserts that two buffers are equal, returning an error describing the first difference found, or nil if they are equal.
func AssertCellStyle ¶
AssertCellStyle asserts that the cell at (x,y) has the expected foreground, background, and modifier.
func BufferToString ¶
BufferToString returns a string representation of the buffer for debugging. Each row is on a separate line, showing only the symbols.
func RuneWidth ¶
RuneWidth returns the display width of a rune in terminal cells. Handles half-width katakana combining marks (U+FF9E, U+FF9F) as width 0 since they combine with the preceding character in some terminals.
Box Drawing (U+2500–U+257F), Block Elements (U+2580–U+259F), and Geometric Shapes (U+25A0–U+25FF) are forced to width 1 because go-runewidth treats them as ambiguous-width (width 2) under CJK locale, but all modern terminal emulators consistently render them as single-width.
func StringWidth ¶
StringWidth returns the display width of a string in terminal cells. Wide characters (CJK etc.) count as 2 cells. 逐 rune 用 RuneWidth 累加而非直通 runewidth.StringWidth: RuneWidth 对 Box Drawing/Block Elements 等强制宽度 1(CJK locale 下 runewidth 按环境变量启用 EastAsianWidth 会计 2),测量与渲染必须 共用同一宽度事实来源,否则对齐与光标计算在中文环境下漂移。
func StringWidthTruncated ¶
StringWidthTruncated returns the display width of s up to maxBytes bytes.
Types ¶
type Buffer ¶
Buffer represents a 2D grid of cells that maps to the terminal screen.
func (*Buffer) Diff ¶
Diff computes the differences between two buffers. 每次调用都会分配新的切片;高频渲染场景应优先使用 DiffInto 复用底层数组。
func (*Buffer) DiffInto ¶
DiffInto computes the differences between two buffers, appending to dst and returning the resulting slice. 传入 dst[:0] 可复用底层容量,避免每帧分配。 dst 为 nil 时等价于 Diff。 宽字符 follower cell(WideChar=true)跳过:leader 输出后终端自动覆盖 follower 区域,backend 同样会忽略它们,进入 diffs 只浪费拷贝。
func (*Buffer) DiffIter ¶
DiffIter returns a zero-allocation diff iterator. Usage:
it := b.DiffIter(previous)
for it.Next() {
x, y, cell := it.Cell()
// process diff
}
func (*Buffer) SetLine ¶
SetLine writes a string starting at (x, y), wrapping to next lines if needed. Handles wide characters correctly.
func (*Buffer) SetString ¶
SetString writes a string at the given position with the given style. Handles multi-byte UTF-8 and wide characters (e.g. CJK) correctly. Wide characters occupy 2 cells; the second cell is reset to hide overlap.
func (*Buffer) SetStringn ¶
SetStringn writes a string at the given position with the given style, limited to at most maxWidth display cells. If maxWidth is 0, no limit is applied. Returns the x position after the last written cell.
type Cell ¶
type Cell struct {
Symbol string
Fg style.Color
Bg style.Color
Modifier style.Modifier
WideChar bool // true if this cell is the second (hidden) half of a wide character
Skip bool // if true, skip this cell during diff rendering
Link string // OSC 8 hyperlink URL (empty = no link)
LinkID string // OSC 8 hyperlink ID (optional, for grouping)
}
Cell represents a single cell in the terminal buffer.
func (Cell) DiffOption ¶
func (c Cell) DiffOption() CellDiffOption
DiffOption returns the CellDiffOption for this cell.
func (*Cell) Reset ¶
func (c *Cell) Reset()
Reset resets the cell to default (space with reset style).
type CellDiff ¶
Diff computes the diff between this buffer and a previous buffer, returning only the cells that changed.
type CellDiffOption ¶
type CellDiffOption int
CellDiffOption controls how a cell is handled during diff computation.
const ( // CellDiffNone means the cell is included in diff normally. CellDiffNone CellDiffOption = iota // CellDiffSkip means the cell is always skipped during diff. CellDiffSkip // CellDiffAlwaysUpdate means the cell is always included in diff, even if unchanged. CellDiffAlwaysUpdate // CellDiffForcedWidth means the cell is included in diff to force a width update // (e.g. after a wide character boundary change). CellDiffForcedWidth )