Skip to main content

Module truncate

Module truncate 

Source
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 left display columns from the start and right display columns from the end of s.
cut_mode
Width-mode variant of cut.
truncate
Truncate s to at most length display columns, appending tail if truncation occurs.
truncate_left
Truncate s from the left until at most length display columns remain.
truncate_left_mode
Width-mode variant of truncate_left.
truncate_mode
Width-mode variant of truncate.