summaryrefslogtreecommitdiffstats
path: root/vendor/nu-ansi-term/examples/256_colors.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
commit2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch)
treed325add32978dbdc1db975a438b3a77d571b1ab8 /vendor/nu-ansi-term/examples/256_colors.rs
parentReleasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff)
downloadrustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz
rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/nu-ansi-term/examples/256_colors.rs')
-rw-r--r--vendor/nu-ansi-term/examples/256_colors.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/nu-ansi-term/examples/256_colors.rs b/vendor/nu-ansi-term/examples/256_colors.rs
new file mode 100644
index 000000000..4766dcdb6
--- /dev/null
+++ b/vendor/nu-ansi-term/examples/256_colors.rs
@@ -0,0 +1,72 @@
+extern crate nu_ansi_term;
+use nu_ansi_term::Color;
+
+// This example prints out the 256 colors.
+// They're arranged like this:
+//
+// - 0 to 8 are the eight standard colors.
+// - 9 to 15 are the eight bold colors.
+// - 16 to 231 are six blocks of six-by-six color squares.
+// - 232 to 255 are shades of grey.
+
+fn main() {
+ // First two lines
+ for c in 0..8 {
+ glow(c, c != 0);
+ print!(" ");
+ }
+ println!();
+ for c in 8..16 {
+ glow(c, c != 8);
+ print!(" ");
+ }
+ println!("\n");
+
+ // Six lines of the first three squares
+ for row in 0..6 {
+ for square in 0..3 {
+ for column in 0..6 {
+ glow(16 + square * 36 + row * 6 + column, row >= 3);
+ print!(" ");
+ }
+
+ print!(" ");
+ }
+
+ println!();
+ }
+ println!();
+
+ // Six more lines of the other three squares
+ for row in 0..6 {
+ for square in 0..3 {
+ for column in 0..6 {
+ glow(124 + square * 36 + row * 6 + column, row >= 3);
+ print!(" ");
+ }
+
+ print!(" ");
+ }
+
+ println!();
+ }
+ println!();
+
+ // The last greyscale lines
+ for c in 232..=243 {
+ glow(c, false);
+ print!(" ");
+ }
+ println!();
+ for c in 244..=255 {
+ glow(c, true);
+ print!(" ");
+ }
+ println!();
+}
+
+fn glow(c: u8, light_bg: bool) {
+ let base = if light_bg { Color::Black } else { Color::White };
+ let style = base.on(Color::Fixed(c));
+ print!("{}", style.paint(&format!(" {:3} ", c)));
+}