28 releases (6 breaking)

0.7.1 Oct 18, 2022
0.6.1 Oct 18, 2022
0.5.1 Jul 22, 2022
0.2.1 Feb 10, 2022
0.1.0 Mar 23, 2020

#62 in Command-line interface

Download history 13129/week @ 2022-12-06 12874/week @ 2022-12-13 10688/week @ 2022-12-20 8816/week @ 2022-12-27 13988/week @ 2023-01-03 16854/week @ 2023-01-10 16286/week @ 2023-01-17 16406/week @ 2023-01-24 19319/week @ 2023-01-31 23244/week @ 2023-02-07 25093/week @ 2023-02-14 23082/week @ 2023-02-21 21385/week @ 2023-02-28 20975/week @ 2023-03-07 20053/week @ 2023-03-14 22762/week @ 2023-03-21

89,666 downloads per month
Used in 118 crates (via tabled)

MIT license

155KB
4K SLoC

papergrid

This is library for pretty tables.

It has relatively low level API. If you're interested in a more friendly one take a look at tabled.

Usage

use papergrid::{
    height::HeightEstimator,
    records::vec_records::VecRecords,
    width::{CfgWidthFunction, WidthEstimator},
    AlignmentHorizontal, Borders,
    Entity::Global,
    Estimate, Grid, GridConfig, Indent, Padding,
};

const STYLE: Borders = Borders {
    top: Some('-'),
    top_left: Some('+'),
    top_right: Some('+'),
    top_intersection: Some('+'),
    bottom: Some('-'),
    bottom_left: Some('+'),
    bottom_right: Some('+'),
    bottom_intersection: Some('+'),
    horizontal: Some('-'),
    horizontal_left: Some('+'),
    horizontal_right: Some('+'),
    vertical: Some('|'),
    vertical_left: Some('|'),
    vertical_right: Some('|'),
    intersection: Some('+'),
};

fn main() {
    let mut cfg = GridConfig::default();
    cfg.set_borders(STYLE);
    cfg.set_column_span((1, 1), 3);
    cfg.set_row_span((0, 0), 2);
    cfg.set_alignment_horizontal((1, 0).into(), AlignmentHorizontal::Center);
    cfg.set_alignment_vertical(Global, papergrid::AlignmentVertical::Center);
    cfg.set_padding(
        (0, 0).into(),
        Padding::new(
            Indent::spaced(4),
            Indent::spaced(4),
            Indent::spaced(1),
            Indent::spaced(1),
        ),
    );

    let data = [
        ["Papergrid", "is a library", "for print tables", "!"],
        ["", "Just like this", "", ""],
    ];

    let records = VecRecords::new(&data, (2, 4), CfgWidthFunction::from_cfg(&cfg));

    let mut width = WidthEstimator::default();
    width.estimate(&records, &cfg);

    let mut height = HeightEstimator::default();
    height.estimate(&records, &cfg);

    let grid = Grid::new(&records, &cfg, &width, &height);

    println!("{}", grid);
}

Running the example you must see.

+-----------------+------------+----------------+-+
|                 |is a library|for print tables|!|
+    Papergrid    +------------+----------------+-+
|                 |Just like this                 |
+-----------------+------------+----------------+-+

Dependencies

~87–305KB