Day 1 Project Files
This commit is contained in:
parent
e1cf4d4dd1
commit
1d0663938b
9
hello_rainbow/Cargo.toml
Normal file
9
hello_rainbow/Cargo.toml
Normal file
@ -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"
|
132
hello_rainbow/src/colors.rs
Normal file
132
hello_rainbow/src/colors.rs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
14
hello_rainbow/src/main.rs
Normal file
14
hello_rainbow/src/main.rs
Normal file
@ -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!");
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user