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
.
```rust 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.setborders(Borders { top: Some('-'), topleft: Some('+'), topright: Some('+'), topintersection: Some('+'), bottom: Some('-'), bottomleft: Some('+'), bottomright: Some('+'), bottomintersection: Some('+'), horizontal: Some('-'), leftintersection: Some('+'), rightintersection: Some('+'), vertical: Some('|'), left: Some('|'), right: Some('|'), intersection: Some('+'), }); cfg.setcolumnspan((1, 1), 3); cfg.setrowspan((0, 0), 2); cfg.setalignmenthorizontal((1, 0).into(), AlignmentHorizontal::Center); cfg.setalignmentvertical(Entity::Global, AlignmentVertical::Center); cfg.setpadding( (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.
text
+-----------------+------------+----------------+-+
| |is a library|for print tables|!|
+ Papergrid +------------+----------------+-+
| |Just like this |
+-----------------+------------+----------------+-+