papergrid/lib.rs
1#![warn(
2 rust_2018_idioms,
3 rust_2018_compatibility,
4 rust_2021_compatibility,
5 missing_debug_implementations,
6 unreachable_pub,
7 missing_docs
8)]
9#![deny(unused_must_use)]
10
11//! Papergrid is a library for generating text-based tables.
12//!
13//! It has relatively low level API.
14//! If you're interested in a more friendly one take a look at [`tabled`](https://github.com/zhiburt/tabled).
15//!
16//! # Example
17//!
18//! ```
19//! use papergrid::{
20//! height::HeightEstimator,
21//! records::vec_records::VecRecords,
22//! width::{CfgWidthFunction, WidthEstimator},
23//! Borders, Estimate, Grid, GridConfig,
24//! };
25//!
26//! // Creating a borders structure of a grid.
27//! let borders = Borders {
28//! top: Some('-'),
29//! top_left: Some('+'),
30//! top_right: Some('+'),
31//! top_intersection: Some('+'),
32//! bottom: Some('-'),
33//! bottom_left: Some('+'),
34//! bottom_right: Some('+'),
35//! bottom_intersection: Some('+'),
36//! horizontal: Some('-'),
37//! horizontal_left: Some('+'),
38//! horizontal_right: Some('+'),
39//! vertical: Some('|'),
40//! vertical_left: Some('|'),
41//! vertical_right: Some('|'),
42//! intersection: Some('+'),
43//! };
44//!
45//! // Creating a grid config.
46//! let mut cfg = GridConfig::default();
47//! cfg.set_borders(borders);
48//!
49//! // Creating an actual data for grid.
50//! let records = vec![vec!["Hello", "World"], vec!["Hi", "World"]];
51//! let records = VecRecords::new(&records, (2, 2), CfgWidthFunction::from_cfg(&cfg));
52//!
53//! // Estimate width space for rendering.
54//! let mut width = WidthEstimator::default();
55//! width.estimate(&records, &cfg);
56//!
57//! // Estimate height space for rendering.
58//! let mut height = HeightEstimator::default();
59//! height.estimate(&records, &cfg);
60//!
61//! // Creating a grid.
62//! let grid = Grid::new(&records, &cfg, &width, &height).to_string();
63//!
64//! assert_eq!(
65//! grid,
66//! concat!(
67//! "+-----+-----+\n",
68//! "|Hello|World|\n",
69//! "+-----+-----+\n",
70//! "|Hi |World|\n",
71//! "+-----+-----+",
72//! ),
73//! );
74//! ```
75
76mod color;
77mod config;
78mod estimation;
79mod grid;
80
81pub mod records;
82pub mod util;
83
84pub use self::{
85 config::{
86 AlignmentHorizontal, AlignmentVertical, Border, Borders, Entity, EntityIterator,
87 Formatting, GridConfig, HorizontalLine, Indent, Margin, Offset, Padding, Position, Sides,
88 VerticalLine,
89 },
90 estimation::{height, width, Estimate},
91 grid::Grid,
92};
93
94#[cfg(feature = "color")]
95pub use crate::{
96 color::{AnsiColor, Color},
97 config::{MarginColor, PaddingColor},
98};