feat: 🎸 Colors

This commit is contained in:
Atsukoro1 2022-12-01 22:06:04 +01:00
parent c16a99c456
commit 4f8f46df21
2 changed files with 30 additions and 9 deletions

View file

@ -1,5 +1,4 @@
// make const with color names and match them with unicode symbol for color const COLORS : [(&str, &str); 34] = [
const COLORS : [(&str, &str); 17] = [
("black", "\u{001b}[30m"), ("black", "\u{001b}[30m"),
("red", "\u{001b}[31m"), ("red", "\u{001b}[31m"),
("green", "\u{001b}[32m"), ("green", "\u{001b}[32m"),
@ -17,6 +16,23 @@ const COLORS : [(&str, &str); 17] = [
("bright_cyan", "\u{001b}[96m"), ("bright_cyan", "\u{001b}[96m"),
("bright_white", "\u{001b}[97m"), ("bright_white", "\u{001b}[97m"),
("cyan_bold", "\u{001b}[36m\u{001b}[1m"), ("cyan_bold", "\u{001b}[36m\u{001b}[1m"),
("bright_cyan_bold", "\u{001b}[96m\u{001b}[1m"),
("reset", "\u{001b}[0m"),
("bold", "\u{001b}[1m"),
("black_bold", "\u{001b}[30m\u{001b}[1m"),
("red_bold", "\u{001b}[31m\u{001b}[1m"),
("green_bold", "\u{001b}[32m\u{001b}[1m"),
("yellow_bold", "\u{001b}[33m\u{001b}[1m"),
("blue_bold", "\u{001b}[34m\u{001b}[1m"),
("magenta_bold", "\u{001b}[35m\u{001b}[1m"),
("white_bold", "\u{001b}[37m\u{001b}[1m"),
("bright_black_bold", "\u{001b}[90m\u{001b}[1m"),
("bright_red_bold", "\u{001b}[91m\u{001b}[1m"),
("bright_green_bold", "\u{001b}[92m\u{001b}[1m"),
("bright_yellow_bold", "\u{001b}[93m\u{001b}[1m"),
("bright_blue_bold", "\u{001b}[94m\u{001b}[1m"),
("bright_magenta_bold", "\u{001b}[95m\u{001b}[1m"),
("bright_white_bold", "\u{001b}[97m\u{001b}[1m"),
]; ];
pub fn print(text: &str, inline: bool, color: &str) { pub fn print(text: &str, inline: bool, color: &str) {
@ -33,4 +49,6 @@ pub fn print(text: &str, inline: bool, color: &str) {
} else { } else {
println!("{}{}", color, text); println!("{}{}", color, text);
} }
print!("{}", COLORS[18].1);
} }

View file

@ -6,24 +6,27 @@ pub fn print_detail(title: &str, value: String, atype: ActionType, color: &str)
match atype { match atype {
ActionType::Details => { ActionType::Details => {
helpers::colors::print(&title, true, color); print(&title, true, &(color.to_owned() + "_bold"));
for _ in 0..(10 - title.len()) { for _ in 0..(10 - title.len()) {
print!(" "); print!(" ");
} }
helpers::colors::print(" : ", true, "white"); helpers::colors::print(" : ", true, "white_bold");
print!("{}", &value); print!("{}", &value);
}, },
ActionType::Delimiter => { ActionType::Delimiter => {
print("-----------------------------", true, "white"); print("-----------------------------", true, "white_bold");
}, },
ActionType::HostInfo => { ActionType::HostInfo => {
print(&format!( print(&format!(
"{}@{}", "{}@{}",
title, title.to_owned(),
value value.to_owned()
), true, color); ),
true,
&(color.to_owned() + "_bold")
);
} }
}; };
} }