Skip to main content

truncate_with

Function truncate_with 

Source
pub fn truncate_with(value: &str, columns: usize, ellipsis: &str) -> String
Expand description

truncate, with the mark that says something was removed given explicitly. A terminal that cannot render … gets ..., and the width arithmetic follows the mark it was actually given rather than assuming one column.

use majordomus_cli::environment::text::{truncate_with, width};
assert_eq!(truncate_with("majordomus", 6, "..."), "maj...");
assert_eq!(width(&truncate_with("majordomus", 6, "...")), 6);
assert_eq!(truncate_with("majordomus", 2, "..."), "ma", "no room for the mark");