use std::fs;
pub struct Logo {
pub lines: Vec<String>,
pub max_len: usize,
pub height: usize,
}
impl Logo {
pub fn empty() -> Self {
Logo {
lines: vec![],
max_len: 0,
height: 0,
}
}
pub fn new(logo_path: Option<String>) -> Self {
let lines: Vec<_> = match logo_path {
Some(logo_path) => fs::read_to_string(logo_path).unwrap(),
None => String::from(DEFAULT_ARTWORK),
}
.lines()
.map(|l| l.replace(r"\033", "\u{1b}"))
.map(|l| l.replace('\t', " "))
.collect();
let mut max_len = 0;
for line in &lines {
let temp_len = Self::get_len(line);
if temp_len > max_len {
max_len = temp_len;
}
}
let height = lines.len();
Logo {
lines,
max_len,
height,
}
}
pub fn get_len(line: &str) -> usize {
let mut is_esc = false;
let l: String = line
.chars()
.filter(|&c| match (is_esc, c) {
(true, 'm') => {
is_esc = false;
false
}
(false, '\u{1b}') => {
is_esc = true;
false
}
_ => !is_esc,
})
.collect();
l.chars().count()
}
}
const DEFAULT_ARTWORK: &str = r#" \033[38;2;80;116;190m/\ \033[38;2;126;179;222m\‾\ /\\033[0m
\033[38;2;80;116;190m\ \ \033[38;2;126;179;222m\ \/ /\033[0m
\033[38;2;80;116;190m/‾‾‾ ‾‾‾\033[38;2;126;179;222m\ / \033[38;2;80;116;190m/\\033[0m
\033[38;2;80;116;190m‾‾\033[38;2;126;179;222m/\033[38;2;80;116;190m‾\033[38;2;126;179;222m/\033[38;2;80;116;190m‾‾‾‾\033[38;2;126;179;222m\ \\033[38;2;80;116;190m/ /\033[0m
\033[38;2;126;179;222m___/ / \\033[38;2;80;116;190m/ /‾‾⟩\033[0m
\033[38;2;126;179;222m⟨__ /\033[38;2;80;116;190m\ \033[38;2;80;116;190m/ /‾‾‾\033[0m
\033[38;2;126;179;222m/ /\033[38;2;80;116;190m\ \\033[38;2;126;179;222m____\033[38;2;80;116;190m/\033[38;2;126;179;222m_\033[38;2;80;116;190m/\033[38;2;126;179;222m__\033[0m
\033[38;2;126;179;222m\/ \033[38;2;80;116;190m/ \\033[38;2;126;179;222m___ ___/\033[0m
\033[38;2;80;116;190m/ /\ \ \033[38;2;126;179;222m\ \\033[0m
\033[38;2;80;116;190m\/ \_\ \033[38;2;126;179;222m\/\033[0m
"#;