pub fn get_line_width(text: &str) -> usize {
#[cfg(not(feature = "ansi"))]
{
unicode_width::UnicodeWidthStr::width(text)
}
#[cfg(feature = "ansi")]
{
ansitok::parse_ansi(text)
.filter(|e| e.kind() == ansitok::ElementKind::Text)
.map(|e| &text[e.start()..e.end()])
.map(unicode_width::UnicodeWidthStr::width)
.sum()
}
}
pub fn get_text_width(text: &str) -> usize {
#[cfg(not(feature = "ansi"))]
{
text.lines()
.map(unicode_width::UnicodeWidthStr::width)
.max()
.unwrap_or(0)
}
#[cfg(feature = "ansi")]
{
text.lines().map(get_line_width).max().unwrap_or(0)
}
}
pub fn get_char_width(c: char) -> usize {
unicode_width::UnicodeWidthChar::width(c).unwrap_or_default()
}
pub fn get_string_width(text: &str) -> usize {
unicode_width::UnicodeWidthStr::width(text)
}