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
|
# papergrid
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`](https://github.com/zhiburt/tabled).
## Usage
```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.set_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('-'),
left_intersection: Some('+'),
right_intersection: Some('+'),
vertical: Some('|'),
left: Some('|'),
right: Some('|'),
intersection: Some('+'),
});
cfg.set_column_span((1, 1), 3);
cfg.set_row_span((0, 0), 2);
cfg.set_alignment_horizontal((1, 0).into(), AlignmentHorizontal::Center);
cfg.set_alignment_vertical(Entity::Global, AlignmentVertical::Center);
cfg.set_padding(
(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 |
+-----------------+------------+----------------+-+
```
|