summaryrefslogtreecommitdiffstats
path: root/vendor/ansi_term/examples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/ansi_term/examples
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ansi_term/examples')
-rw-r--r--vendor/ansi_term/examples/256_colours.rs73
-rw-r--r--vendor/ansi_term/examples/basic_colours.rs18
-rw-r--r--vendor/ansi_term/examples/rgb_colours.rs23
3 files changed, 114 insertions, 0 deletions
diff --git a/vendor/ansi_term/examples/256_colours.rs b/vendor/ansi_term/examples/256_colours.rs
new file mode 100644
index 000000000..92fe2f1c1
--- /dev/null
+++ b/vendor/ansi_term/examples/256_colours.rs
@@ -0,0 +1,73 @@
+extern crate ansi_term;
+use ansi_term::Colour;
+
+// This example prints out the 256 colours.
+// They're arranged like this:
+//
+// - 0 to 8 are the eight standard colours.
+// - 9 to 15 are the eight bold colours.
+// - 16 to 231 are six blocks of six-by-six colour squares.
+// - 232 to 255 are shades of grey.
+
+fn main() {
+
+ // First two lines
+ for c in 0..8 {
+ glow(c, c != 0);
+ print!(" ");
+ }
+ print!("\n");
+ for c in 8..16 {
+ glow(c, c != 8);
+ print!(" ");
+ }
+ print!("\n\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!(" ");
+ }
+
+ print!("\n");
+ }
+ print!("\n");
+
+ // 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!(" ");
+ }
+
+ print!("\n");
+ }
+ print!("\n");
+
+ // The last greyscale lines
+ for c in 232..=243 {
+ glow(c, false);
+ print!(" ");
+ }
+ print!("\n");
+ for c in 244..=255 {
+ glow(c, true);
+ print!(" ");
+ }
+ print!("\n");
+}
+
+fn glow(c: u8, light_bg: bool) {
+ let base = if light_bg { Colour::Black } else { Colour::White };
+ let style = base.on(Colour::Fixed(c));
+ print!("{}", style.paint(&format!(" {:3} ", c)));
+}
diff --git a/vendor/ansi_term/examples/basic_colours.rs b/vendor/ansi_term/examples/basic_colours.rs
new file mode 100644
index 000000000..ba8815621
--- /dev/null
+++ b/vendor/ansi_term/examples/basic_colours.rs
@@ -0,0 +1,18 @@
+extern crate ansi_term;
+use ansi_term::{Style, Colour::*};
+
+// This example prints out the 16 basic colours.
+
+fn main() {
+ let normal = Style::default();
+
+ println!("{} {}", normal.paint("Normal"), normal.bold().paint("bold"));
+ println!("{} {}", Black.paint("Black"), Black.bold().paint("bold"));
+ println!("{} {}", Red.paint("Red"), Red.bold().paint("bold"));
+ println!("{} {}", Green.paint("Green"), Green.bold().paint("bold"));
+ println!("{} {}", Yellow.paint("Yellow"), Yellow.bold().paint("bold"));
+ println!("{} {}", Blue.paint("Blue"), Blue.bold().paint("bold"));
+ println!("{} {}", Purple.paint("Purple"), Purple.bold().paint("bold"));
+ println!("{} {}", Cyan.paint("Cyan"), Cyan.bold().paint("bold"));
+ println!("{} {}", White.paint("White"), White.bold().paint("bold"));
+}
diff --git a/vendor/ansi_term/examples/rgb_colours.rs b/vendor/ansi_term/examples/rgb_colours.rs
new file mode 100644
index 000000000..fd2cc7a85
--- /dev/null
+++ b/vendor/ansi_term/examples/rgb_colours.rs
@@ -0,0 +1,23 @@
+extern crate ansi_term;
+use ansi_term::{Style, Colour};
+
+// This example prints out a colour gradient in a grid by calculating each
+// character’s red, green, and blue components, and using 24-bit colour codes
+// to display them.
+
+const WIDTH: i32 = 80;
+const HEIGHT: i32 = 24;
+
+fn main() {
+ for row in 0 .. HEIGHT {
+ for col in 0 .. WIDTH {
+ let r = (row * 255 / HEIGHT) as u8;
+ let g = (col * 255 / WIDTH) as u8;
+ let b = 128;
+
+ print!("{}", Style::default().on(Colour::RGB(r, g, b)).paint(" "));
+ }
+
+ print!("\n");
+ }
+}