summaryrefslogtreecommitdiffstats
path: root/vendor/tabled/examples/chess.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/tabled/examples/chess.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/tabled/examples/chess.rs')
-rw-r--r--vendor/tabled/examples/chess.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/tabled/examples/chess.rs b/vendor/tabled/examples/chess.rs
new file mode 100644
index 000000000..db83218c8
--- /dev/null
+++ b/vendor/tabled/examples/chess.rs
@@ -0,0 +1,37 @@
+//! This example demonstrates using the [`Color`] [setting](tabled::settings) to
+//! stylize text, backgrounds, and borders.
+//!
+//! * 🚩 This example requires the `color` feature.
+//!
+//! * Note how [`Format::content()`] is used to break out [`CellOption`]
+//! specifications. This is helpful for organizing extensive [`Table`] configurations.
+
+use std::iter::FromIterator;
+
+use tabled::{
+ builder::Builder,
+ settings::{style::Style, themes::Colorization, Color},
+};
+
+fn main() {
+ let board = [
+ ["♜", "♞", "♝", "♛", "♚", "♝", "♞", "♜"],
+ ["♟", "♟", "♟", "♟", "♟", "♟", "♟", "♟"],
+ [" ", " ", " ", " ", " ", " ", " ", " "],
+ [" ", " ", " ", " ", " ", " ", " ", " "],
+ [" ", " ", " ", " ", " ", " ", " ", " "],
+ [" ", " ", " ", " ", " ", " ", " ", " "],
+ ["♙", "♙", "♙", "♙", "♙", "♙", "♙", "♙"],
+ ["♖", "♘", "♗", "♕", "♔", "♗", "♘", "♖"],
+ ];
+
+ let color_white = Color::BG_WHITE | Color::FG_BLACK;
+ let color_black = Color::FG_WHITE | Color::BG_BLACK;
+
+ let mut table = Builder::from_iter(board).build();
+ table
+ .with(Style::empty())
+ .with(Colorization::chess(color_white, color_black));
+
+ println!("{table}");
+}