#table #plain-text #formatted #grid #cells #column

macro text-grid-macros

A library to create formatted plain-text tables

1 unstable release

0.4.1 Mar 5, 2024

#19 in #cells

Download history 53/week @ 2024-04-01 50/week @ 2024-04-08 18/week @ 2024-04-15 37/week @ 2024-04-22 25/week @ 2024-04-29 21/week @ 2024-05-06 52/week @ 2024-05-13 142/week @ 2024-05-20 132/week @ 2024-05-27 196/week @ 2024-06-03 151/week @ 2024-06-10 130/week @ 2024-06-17 59/week @ 2024-06-24 31/week @ 2024-07-01 47/week @ 2024-07-08 47/week @ 2024-07-15

197 downloads per month
Used in 5 crates (via text-grid)

MIT/Apache

12KB
272 lines

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

~320–780KB
~18K SLoC