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::{
    height::HeightEstimator,
    records::vec_records::VecRecords,
    width::{CfgWidthFunction, WidthEstimator},
    Borders, Estimate, Grid, GridConfig,
};

// 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('-'),
    horizontal_left: Some('+'),
    horizontal_right: Some('+'),
    vertical: Some('|'),
    vertical_left: Some('|'),
    vertical_right: Some('|'),
    intersection: Some('+'),
};

// Creating a grid config.
let mut cfg = GridConfig::default();
cfg.set_borders(borders);

// Creating an actual data for grid.
let records = vec![vec!["Hello", "World"], vec!["Hi", "World"]];
let records = VecRecords::new(&records, (2, 2), CfgWidthFunction::from_cfg(&cfg));

// Estimate width space for rendering.
let mut width = WidthEstimator::default();
width.estimate(&records, &cfg);

// Estimate height space for rendering.
let mut height = HeightEstimator::default();
height.estimate(&records, &cfg);

// Creating a grid.
let grid = Grid::new(&records, &cfg, &width, &height).to_string();

assert_eq!(
    grid,
    concat!(
        "+-----+-----+\n",
        "|Hello|World|\n",
        "+-----+-----+\n",
        "|Hi   |World|\n",
        "+-----+-----+",
    ),
);

Modules

The module contains a HeightEstimator for Grid height estimation.
The module contains a Records abstraction of a Grid trait and its implementators.
This module contains a different functions which are used by the Grid.
The module contains a WidthEstimator for Grid width estimation.

Structs

Border is a representation of a cells’s borders (left, right, top, bottom, and the corners)
Borders represents a Table frame with horizontal and vertical split lines.
An iterator over cells.
Formatting represent a logic of formatting of a cell.
Grid provides a set of methods for building a text-based table.
This structure represents a settings of a grid.
A structre for a custom horizontal line.
Indent represent a filled space.
A structure which represents 4 box sides.
A structre for a vertical line.

Enums

AlignmentHorizontal represents an horizontal alignment of a cell content.
AlignmentVertical represents an vertical alignment of a cell content.
Entity a structure which represent a set of cells.
The structure represents an offset in a text.

Traits

An Evaluator of an metric of a Grid

Type Definitions

Margin represent a 4 indents of table as a whole.
Padding represent a 4 indents of cell.
Position is a (row, col) position on a Grid.