summaryrefslogtreecommitdiffstats
path: root/vendor/nu-ansi-term/examples
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
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')
-rw-r--r--vendor/nu-ansi-term/examples/256_colors.rs72
-rw-r--r--vendor/nu-ansi-term/examples/basic_colors.rs18
-rw-r--r--vendor/nu-ansi-term/examples/gradient_colors.rs37
-rw-r--r--vendor/nu-ansi-term/examples/rgb_colors.rs23
4 files changed, 150 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)));
+}
diff --git a/vendor/nu-ansi-term/examples/basic_colors.rs b/vendor/nu-ansi-term/examples/basic_colors.rs
new file mode 100644
index 000000000..3c2b6817f
--- /dev/null
+++ b/vendor/nu-ansi-term/examples/basic_colors.rs
@@ -0,0 +1,18 @@
+extern crate nu_ansi_term;
+use nu_ansi_term::{Color::*, Style};
+
+// This example prints out the 16 basic colors.
+
+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/nu-ansi-term/examples/gradient_colors.rs b/vendor/nu-ansi-term/examples/gradient_colors.rs
new file mode 100644
index 000000000..1c9583865
--- /dev/null
+++ b/vendor/nu-ansi-term/examples/gradient_colors.rs
@@ -0,0 +1,37 @@
+use nu_ansi_term::{build_all_gradient_text, Color, Gradient, Rgb, TargetGround};
+
+fn main() {
+ let text = "lorem ipsum quia dolor sit amet, consectetur, adipisci velit";
+
+ // a gradient from hex colors
+ let start = Rgb::from_hex(0x40c9ff);
+ let end = Rgb::from_hex(0xe81cff);
+ let grad0 = Gradient::new(start, end);
+
+ // a gradient from color::rgb()
+ let start = Color::Rgb(64, 201, 255);
+ let end = Color::Rgb(232, 28, 255);
+ let gradient = Gradient::from_color_rgb(start, end);
+
+ // a slightly different gradient
+ let start2 = Color::Rgb(128, 64, 255);
+ let end2 = Color::Rgb(0, 28, 255);
+ let gradient2 = Gradient::from_color_rgb(start2, end2);
+
+ // reverse the gradient
+ let gradient3 = gradient.reverse();
+
+ let build_fg = gradient.build(text, TargetGround::Foreground);
+ println!("{}", build_fg);
+ let build_bg = gradient.build(text, TargetGround::Background);
+ println!("{}", build_bg);
+ let bgt = build_all_gradient_text(text, gradient, gradient2);
+ println!("{}", bgt);
+ let bgt2 = build_all_gradient_text(text, gradient, gradient3);
+ println!("{}", bgt2);
+
+ println!(
+ "{}",
+ grad0.build("nushell is awesome", TargetGround::Foreground)
+ );
+}
diff --git a/vendor/nu-ansi-term/examples/rgb_colors.rs b/vendor/nu-ansi-term/examples/rgb_colors.rs
new file mode 100644
index 000000000..4657d401f
--- /dev/null
+++ b/vendor/nu-ansi-term/examples/rgb_colors.rs
@@ -0,0 +1,23 @@
+extern crate nu_ansi_term;
+use nu_ansi_term::{Color, Style};
+
+// This example prints out a color gradient in a grid by calculating each
+// character’s red, green, and blue components, and using 24-bit color 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(Color::Rgb(r, g, b)).paint(" "));
+ }
+
+ println!();
+ }
+}