Documentation
¶
Overview ¶
Package textwidth centralizes rune-safe terminal cell-width math for beam: every width measurement, truncation, pad, and wrap goes through here instead of ad hoc len() arithmetic.
Widths are terminal cells (East-Asian wide runes count 2). Because frame spans carry no escape codes, Width(line.Text()) is a line's rendered width.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Truncate ¶
Truncate cuts s to at most w cells, appending tail (whose width counts toward w) when anything was removed. Never splits a rune.
func Wrap ¶
Wrap wraps s to at most w cells per line, breaking after spaces where possible and hard-breaking only words wider than w. Existing newlines are respected, and every rune of s appears in the output exactly once, in order — Wrap only ever inserts breaks, leaving a space at the end of the earlier line, a property the composer's caret math counts on.
A non-positive w still splits on newlines and does no other wrapping: a returned element is a terminal row headed straight for a frame.Span, and a span holding a newline breaks frame.Line's one-row contract, so a degenerate width must never return the input whole.
go-runewidth's own Wrap is not used: its word-boundary detection breaks after any non-ASCII rune, hard-splitting words mid-run.
Types ¶
This section is empty.