Expand description
Papergrid is a library for generating text-based tables.
It has relatively low level API.
If you’re interested in a more friendly one take a look at tabled
.
§Example
use papergrid::{
records::IterRecords,
dimension::{Estimate},
config::Borders,
colors::NoColors,
grid::iterable::IterGrid,
config::spanned::SpannedConfig,
dimension::iterable::IterGridDimension,
};
// Creating a borders structure of a grid.
let 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('-'),
vertical: Some('|'),
left: Some('|'),
right: Some('|'),
intersection: Some('+'),
left_intersection: Some('+'),
right_intersection: Some('+'),
};
// Creating a grid config.
let mut cfg = SpannedConfig::default();
cfg.set_borders(borders);
// Creating an actual data for grid.
let records = vec![vec!["Hello", "World"], vec!["Hi", "World"]];
let records = IterRecords::new(records, 2, None);
// Estimate grid dimension.
let mut dims = IterGridDimension::default();
dims.estimate(&records, &cfg);
// Creating a grid.
let grid = IterGrid::new(&records, &cfg, &dims, NoColors);
assert_eq!(
grid.to_string(),
concat!(
"+-----+-----+\n",
"|Hello|World|\n",
"+-----+-----+\n",
"|Hi |World|\n",
"+-----+-----+",
),
);
Modules§
- ansi
- A module which contains
ANSIFmt
trait and its implementationANSIStr
- colors
- A module which contains Colors trait and its blanket implementations.
- config
- A module which contains a general settings which might be used in other grid implementations.
- dimension
- The module contains an
Dimension
trait and its implementations. - grid
- Module contains a list of backends for pretty print tables.
- records
- The module contains a
Records
abstraction of a grid trait and its implementers. - util
- A module contains utility functions which grid relay on.