summaryrefslogtreecommitdiffstats
path: root/vendor/nu-ansi-term/examples
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/nu-ansi-term/examples/256_colors.rs (renamed from vendor/ansi_term/examples/256_colours.rs)33
-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, 94 insertions, 17 deletions
diff --git a/vendor/ansi_term/examples/256_colours.rs b/vendor/nu-ansi-term/examples/256_colors.rs
index 92fe2f1c1..4766dcdb6 100644
--- a/vendor/ansi_term/examples/256_colours.rs
+++ b/vendor/nu-ansi-term/examples/256_colors.rs
@@ -1,27 +1,26 @@
-extern crate ansi_term;
-use ansi_term::Colour;
+extern crate nu_ansi_term;
+use nu_ansi_term::Color;
-// This example prints out the 256 colours.
+// This example prints out the 256 colors.
// 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.
+// - 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!(" ");
}
- print!("\n");
+ println!();
for c in 8..16 {
glow(c, c != 8);
print!(" ");
}
- print!("\n\n");
+ println!("\n");
// Six lines of the first three squares
for row in 0..6 {
@@ -34,9 +33,9 @@ fn main() {
print!(" ");
}
- print!("\n");
+ println!();
}
- print!("\n");
+ println!();
// Six more lines of the other three squares
for row in 0..6 {
@@ -49,25 +48,25 @@ fn main() {
print!(" ");
}
- print!("\n");
+ println!();
}
- print!("\n");
+ println!();
// The last greyscale lines
for c in 232..=243 {
glow(c, false);
print!(" ");
}
- print!("\n");
+ println!();
for c in 244..=255 {
glow(c, true);
print!(" ");
}
- print!("\n");
+ println!();
}
fn glow(c: u8, light_bg: bool) {
- let base = if light_bg { Colour::Black } else { Colour::White };
- let style = base.on(Colour::Fixed(c));
+ 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!();
+ }
+}