Skip to main content

shorten

Function shorten 

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

text cut to fit in width terminal columns, ending in … when cut: a wide character, such as most CJK ones, takes two columns.

use rig_tools::shorten;

assert_eq!(shorten("a short label", 20), "a short label");
assert_eq!(shorten("a longer label", 9), "a longer…");
assert_eq!(shorten("日本語のラベル", 7), "日本語…");