Expand description
Console table rendering with Unicode/CJK-aware alignment, truncation, and ANSI color support.
§Ambiguous-width characters
Characters like Φ (U+03A6) have Unicode East_Asian_Width=Ambiguous.
Terminals render them as 1 or 2 columns depending on locale and terminal
settings. unicode_width reports them as 1. To align with the terminal,
this crate counts them as 2 when it believes the output target is a CJK
context, and 1 otherwise.
Default behavior: ambiguous characters are counted as 2 columns
(AmbiguousWidth::Wide). This matches CJK terminals, which are the
primary target of this crate. If your terminal renders Φ as 1 column,
call [Table::cjk_context(false)] or Table::ambiguous_width to
override.
§Example
use console_table::{Align, Style, Table};
let rows = vec![
vec!["#".to_string(), "source".to_string(), "latency".to_string()],
vec!["1".to_string(), "rsproxy".to_string(), "57 ms".to_string()],
vec!["2".to_string(), "tuna".to_string(), "16 ms".to_string()],
];
let table = Table::new(rows)
.style(Style::Boxed)
.aligns(vec![Align::Right, Align::Left, Align::Auto]);
println!("{}", table.render());Structs§
- Table
- Table configuration.
Enums§
- Align
- Horizontal alignment of a cell.
- Ambiguous
Width - How to treat Unicode
East_Asian_Width=Ambiguouscharacters. - Color
- ANSI foreground color.
- Style
- Border style of the table.
Functions§
- display_
width - Terminal display width of
s, ignoring ANSI escape sequences. - is_
numeric_ like - Return
trueifslooks like a number, forAlign::Auto. - pad_
left_ with_ spaces - Pad
son the left with spaces up towidthdisplay columns. - pad_
right_ with_ spaces - Pad
son the right with spaces up towidthdisplay columns. - render_
table - Convenience function: render a table directly.
- strip_
ansi - Strip CSI-style ANSI escape sequences (e.g.
\x1b[...m) froms. - truncate_
visible - Truncate
sto at mostmax_widthdisplay columns. - truncate_
visible_ with - Truncate
sto at mostmax_widthdisplay columns, usingawfor ambiguous characters.