• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zhiburt / tabled / 11980328468

22 Nov 2024 09:20PM UTC coverage: 74.203% (-0.4%) from 74.583%
11980328468

push

github

zhiburt
toml_to_table/ Bump to 0.5.0

12504 of 16851 relevant lines covered (74.2%)

2.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/testing_table/src/util.rs
1
/// Returns a string width.
2
pub fn get_line_width(text: &str) -> usize {
×
3
    #[cfg(not(feature = "ansi"))]
4
    {
5
        unicode_width::UnicodeWidthStr::width(text)
×
6
    }
7

8
    #[cfg(feature = "ansi")]
9
    {
10
        // we need to strip ansi because of terminal links
11
        // and they're can't be stripped by ansi_str.
12

13
        ansitok::parse_ansi(text)
14
            .filter(|e| e.kind() == ansitok::ElementKind::Text)
15
            .map(|e| &text[e.start()..e.end()])
16
            .map(unicode_width::UnicodeWidthStr::width)
17
            .sum()
18
    }
19
}
20

21
/// Returns a max string width of a line.
22
pub fn get_text_width(text: &str) -> usize {
×
23
    #[cfg(not(feature = "ansi"))]
24
    {
25
        text.lines()
×
26
            .map(unicode_width::UnicodeWidthStr::width)
27
            .max()
28
            .unwrap_or(0)
29
    }
30

31
    #[cfg(feature = "ansi")]
32
    {
33
        text.lines().map(get_line_width).max().unwrap_or(0)
34
    }
35
}
36

37
/// Returns a char width.
38
pub fn get_char_width(c: char) -> usize {
×
39
    unicode_width::UnicodeWidthChar::width(c).unwrap_or_default()
×
40
}
41

42
/// Returns a string width (accouting all characters).
43
pub fn get_string_width(text: &str) -> usize {
×
44
    unicode_width::UnicodeWidthStr::width(text)
×
45
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc