Commit 009900d8 authored by Moritz Sokoll's avatar Moritz Sokoll 🦀
Browse files

added text formatting function

parent 23bc9a73
......@@ -38,7 +38,37 @@ pub mod formatting {
///
/// the formatted text with escape characters to be printed to the terminal
pub fn format(text: Vec<Variant<ColoredText, ColoredBg>>) -> String {
let out: String = String::new();
let mut out: String = String::new();
for elm in text {
let add: String = match elm {
Variant::One(n) => {
match n {
ColoredText::Black(p) => format!("\033[30m{}", p),
ColoredText::Red(p) => format!("\033[31m{}", p),
ColoredText::Green(p) => format!("\033[32m{}", p),
ColoredText::Yellow(p) => format!("\033[33m{}", p),
ColoredText::Blue(p) => format!("\033[34m{}", p),
ColoredText::Magenta(p) => format!("\033[35m{}", p),
ColoredText::Cyan(p) => format!("\033[36m{}", p),
ColoredText::White(p) => format!("\033[37m{}", p),
}
}
Variant::Two(n) => {
match n {
ColoredBg::Black => String::from("\033[40m"),
ColoredBg::Red => String::from("\033[41m"),
ColoredBg::Green => String::from("\033[42m"),
ColoredBg::Yellow => String::from("\033[43m"),
ColoredBg::Blue => String::from("\033[44m"),
ColoredBg::Magenta => String::from("\033[45m"),
ColoredBg::Cyan => String::from("\033[46m"),
ColoredBg::White => String::from("\033[47m"),
}
},
};
out.push_str(add.as_str());
}
out
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment