#table #grid #pretty-table #pretty #text

text-grid

A library to create formatted plain-text tables

6 releases (3 breaking)

0.4.1 Mar 5, 2024
0.4.0 Nov 12, 2023
0.3.0 Jun 10, 2023
0.2.0 Feb 26, 2019
0.1.1 Dec 17, 2018

#237 in Command-line interface

Download history 39/week @ 2023-12-22 23/week @ 2023-12-29 19/week @ 2024-01-05 14/week @ 2024-01-12 11/week @ 2024-01-19 13/week @ 2024-01-26 14/week @ 2024-02-02 15/week @ 2024-02-09 23/week @ 2024-02-16 41/week @ 2024-02-23 185/week @ 2024-03-01 59/week @ 2024-03-08 42/week @ 2024-03-15 30/week @ 2024-03-22 43/week @ 2024-03-29 77/week @ 2024-04-05

198 downloads per month
Used in lgbm

MIT/Apache

64KB
1.5K SLoC

text-grid-rs

Crates.io Docs.rs CI

A library to create formatted plain-text tables.

Example

use text_grid::*;
struct RowData {
    a: String,
    b: u32,
    c: u32,
    d: f64,
}
impl Cells for RowData {
    fn fmt(f: &mut CellsFormatter<Self>) {
        f.column("a", |s| &s.a);
        f.column("b", |s| s.b);
        f.column("c", |s| cell(s.c).left());
        f.column_with("d", |f| {
            f.column("x", |s| s.d);
            f.column("y", |s| cells_f!("{:.2e}", s.d));
        });
    }
}

let rows = [
    RowData { a: "ABC".to_string(), b: 300, c: 1,   d: 100.1 },
    RowData { a: "XY".to_string(),  b: 2,   c: 200, d: 1.234 },
];
let g = to_grid(rows);
assert_eq!(format!("\n{g}"), OUTPUT);

const OUTPUT: &str = r#"
  a  |  b  |  c  |         d          |
-----|-----|-----|--------------------|
     |     |     |    x    |    y     |
-----|-----|-----|---------|----------|
 ABC | 300 | 1   | 100.1   | 1.00 e 2 |
 XY  |   2 | 200 |   1.234 | 1.23 e 0 |
"#;

License

This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.7–2.5MB
~38K SLoC