1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#![warn(
    rust_2018_idioms,
    rust_2018_compatibility,
    rust_2021_compatibility,
    missing_debug_implementations,
    unreachable_pub,
    missing_docs
)]
#![deny(unused_must_use)]

//! 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`](https://github.com/zhiburt/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",
//!         "+-----+-----+",
//!     ),
//! );
//! ```

mod color;
mod config;
mod estimation;
mod grid;

pub mod records;
pub mod util;

pub use self::{
    config::{
        AlignmentHorizontal, AlignmentVertical, Border, Borders, Entity, EntityIterator,
        Formatting, GridConfig, HorizontalLine, Indent, Margin, Offset, Padding, Position, Sides,
        VerticalLine,
    },
    estimation::{height, width, Estimate},
    grid::Grid,
};

#[cfg(feature = "color")]
pub use crate::{
    color::{AnsiColor, Color},
    config::{MarginColor, PaddingColor},
};