36 releases

0.12.0 Aug 5, 2024
0.11.0 Dec 20, 2023
0.10.0 Jul 24, 2023
0.7.1 Oct 18, 2022
0.1.0 Mar 23, 2020

#229 in Command-line interface

Download history 67221/week @ 2024-07-13 71925/week @ 2024-07-20 72040/week @ 2024-07-27 69847/week @ 2024-08-03 77162/week @ 2024-08-10 77969/week @ 2024-08-17 94313/week @ 2024-08-24 83189/week @ 2024-08-31 87619/week @ 2024-09-07 77582/week @ 2024-09-14 94404/week @ 2024-09-21 112778/week @ 2024-09-28 92906/week @ 2024-10-05 110834/week @ 2024-10-12 101892/week @ 2024-10-19 107244/week @ 2024-10-26

427,358 downloads per month
Used in 354 crates (via tabled)

MIT license

265KB
7K 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::{
    colors::NoColors,
    config::{
        spanned::SpannedConfig, AlignmentHorizontal, AlignmentVertical, Borders, Entity, Indent,
        Sides,
    },
    dimension::{spanned::SpannedGridDimension, Estimate},
    grid::peekable::PeekableGrid,
    records::vec_records::{CellInfo, VecRecords},
};

fn main() {
    let mut cfg = SpannedConfig::default();
    cfg.set_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('-'),
        left_intersection: Some('+'),
        right_intersection: Some('+'),
        vertical: Some('|'),
        left: Some('|'),
        right: Some('|'),
        intersection: Some('+'),
    });
    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(Entity::Global, AlignmentVertical::Center);
    cfg.set_padding(
        (0, 0).into(),
        Sides::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 data = data
        .iter()
        .map(|row| row.iter().map(CellInfo::new).collect())
        .collect();

    let records = VecRecords::new(data);

    let mut dims = SpannedGridDimension::default();
    dims.estimate(&records, &cfg);

    let grid = PeekableGrid::new(&records, &cfg, &dims, NoColors).to_string();

    println!("{grid}");
}

Running the example you must see.

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

Dependencies

~2MB
~28K SLoC