Skip to main content

truncate_middle

Function truncate_middle 

Source
pub fn truncate_middle(text: &str, max_len: usize) -> String
Expand description

Truncate text to at most max_len chars, keeping a head and a tail joined by a single so context from both ends is preserved.

Control characters are replaced with spaces before truncation so the result is safe to render in a terminal/TUI. When the text already fits it is returned unchanged (after sanitization).

This is the canonical middle-truncation helper, shared so the same logic is not re-implemented per crate.