use std::path::PathBuf;
use makeover::{Rgb, ThemeColors, ThemeDirs, ThemeId, Token};
use ratatui::style::Color;
#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
pub struct Theme {
pub surface_page: Color,
pub surface_raised: Color,
pub surface_sunken: Color,
pub surface_overlay: Color,
pub surface_well: Option<Color>,
pub content_primary: Color,
pub content_secondary: Color,
pub content_muted: Color,
pub action_primary: Color,
pub status_danger: Color,
pub status_success: Color,
pub status_warning: Color,
pub status_info: Color,
pub status_danger_surface: Color,
pub status_success_surface: Color,
pub status_warning_surface: Color,
pub status_info_surface: Color,
pub row_hover: Color,
pub row_rule: Color,
pub row_selected: Color,
pub heat: [Color; 5],
pub line_border: Color,
pub border_strong: Color,
pub selection_on: Color,
pub focus_ring: Color,
pub bevel_light: Color,
pub bevel_dark: Color,
pub category: [Color; 6],
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum ThemeError {
MissingKey(&'static str),
InvalidHex { key: &'static str, value: String },
}
impl std::fmt::Display for ThemeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::MissingKey(k) => write!(f, "theme missing required key `{k}`"),
Self::InvalidHex { key, value } => {
write!(f, "theme key `{key}` has invalid hex value `{value}`")
}
}
}
}
impl std::error::Error for ThemeError {}
#[derive(Debug)]
#[non_exhaustive]
pub enum LoadError {
NotFound { id: ThemeId, searched: Vec<PathBuf> },
Read {
id: ThemeId,
searched: Vec<PathBuf>,
source: Box<makeover::LoadError>,
},
Incomplete { id: ThemeId, source: ThemeError },
}
impl std::fmt::Display for LoadError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let joined = |searched: &[PathBuf]| {
searched
.iter()
.map(|path| path.display().to_string())
.collect::<Vec<_>>()
.join(", ")
};
match self {
Self::NotFound { id, searched } => {
write!(f, "no theme `{id}` (searched: {})", joined(searched))
}
Self::Read { id, searched, .. } => {
write!(f, "loading theme `{id}` (searched: {})", joined(searched))
}
Self::Incomplete { id, .. } => write!(f, "theme `{id}` is incomplete"),
}
}
}
impl std::error::Error for LoadError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::NotFound { .. } => None,
Self::Read { source, .. } => Some(source.as_ref()),
Self::Incomplete { source, .. } => Some(source),
}
}
}
impl Theme {
pub fn load(
dirs: &ThemeDirs,
id: &ThemeId,
fidelity: crate::Fidelity,
) -> Result<Self, LoadError> {
let searched = || -> Vec<PathBuf> {
dirs.search_path()
.map(|(path, _)| path.to_path_buf())
.collect()
};
let colors = makeover::load_theme(dirs, id).map_err(|source| match source {
makeover::LoadError::NotFound(_) => LoadError::NotFound {
id: id.clone(),
searched: searched(),
},
source => LoadError::Read {
id: id.clone(),
searched: searched(),
source: Box::new(source),
},
})?;
Self::from_theme(&colors)
.map(|theme| theme.for_terminal(fidelity))
.map_err(|source| LoadError::Incomplete {
id: id.clone(),
source,
})
}
pub fn from_theme(theme: &ThemeColors) -> Result<Self, ThemeError> {
let authored = |key: &'static str| -> Result<Rgb, ThemeError> {
let hex = theme.colors.get(key).ok_or(ThemeError::MissingKey(key))?;
Rgb::from_hex(hex).ok_or_else(|| ThemeError::InvalidHex {
key,
value: hex.clone(),
})
};
let resolved = makeover::resolve(theme);
let derived = |token: Token| -> Result<Rgb, ThemeError> {
resolved
.color(token)
.ok_or(ThemeError::MissingKey(token.as_str()))
};
let lifted = |key: &'static str, token: Token| -> Result<Rgb, ThemeError> {
authored(key)?;
derived(token)
};
let accent = authored("action.primary")?;
let page = authored("surface.page")?;
let selection_on = on_accent(accent, page, authored("content.primary")?);
let grounds = [
page,
authored("surface.raised")?,
derived(Token::RowSelected)?,
];
let status = |key: &'static str| -> Result<Color, ThemeError> {
Ok(rgb(away_from(authored(key)?, &grounds, UI_FLOOR)))
};
Ok(Self {
surface_page: rgb(authored("surface.page")?),
surface_raised: rgb(authored("surface.raised")?),
surface_sunken: rgb(authored("surface.sunken")?),
surface_overlay: rgb(authored("surface.overlay")?),
surface_well: resolved.color(Token::SurfaceWell).map(rgb),
content_primary: rgb(lifted("content.primary", Token::Content)?),
content_secondary: rgb(lifted("content.secondary", Token::ContentSecondary)?),
content_muted: rgb(lifted("content.muted", Token::ContentMuted)?),
action_primary: rgb(accent),
selection_on: rgb(selection_on),
focus_ring: rgb(derived(Token::FocusRing)?),
status_danger: status("status.danger")?,
status_success: status("status.success")?,
status_warning: status("status.warning")?,
status_info: status("status.info")?,
status_danger_surface: rgb(derived(Token::DangerSurface)?),
status_success_surface: rgb(derived(Token::SuccessSurface)?),
status_warning_surface: rgb(derived(Token::WarningSurface)?),
status_info_surface: rgb(derived(Token::InfoSurface)?),
row_hover: rgb(derived(Token::RowHover)?),
row_rule: rgb(derived(Token::RowRule)?),
row_selected: rgb(derived(Token::RowSelected)?),
heat: [
rgb(derived(Token::Heat0)?),
rgb(derived(Token::Heat1)?),
rgb(derived(Token::Heat2)?),
rgb(derived(Token::Heat3)?),
rgb(derived(Token::Heat4)?),
],
line_border: rgb(authored("line.border")?),
border_strong: rgb(derived(Token::BorderStrong)?),
bevel_light: rgb(derived(Token::BevelLight)?),
bevel_dark: rgb(derived(Token::BevelDark)?),
category: [
rgb(authored("category.one")?),
rgb(authored("category.two")?),
rgb(authored("category.three")?),
rgb(authored("category.four")?),
rgb(authored("category.five")?),
rgb(authored("category.six")?),
],
})
}
#[must_use]
pub fn for_terminal(self, fidelity: crate::Fidelity) -> Self {
let Some(q) = Quantize::for_fidelity(fidelity) else {
return self;
};
debug_assert!(
matches!(self.surface_page, Color::Rgb(..)),
"for_terminal takes the authored theme; this one is already quantised"
);
let plain = |c: Color| q.plain(c);
let on_page = |c: Color| q.against(c, self.surface_page);
let read = [self.surface_page, self.surface_raised, self.surface_sunken];
let text = |c: Color| q.legible(c, &read, TEXT_FLOOR);
let marked = [self.surface_page, self.surface_raised, self.row_selected];
let ink = |c: Color| q.legible(c, &marked, UI_FLOOR);
Self {
surface_page: plain(self.surface_page),
surface_raised: plain(self.surface_raised),
surface_sunken: plain(self.surface_sunken),
surface_overlay: plain(self.surface_overlay),
surface_well: self.surface_well.map(plain),
content_primary: text(self.content_primary),
content_secondary: text(self.content_secondary),
content_muted: ink(self.content_muted),
action_primary: on_page(self.action_primary),
selection_on: q.legible(self.selection_on, &[self.action_primary], TEXT_FLOOR),
focus_ring: on_page(self.focus_ring),
status_danger: ink(self.status_danger),
status_success: ink(self.status_success),
status_warning: ink(self.status_warning),
status_info: ink(self.status_info),
status_danger_surface: plain(self.status_danger_surface),
status_success_surface: plain(self.status_success_surface),
status_warning_surface: plain(self.status_warning_surface),
status_info_surface: plain(self.status_info_surface),
row_hover: plain(self.row_hover),
row_rule: plain(self.row_rule),
row_selected: plain(self.row_selected),
heat: self.heat.map(plain),
line_border: on_page(self.line_border),
border_strong: on_page(self.border_strong),
bevel_light: plain(self.bevel_light),
bevel_dark: plain(self.bevel_dark),
category: self.category.map(on_page),
}
}
#[must_use]
pub const fn palette(&self, fidelity: crate::Fidelity) -> crate::Palette {
crate::Palette {
page: self.surface_page,
raised: self.surface_raised,
overlay: self.surface_overlay,
well: self.surface_well,
bevel_light: self.bevel_light,
bevel_dark: self.bevel_dark,
fidelity,
tones: self.tones(),
}
}
#[must_use]
pub const fn tones(&self) -> crate::Tones {
crate::Tones::NONE
.content(self.content_primary)
.secondary(self.content_secondary)
.muted(self.content_muted)
.action(self.action_primary)
.on_action(self.selection_on)
.info(self.status_info)
.success(self.status_success)
.warning(self.status_warning)
.danger(self.status_danger)
.info_surface(self.status_info_surface)
.success_surface(self.status_success_surface)
.warning_surface(self.status_warning_surface)
.danger_surface(self.status_danger_surface)
.neutral_surface(self.row_hover)
.border(self.line_border)
.sunken(self.surface_sunken)
.ground(self.surface_raised)
.stripe(self.surface_page)
.selected(self.row_selected)
.heat_0(self.heat[0])
.heat_1(self.heat[1])
.heat_2(self.heat[2])
.heat_3(self.heat[3])
.heat_4(self.heat[4])
}
}
fn rgb(c: Rgb) -> Color {
Color::Rgb(c.r, c.g, c.b)
}
const TEXT_FLOOR: f32 = 4.5;
const UI_FLOOR: f32 = 3.0;
fn on_accent(accent: Rgb, page: Rgb, content: Rgb) -> Rgb {
let best = if makeover::wcag_contrast(page, accent) >= makeover::wcag_contrast(content, accent)
{
page
} else {
content
};
if makeover::wcag_contrast(best, accent) >= TEXT_FLOOR {
best
} else {
makeover::readable_on(accent)
}
}
fn away_from(color: Rgb, grounds: &[Rgb], floor: f32) -> Rgb {
let worst = |c: Rgb| {
grounds
.iter()
.map(|ground| makeover::wcag_contrast(c, *ground))
.fold(f32::INFINITY, f32::min)
};
if worst(color) >= floor {
return color;
}
let Some(first) = grounds.first() else {
return color;
};
let dark = makeover::wcag_contrast(
Rgb {
r: 255,
g: 255,
b: 255,
},
*first,
) > makeover::wcag_contrast(Rgb { r: 0, g: 0, b: 0 }, *first);
let mut candidate = color;
for _ in 0..20 {
candidate = if dark {
makeover::lighten(candidate, 0.05)
} else {
makeover::darken(candidate, 0.05)
};
if worst(candidate) >= floor {
return candidate;
}
}
candidate
}
#[derive(Debug, Clone, Copy)]
pub struct Quantize {
palette: &'static [Rgb],
offset: usize,
}
impl Quantize {
#[must_use]
pub const fn for_fidelity(fidelity: crate::Fidelity) -> Option<Self> {
match fidelity {
crate::Fidelity::TrueColor => None,
crate::Fidelity::Ansi256 => Some(Self {
palette: makeover::ANSI_240,
offset: makeover::ANSI_240_OFFSET,
}),
crate::Fidelity::Ansi16 => Some(Self {
palette: &makeover::ANSI_16,
offset: 0,
}),
}
}
#[must_use]
pub fn plain(&self, c: Color) -> Color {
match c {
Color::Rgb(r, g, b) => Color::Indexed(
(makeover::quantize(Rgb { r, g, b }, self.palette) + self.offset) as u8,
),
other => other,
}
}
#[must_use]
pub fn legible(&self, c: Color, on: &[Color], floor: f32) -> Color {
let Color::Rgb(r, g, b) = c else {
return self.plain(c);
};
let grounds: Vec<Rgb> = on
.iter()
.filter_map(|ground| match ground {
Color::Rgb(r, g, b) => Some(Rgb {
r: *r,
g: *g,
b: *b,
}),
_ => None,
})
.collect();
Color::Indexed(
(makeover::quantize_legible(Rgb { r, g, b }, &grounds, floor, self.palette)
+ self.offset) as u8,
)
}
#[must_use]
pub fn against(&self, c: Color, on: Color) -> Color {
match (c, on) {
(Color::Rgb(r, g, b), Color::Rgb(br, bg, bb)) => Color::Indexed(
(makeover::quantize_against(
Rgb { r, g, b },
Rgb {
r: br,
g: bg,
b: bb,
},
self.palette,
) + self.offset) as u8,
),
_ => self.plain(c),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn shipped() -> makeover::ThemeDirs {
makeover::ThemeDirs::new().bundled(Some(
makeover::bundled_themes_dir().expect("makeover ships themes"),
))
}
fn bundled(id: &makeover::ThemeId) -> ThemeColors {
makeover::load_theme(&shipped(), id).expect("bundled theme loads")
}
fn metas() -> Vec<makeover::ThemeMeta> {
makeover::list_themes_from_dirs(&shipped()).themes
}
#[test]
fn every_bundled_theme_resolves() {
let metas = metas();
assert!(
!metas.is_empty(),
"makeover shipped no themes to test against"
);
for meta in &metas {
let colors = bundled(&meta.id);
assert!(
Theme::from_theme(&colors).is_ok(),
"bundled theme `{}` failed to resolve",
meta.id
);
}
}
fn to_rgb(c: Color) -> Rgb {
match c {
Color::Rgb(r, g, b) => Rgb { r, g, b },
other => panic!("expected a resolved colour, got {other:?}"),
}
}
#[test]
fn body_text_clears_the_text_floor_on_the_page_in_every_bundled_theme() {
for meta in metas() {
let theme = Theme::from_theme(&bundled(&meta.id)).expect("resolves");
let got =
makeover::wcag_contrast(to_rgb(theme.content_primary), to_rgb(theme.surface_page));
assert!(
got >= TEXT_FLOOR,
"{}: content_primary is {got:.2} on the page",
meta.id
);
}
}
#[test]
fn the_two_derived_cues_are_legible_in_every_bundled_theme() {
for meta in metas() {
let theme = Theme::from_theme(&bundled(&meta.id)).expect("resolves");
let selection =
makeover::wcag_contrast(to_rgb(theme.selection_on), to_rgb(theme.action_primary));
assert!(
selection >= TEXT_FLOOR,
"{}: selection_on is {selection:.2} on the accent",
meta.id
);
let ring =
makeover::wcag_contrast(to_rgb(theme.focus_ring), to_rgb(theme.surface_page));
assert!(
ring >= UI_FLOOR,
"{}: focus_ring is {ring:.2} on the page",
meta.id
);
assert_ne!(theme.focus_ring, theme.border_strong, "{}", meta.id);
}
}
#[test]
fn the_cursor_row_is_its_own_colour_on_every_bundled_theme() {
for meta in metas() {
let theme = Theme::from_theme(&bundled(&meta.id)).expect("resolves");
assert_ne!(theme.row_selected, theme.surface_page, "{}", meta.id);
assert_ne!(theme.row_selected, theme.surface_raised, "{}", meta.id);
}
}
#[test]
fn the_derived_cues_are_quantised_for_the_surface_each_sits_on() {
let theme = Theme::from_theme(&bundled(&makeover::ThemeId::from_static("goingson")))
.expect("resolves");
let ansi16 = theme.for_terminal(crate::Fidelity::Ansi16);
let q = Quantize::for_fidelity(crate::Fidelity::Ansi16).expect("Ansi16 quantises");
assert_eq!(
ansi16.selection_on,
q.against(theme.selection_on, theme.action_primary)
);
assert_eq!(
ansi16.focus_ring,
q.against(theme.focus_ring, theme.surface_page)
);
}
fn worst(ink: Color, grounds: &[Color], fidelity: crate::Fidelity) -> f32 {
let paint = |c: Color| match c {
Color::Rgb(r, g, b) => Rgb { r, g, b },
Color::Indexed(i) => match fidelity {
crate::Fidelity::Ansi16 => makeover::ANSI_16[i as usize],
_ => makeover::ANSI_256[i as usize],
},
other => panic!("unexpected {other:?}"),
};
grounds
.iter()
.map(|g| makeover::wcag_contrast(paint(ink), paint(*g)))
.fold(f32::INFINITY, f32::min)
}
#[test]
fn text_reads_on_every_surface_it_is_drawn_on_at_every_fidelity() {
for meta in metas() {
let theme = Theme::from_theme(&bundled(&meta.id)).expect("resolves");
for fidelity in [crate::Fidelity::Ansi16, crate::Fidelity::Ansi256] {
let shown = theme.for_terminal(fidelity);
let read = [
shown.surface_page,
shown.surface_raised,
shown.surface_sunken,
];
let grey = |c: Rgb| {
let lab = c.to_oklab();
lab.a.hypot(lab.b) < 0.04
};
let entries: Vec<u8> = (0..=255u8)
.filter(|i| (fidelity == crate::Fidelity::Ansi16) == (*i < 16))
.collect();
for (name, ink) in [
("content_primary", shown.content_primary),
("content_secondary", shown.content_secondary),
] {
let got = worst(ink, &read, fidelity);
let possible = entries.iter().any(|i| {
let entry = match fidelity {
crate::Fidelity::Ansi16 => makeover::ANSI_16[*i as usize],
_ => makeover::ANSI_256[*i as usize],
};
grey(entry) && worst(Color::Indexed(*i), &read, fidelity) >= TEXT_FLOOR
});
assert!(
got >= TEXT_FLOOR || !possible,
"{} {fidelity:?}: {name} worst {got:.2} though its kind can clear",
meta.id
);
}
}
}
}
#[test]
fn status_inks_clear_the_ui_floor_on_the_cursor_row_as_authored() {
for meta in metas() {
let theme = Theme::from_theme(&bundled(&meta.id)).expect("resolves");
let grounds = [theme.surface_page, theme.surface_raised, theme.row_selected];
for (name, ink) in [
("danger", theme.status_danger),
("success", theme.status_success),
("warning", theme.status_warning),
("info", theme.status_info),
] {
let got = worst(ink, &grounds, crate::Fidelity::TrueColor);
assert!(got >= UI_FLOOR, "{}: {name} worst {got:.2}", meta.id);
}
}
}
#[test]
fn an_ink_already_legible_is_left_as_authored() {
let page = Rgb {
r: 255,
g: 255,
b: 255,
};
let ink = Rgb { r: 0, g: 0, b: 0 };
assert_eq!(away_from(ink, &[page], UI_FLOOR), ink);
}
#[test]
fn a_missing_intent_names_the_key_it_wanted() {
let mut colors = bundled(&makeover::ThemeId::from_static("goingson"));
colors.colors.remove("content.muted");
match Theme::from_theme(&colors) {
Err(ThemeError::MissingKey(k)) => assert_eq!(k, "content.muted"),
other => panic!("expected MissingKey(content.muted), got {other:?}"),
}
}
#[test]
fn an_unparseable_hex_names_the_key_and_the_value() {
let mut colors = bundled(&makeover::ThemeId::from_static("goingson"));
colors
.colors
.insert("content.muted".into(), "not-a-colour".into());
match Theme::from_theme(&colors) {
Err(ThemeError::InvalidHex { key, value }) => {
assert_eq!(key, "content.muted");
assert_eq!(value, "not-a-colour");
}
other => panic!("expected InvalidHex, got {other:?}"),
}
}
#[test]
fn load_resolves_and_quantises_a_theme_on_the_search_path() {
let id = makeover::ThemeId::from_static("goingson");
let loaded = Theme::load(&shipped(), &id, crate::Fidelity::Ansi16).expect("loads");
let by_hand = Theme::from_theme(&bundled(&id))
.expect("resolves")
.for_terminal(crate::Fidelity::Ansi16);
assert_eq!(loaded.surface_page, by_hand.surface_page);
assert_eq!(loaded.content_primary, by_hand.content_primary);
}
#[test]
fn a_theme_missing_from_the_search_path_names_every_directory_searched() {
let dirs = shipped();
let id = makeover::ThemeId::from_static("no-such-theme");
let err = Theme::load(&dirs, &id, crate::Fidelity::TrueColor).expect_err("missing");
assert!(matches!(err, LoadError::NotFound { .. }), "{err:?}");
let message = err.to_string();
assert!(message.contains("`no-such-theme`"), "{message}");
for (dir, _) in dirs.search_path() {
assert!(message.contains(&dir.display().to_string()), "{message}");
}
}
#[test]
fn a_theme_missing_an_intent_is_reported_incomplete_with_the_key() {
let dir = std::env::temp_dir().join(format!("makeover-tui-load-{}", std::process::id()));
std::fs::create_dir_all(&dir).expect("temp dir");
std::fs::write(dir.join("partial.toml"), "[surface]\npage = \"#ffffff\"\n")
.expect("theme file");
let dirs = makeover::ThemeDirs::new().custom(Some(dir.clone()));
let id = makeover::ThemeId::from_static("partial");
let err = Theme::load(&dirs, &id, crate::Fidelity::TrueColor).expect_err("incomplete");
std::fs::remove_dir_all(&dir).ok();
assert_eq!(err.to_string(), "theme `partial` is incomplete");
let source = std::error::Error::source(&err).expect("names the key");
assert!(
source.to_string().contains("theme missing required key"),
"{source}"
);
}
#[test]
fn a_capable_terminal_gets_the_theme_as_authored() {
let theme = Theme::from_theme(&bundled(&makeover::ThemeId::from_static("goingson")))
.expect("resolves");
let same = theme.for_terminal(crate::Fidelity::TrueColor);
assert_eq!(same.surface_page, theme.surface_page);
assert_eq!(same.content_primary, theme.content_primary);
assert!(matches!(same.surface_page, Color::Rgb(..)));
}
#[test]
fn a_limited_terminal_gets_indices_rather_than_rgb() {
let theme = Theme::from_theme(&bundled(&makeover::ThemeId::from_static("goingson")))
.expect("resolves");
for fidelity in [crate::Fidelity::Ansi16, crate::Fidelity::Ansi256] {
let q = theme.for_terminal(fidelity);
assert!(
matches!(q.surface_page, Color::Indexed(_)),
"{fidelity:?} left a surface as rgb"
);
assert!(
matches!(q.content_primary, Color::Indexed(_)),
"{fidelity:?} left content as rgb"
);
}
}
#[test]
fn the_256_indices_land_outside_the_repaintable_low_sixteen() {
let theme = Theme::from_theme(&bundled(&makeover::ThemeId::from_static("goingson")))
.expect("resolves");
let q = theme.for_terminal(crate::Fidelity::Ansi256);
for (name, c) in [
("surface_page", q.surface_page),
("content_primary", q.content_primary),
("bevel_light", q.bevel_light),
("bevel_dark", q.bevel_dark),
] {
match c {
Color::Indexed(i) => assert!(i >= 16, "{name} landed on repaintable index {i}"),
other => panic!("{name} was not quantised: {other:?}"),
}
}
}
#[test]
fn the_bevel_pair_stays_two_tones_at_256() {
let theme = Theme::from_theme(&bundled(&makeover::ThemeId::from_static("goingson")))
.expect("resolves");
let q = theme.for_terminal(crate::Fidelity::Ansi256);
assert_ne!(q.bevel_light, q.bevel_dark);
}
#[test]
fn the_palette_takes_the_well_and_not_the_sunken_surface() {
let colors = bundled(&makeover::ThemeId::from_static("goingson"));
let theme = Theme::from_theme(&colors).expect("resolves");
let palette = theme.palette(crate::Fidelity::TrueColor);
assert_eq!(palette.well, theme.surface_well);
assert_ne!(palette.well, Some(theme.surface_sunken));
}
#[test]
fn a_heat_band_is_a_background_up_to_the_cursor_row_and_band_0_is_none() {
use makeover_layout::Heat;
use ratatui::style::Style;
for meta in metas() {
let theme = Theme::from_theme(&bundled(&meta.id)).expect("resolves");
assert_eq!(theme.heat[0], theme.surface_raised, "{}", meta.id);
assert_eq!(theme.heat[4], theme.row_selected, "{}", meta.id);
let palette = theme.palette(crate::Fidelity::TrueColor);
let ink = crate::piece::Ink::new(&palette, &crate::piece::PieceStyle::default());
assert_eq!(ink.heat(Heat(0)), Style::new(), "{}", meta.id);
for (band, fill) in (1u8..).zip(&theme.heat[1..]) {
assert_eq!(ink.heat(Heat(band)), Style::new().bg(*fill), "{}", meta.id);
}
assert_eq!(ink.heat(Heat(9)), ink.heat(Heat(4)), "{}", meta.id);
}
}
#[test]
fn a_themes_palette_resolves_into_the_house_ink() {
use ratatui::style::{Modifier, Style};
let theme = Theme::from_theme(&bundled(&makeover::ThemeId::from_static("goingson")))
.expect("resolves");
let palette = theme.palette(crate::Fidelity::TrueColor);
let ink = crate::piece::Ink::new(&palette, &crate::piece::PieceStyle::default());
assert_eq!(ink.muted, Style::new().fg(theme.content_muted));
assert_eq!(
ink.filled,
Style::new().fg(theme.selection_on).bg(theme.action_primary)
);
assert_eq!(
ink.page,
Style::new()
.fg(theme.action_primary)
.add_modifier(Modifier::BOLD)
);
let danger = ink.badge(makeover_layout::Tone::Danger).expect("filled");
assert_eq!(danger.fill.bg, Some(theme.status_danger_surface));
assert_eq!(danger.edge.fg, Some(theme.status_danger));
let table = crate::table::TableInk::new(&palette, &crate::table::TableStyle::default());
assert_eq!(table.ground, Style::new().bg(theme.surface_raised));
assert_eq!(table.stripe, Style::new().bg(theme.surface_page));
assert_eq!(table.selected.bg, Some(theme.row_selected));
assert!(table.selected.fg.is_none());
assert_eq!(table.header.bg, Some(theme.surface_sunken));
}
}