nestable
A small Rust library for rendering text tables in the terminal.
Supports:
- multi-line cells
- Unicode (including emoji)
- ANSI styling (colours, bold, etc.) on column, row or cell basis
- alignment on column, row or cell basis
- nested tables (via pre-rendering)
Demonstration
There is a demo to be found in examples/demo.rs. To build and run it, use:
cargo run --example demo

Command Line Utility
Despite being mostly developed as a rust library with minimal ddependencies, it
also provides a nestable command line tool which can render CSV inputs from
stdin and can be used as follows:
cat file.csv | nestable
This provides incredibly limited functionality at the moment will be fleshed out with a proper implementation of RFC-4180 at a later point.
Library Example
use *;
Example output:

Design
This crate uses a simple two-phase approach:
-
Input model Rows are defined as collections of strings.
-
Layout model Cells are split into lines, widths are computed, and a layout is derived before rendering.
Rendering is then performed from the computed layout.
ANSI handling
- ANSI escape sequences are preserved in output
- Display width is calculated while ignoring ANSI sequences
- Non-SGR escape sequences are not supported and may be ignored or warned about
Nested tables
Nested tables are supported by rendering them to strings:
Note: nested tables are rendered independently and are not resized based on the outer table.
Limitations
- No automatic text wrapping
- Layout is content-driven (columns expand to fit content)
- No column/row alignment options (yet)
- No true column spanning (only implicit “fill to end” behaviour)
- ANSI parsing is minimal (focused on common styling sequences)
Styling
Several predefined styles are available:
GLYPHS_ROUNDEDGLYPHS_SQUAREGLYPHS_NO_BORDERGLYPHS_NO_ROW_SEPARATORASCII_BORDERASCII_NO_BORDERASCII_NO_ROW_SEPARATOR
Optionally, the first row can be inverted.
Example:
use nestable::*;
let table = Table::new()
.add_rows([
["a", "b"],
["c", "d"],
])
.set_table_style(styles::GLYPHS_ROUNDED)
.set_inverted_header(false);
println!("{}", table);
License
MIT
Author
Charles Yates
Contributing / Feedback
Questions, suggestions, and bug reports are welcome via GitLab issues.