use rich::style::Style;
use rich::theme::Theme;
pub const EXTRA_STYLES: &[(&str, &str)] = &[
("error", "bold red"),
("warning", "yellow"),
("info", "cyan"),
("success", "bold green"),
];
pub const STYLE_TABLES: &[&[(&str, &str)]] = &[
EXTRA_STYLES,
crate::cli_doc::STYLES,
crate::diff::STYLES,
crate::workflow::STYLES,
crate::transfer::STYLES,
crate::countdown::STYLES,
crate::notify::STYLES,
crate::table::STYLES,
crate::badge::STYLES,
crate::size_bar::STYLES,
crate::chart::STYLES,
];
pub fn extended_theme() -> Theme {
let mut theme = Theme::default_theme();
for (name, spec) in STYLE_TABLES.iter().copied().flatten() {
if let Ok(style) = Style::parse(spec) {
theme.insert(*name, style);
}
}
theme
}
#[cfg(test)]
mod tests {
use super::*;
fn ours() -> impl Iterator<Item = &'static (&'static str, &'static str)> {
STYLE_TABLES.iter().copied().flatten()
}
#[test]
fn extends_without_dropping_upstream_styles() {
let base = Theme::default_theme();
let extended = extended_theme();
assert_eq!(extended.len(), base.len() + ours().count());
assert!(extended.get("repr.number").is_some());
assert_eq!(
extended.get("error"),
Style::parse("bold red").ok().as_ref()
);
}
#[test]
fn every_added_style_parses() {
for (name, spec) in ours() {
assert!(
Style::parse(spec).is_ok(),
"{name:?} has a bad style {spec:?}"
);
}
}
#[test]
fn core_theme_stays_upstream_only() {
let base = Theme::default_theme();
for (name, _) in ours() {
assert!(
base.get(name).is_none(),
"{name:?} leaked into the core default theme"
);
}
}
}