Expand description
Width-aware truncation and cutting for ANSI-decorated strings.
§Category
This module shortens strings by terminal display columns while preserving escape sequences such as SGR resets and OSC hyperlinks. Escape bytes do not count toward width.
§Width conventions
Width is computed by crate::ansi::text::tokenize using WidthMode.
Visible text is truncated only on token boundaries; escape sequences before,
inside, or after the retained text are copied so terminal state remains
attached to the result.
§Mode interaction
Truncation does not emulate terminal modes. Mode-dependent sequence semantics are preserved as bytes but not interpreted.
Functions§
- cut
- Remove
leftdisplay columns from the start andrightdisplay columns from the end ofs. - cut_
mode - Width-mode variant of
cut. - truncate
- Truncate
sto at mostlengthdisplay columns, appendingtailif truncation occurs. - truncate_
left - Truncate
sfrom the left until at mostlengthdisplay columns remain. - truncate_
left_ mode - Width-mode variant of
truncate_left. - truncate_
mode - Width-mode variant of
truncate.