From 1d0663938b86ccd6e55ffbaae6976a88ccb2e5f6 Mon Sep 17 00:00:00 2001 From: Dom Sec <54043553+dom-sec@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:25:59 -0400 Subject: [PATCH] Day 1 Project Files --- hello_rainbow/Cargo.toml | 9 +++ hello_rainbow/src/colors.rs | 132 ++++++++++++++++++++++++++++++++++++ hello_rainbow/src/main.rs | 14 ++++ 3 files changed, 155 insertions(+) create mode 100644 hello_rainbow/Cargo.toml create mode 100644 hello_rainbow/src/colors.rs create mode 100644 hello_rainbow/src/main.rs diff --git a/hello_rainbow/Cargo.toml b/hello_rainbow/Cargo.toml new file mode 100644 index 0000000..abe187e --- /dev/null +++ b/hello_rainbow/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "hello_rainbow" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +termcolor = "1.2" diff --git a/hello_rainbow/src/colors.rs b/hello_rainbow/src/colors.rs new file mode 100644 index 0000000..0741137 --- /dev/null +++ b/hello_rainbow/src/colors.rs @@ -0,0 +1,132 @@ +use std::io::{Write}; +use termcolor::{Color, ColorChoice, ColorSpec, WriteColor, StandardStream}; + +pub fn print_green(text: &str) { + // Create a color specification for green + let mut spec = ColorSpec::new(); + spec.set_fg(Some(Color::Green)); + + // Create a standard stream for writing to the console + let mut stdout = StandardStream::stdout(ColorChoice::Always); + + // Write the text to the console with the green color + stdout.set_color(&spec).unwrap(); + writeln!(&mut stdout, "{}", text).unwrap(); + + // Reset the color specification to the default + stdout.reset().unwrap(); +} + +pub fn print_black(text: &str) { + // Create a color specification for black + let mut spec = ColorSpec::new(); + spec.set_fg(Some(Color::Black)); + + // Create a standard stream for writing to the console + let mut stdout = StandardStream::stdout(ColorChoice::Always); + + // Write the text to the console with the green color + stdout.set_color(&spec).unwrap(); + writeln!(&mut stdout, "{}", text).unwrap(); + + // Reset the color specification to the default + stdout.reset().unwrap(); +} + +pub fn print_blue(text: &str) { + // Create a color specification for blue + let mut spec = ColorSpec::new(); + spec.set_fg(Some(Color::Blue)); + + // Create a standard stream for writing to the console + let mut stdout = StandardStream::stdout(ColorChoice::Always); + + // Write the text to the console with the green color + stdout.set_color(&spec).unwrap(); + writeln!(&mut stdout, "{}", text).unwrap(); + + // Reset the color specification to the default + stdout.reset().unwrap(); +} + +pub fn print_red(text: &str) { + // Create a color specification for red + let mut spec = ColorSpec::new(); + spec.set_fg(Some(Color::Red)); + + // Create a standard stream for writing to the console + let mut stdout = StandardStream::stdout(ColorChoice::Always); + + // Write the text to the console with the green color + stdout.set_color(&spec).unwrap(); + writeln!(&mut stdout, "{}", text).unwrap(); + + // Reset the color specification to the default + stdout.reset().unwrap(); +} + +pub fn print_cyan(text: &str) { + // Create a color specification for cyan + let mut spec = ColorSpec::new(); + spec.set_fg(Some(Color::Cyan)); + + // Create a standard stream for writing to the console + let mut stdout = StandardStream::stdout(ColorChoice::Always); + + // Write the text to the console with the green color + stdout.set_color(&spec).unwrap(); + writeln!(&mut stdout, "{}", text).unwrap(); + + // Reset the color specification to the default + stdout.reset().unwrap(); +} + +pub fn print_magenta(text: &str) { + // Create a color specification for magenta + let mut spec = ColorSpec::new(); + spec.set_fg(Some(Color::Magenta)); + + // Create a standard stream for writing to the console + let mut stdout = StandardStream::stdout(ColorChoice::Always); + + // Write the text to the console with the green color + stdout.set_color(&spec).unwrap(); + writeln!(&mut stdout, "{}", text).unwrap(); + + // Reset the color specification to the default + stdout.reset().unwrap(); +} + +pub fn print_yellow(text: &str) { + // Create a color specification for yellow + let mut spec = ColorSpec::new(); + spec.set_fg(Some(Color::Yellow)); + + // Create a standard stream for writing to the console + let mut stdout = StandardStream::stdout(ColorChoice::Always); + + // Write the text to the console with the green color + stdout.set_color(&spec).unwrap(); + writeln!(&mut stdout, "{}", text).unwrap(); + + // Reset the color specification to the default + stdout.reset().unwrap(); +} + +pub fn print_white(text: &str) { + // Create a color specification for white + let mut spec = ColorSpec::new(); + spec.set_fg(Some(Color::White)); + + // Create a standard stream for writing to the console + let mut stdout = StandardStream::stdout(ColorChoice::Always); + + // Write the text to the console with the green color + stdout.set_color(&spec).unwrap(); + writeln!(&mut stdout, "{}", text).unwrap(); + + // Reset the color specification to the default + stdout.reset().unwrap(); +} + + diff --git a/hello_rainbow/src/main.rs b/hello_rainbow/src/main.rs new file mode 100644 index 0000000..19dadfc --- /dev/null +++ b/hello_rainbow/src/main.rs @@ -0,0 +1,14 @@ +mod colors; + +fn main() { + + colors::print_black("Hello Black!"); + colors::print_blue("Hello Blue!"); + colors::print_green("Hello Green!"); + colors::print_red("Hello Red!"); + colors::print_cyan("Hello Cyan!"); + colors::print_magenta("Hello Magenta!"); + colors::print_yellow("Hello Yellow!"); + colors::print_white("Hello White!"); + +}