pub struct Ui {
pub color: bool,
}
const BANNER: &str = r#" ______ _____ __ __ ______ __ __
/ ____/ / ___/ / / / / / ____/ / / / /
/ / _____ \__ \ / /_/ / / __/ / / / /
/ /___ /_____/ ___/ / / __ / / /___ / /___ / /___
\____/ /____/ /_/ /_/ /_____/ /_____//_____/
"#;
impl Ui {
fn paint(&self, code: &str, s: &str) -> String {
if self.color {
format!("\x1b[{code}m{s}\x1b[0m")
} else {
s.to_string()
}
}
pub fn banner(&self) -> String {
self.paint("1;36", BANNER)
}
pub fn prompt_label(n: usize) -> String {
format!("In [{n}]:")
}
pub fn prompt_width(n: usize) -> usize {
Self::prompt_label(n).len() + 1
}
pub fn out_label(&self, n: usize) -> String {
self.paint("1;31", &format!("Out[{n}]: "))
}
pub fn inserted_newline_marker(&self) -> String {
self.dim("↵")
}
pub fn err(&self, s: &str) -> String {
self.paint("31", s)
}
pub fn warn(&self, s: &str) -> String {
self.paint("33", s)
}
pub fn dim(&self, s: &str) -> String {
self.paint("2", s)
}
pub fn bold(&self, s: &str) -> String {
self.paint("1", s)
}
}