summaryrefslogtreecommitdiffstats
path: root/vendor/papergrid/examples/common_grid.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/papergrid/examples/common_grid.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/papergrid/examples/common_grid.rs')
-rw-r--r--vendor/papergrid/examples/common_grid.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/papergrid/examples/common_grid.rs b/vendor/papergrid/examples/common_grid.rs
new file mode 100644
index 000000000..a0fc8d4c7
--- /dev/null
+++ b/vendor/papergrid/examples/common_grid.rs
@@ -0,0 +1,67 @@
+//! This example demonstrates the flexibility of [`papergrid`] with manual configurations
+//! of [`Borders`], [`CompactConfig`], and column counts with [`IterRecords`].
+//!
+//! * For an alternative to [`CompactGrid`] and [`CompactGridDimension`] with
+//! flexible row height, variable intra-column spans, and multiline cell support
+//! see [`Grid`] and [`SpannedGridDimension`].
+
+use papergrid::{
+ config::compact::CompactConfig,
+ config::{AlignmentHorizontal, Borders, Indent, Sides},
+ dimension::compact::CompactGridDimension,
+ dimension::Estimate,
+ grid::compact::CompactGrid,
+ records::IterRecords,
+};
+
+fn main() {
+ let cfg = generate_table_config();
+
+ let data = [
+ ["Papergrid", "is a library", "for printing tables", "!"],
+ [
+ "Just like this",
+ "NOTICE",
+ "that multiline is not supported",
+ "H\ne\nl\nl\no",
+ ],
+ ];
+ let records = IterRecords::new(data, 4, None);
+
+ let mut dim = CompactGridDimension::default();
+ dim.estimate(records, &cfg);
+
+ let grid = CompactGrid::new(records, &dim, &cfg);
+
+ println!("{grid}");
+}
+
+fn generate_table_config() -> CompactConfig {
+ const STYLE: Borders<char> = 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('+'),
+ };
+
+ CompactConfig::default()
+ .set_borders(STYLE)
+ .set_alignment_horizontal(AlignmentHorizontal::Center)
+ .set_padding(Sides::new(
+ Indent::spaced(1),
+ Indent::spaced(1),
+ Indent::spaced(0),
+ Indent::spaced(0),
+ ))
+}