use std::borrow::Cow;
use tabled::Table;
use tabled::settings::Style;
use tabled::settings::style::HorizontalLine;
fn no_color() -> bool {
!crate::runtime_flags::color_enabled()
}
fn wrap<'a>(code: &str, text: &'a str) -> Cow<'a, str> {
if no_color() {
Cow::Borrowed(text)
} else {
Cow::Owned(format!("\x1b[{}m{}\x1b[0m", code, text))
}
}
pub fn red(text: &str) -> Cow<'_, str> {
wrap("31", text)
}
pub fn green(text: &str) -> Cow<'_, str> {
wrap("32", text)
}
pub fn yellow(text: &str) -> Cow<'_, str> {
wrap("33", text)
}
pub fn magenta(text: &str) -> Cow<'_, str> {
wrap("35", text)
}
pub fn cyan(text: &str) -> Cow<'_, str> {
wrap("36", text)
}
pub fn bold(text: &str) -> Cow<'_, str> {
wrap("1", text)
}
pub fn dim(text: &str) -> Cow<'_, str> {
wrap("2", text)
}
pub fn print_table(mut table: Table) {
println!("{}", table.with(Style::rounded()));
}
pub fn print_table_with_total(mut table: Table) {
let n_rows = table.count_rows();
let style = Style::rounded().horizontals([
(n_rows - 1, HorizontalLine::inherit(Style::modern()))
]);
println!("{}", table.with(style));
}
pub fn yes_no(b: bool) -> &'static str {
if b { "Yes" } else { "No" }
}