ctl-text
Styled text for terminals: spans that are safe to print, widths counted in terminal cells, and lines wrapped or cut to fit.
ctl-text lays text out as plain data before anything is written to a terminal.
A Span is text in one style, and a Line is a list of spans.
A Text is a list of lines that wraps to a width.
None of them holds an escape sequence. So text from outside the program, such as a commit subject, cannot move the cursor or reorder a line. Whatever writes the lines to a terminal adds the styling after layout.
What it provides
Span,Line, andText, andoverlayfor combining two styles.text_width,cluster_width, andprefix_len, which count cells per extended grapheme cluster.Overflow, the policy for a line wider than its width. It keeps words whole, folds inside a word, or ends with an ellipsis.Renderable,Context, andMeasurement, the protocol a widget follows. A widget reports its size, then draws itself at a width.unsafe_chars::is_unsafeandunsafe_chars::strip_unsafe, the rule for which characters never reach a terminal, and the function that applies it.
Example
use AnsiColor;
use ;
let green = new.fg_color;
let text = styled.overflow;
let lines = text.render;
let plain: = lines.iter.map.collect;
assert_eq!;
Features
ctl-text has no optional features.
Documentation
The API reference is on docs.rs.
License
MIT.