From 9918693037dce8aa4bb6f08741b6812923486c18 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 19 Jun 2024 11:26:03 +0200 Subject: Merging upstream version 1.76.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/nu-ansi-term-0.46.0/examples/256_colors.rs | 72 ++++++++++++++++++++++ .../nu-ansi-term-0.46.0/examples/basic_colors.rs | 18 ++++++ .../examples/gradient_colors.rs | 37 +++++++++++ vendor/nu-ansi-term-0.46.0/examples/rgb_colors.rs | 23 +++++++ 4 files changed, 150 insertions(+) create mode 100644 vendor/nu-ansi-term-0.46.0/examples/256_colors.rs create mode 100644 vendor/nu-ansi-term-0.46.0/examples/basic_colors.rs create mode 100644 vendor/nu-ansi-term-0.46.0/examples/gradient_colors.rs create mode 100644 vendor/nu-ansi-term-0.46.0/examples/rgb_colors.rs (limited to 'vendor/nu-ansi-term-0.46.0/examples') diff --git a/vendor/nu-ansi-term-0.46.0/examples/256_colors.rs b/vendor/nu-ansi-term-0.46.0/examples/256_colors.rs new file mode 100644 index 000000000..4766dcdb6 --- /dev/null +++ b/vendor/nu-ansi-term-0.46.0/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-0.46.0/examples/basic_colors.rs b/vendor/nu-ansi-term-0.46.0/examples/basic_colors.rs new file mode 100644 index 000000000..3c2b6817f --- /dev/null +++ b/vendor/nu-ansi-term-0.46.0/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-0.46.0/examples/gradient_colors.rs b/vendor/nu-ansi-term-0.46.0/examples/gradient_colors.rs new file mode 100644 index 000000000..1c9583865 --- /dev/null +++ b/vendor/nu-ansi-term-0.46.0/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-0.46.0/examples/rgb_colors.rs b/vendor/nu-ansi-term-0.46.0/examples/rgb_colors.rs new file mode 100644 index 000000000..4657d401f --- /dev/null +++ b/vendor/nu-ansi-term-0.46.0/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!(); + } +} -- cgit v1.2.3