[][src]Function textwrap::core::display_width

pub fn display_width(text: &str) -> usize

Compute the display width of text while skipping over ANSI escape sequences.

Examples

use textwrap::core::display_width;
assert_eq!(display_width("Café Plain"), 10);
assert_eq!(display_width("\u{1b}[31mCafé Rouge\u{1b}[0m"), 10);

Note: When the unicode-width Cargo feature is enabled, this function will correctly deal with combining characters in their decomposed form (see Unicode equivalence).

An example of a decomposed character can be “é”, which can be decomposed into: “e” followed by an acute accent: “◌́”. Without the unicode-width Cargo feature, every char has a width of 1, including the combining accent:

use textwrap::core::display_width;
assert_eq!(display_width("Cafe Plain"), 10);
#[cfg(feature = "unicode-width")]
assert_eq!(display_width("Cafe\u{301} Plain"), 10);
#[cfg(not(feature = "unicode-width"))]
assert_eq!(display_width("Cafe\u{301} Plain"), 11);