chkc_help/
theme.rs

1//! small wrapper around `termimad::MadSkin` so you can pick an accent and move on.
2
3use termimad::crossterm::style::Color;
4use termimad::{Alignment, CompoundStyle, MadSkin};
5
6/// accent-aware theme used by the renderer.
7#[derive(Debug, Clone)]
8pub struct HelpTheme {
9    pub accent: Color,
10    pub skin: MadSkin,
11}
12
13impl HelpTheme {
14    /// apply an accent to an existing `MadSkin`.
15    pub fn new(mut skin: MadSkin, accent: Color) -> Self {
16        apply_accent(&mut skin, accent);
17        Self { accent, skin }
18    }
19
20    /// light preset respecting the accent.
21    pub fn light(accent: Color) -> Self {
22        Self::new(MadSkin::default_light(), accent)
23    }
24
25    /// dark preset respecting the accent.
26    pub fn dark(accent: Color) -> Self {
27        Self::new(MadSkin::default_dark(), accent)
28    }
29
30    /// chooses light/dark based on terminal luminance.
31    pub fn default(accent: Color) -> Self {
32        if terminal_light::luma().map_or(false, |luma| luma > 0.6) {
33            Self::light(accent)
34        } else {
35            Self::dark(accent)
36        }
37    }
38}
39
40/// tweak a `MadSkin` in-place to carry the accent through headers, bold, strikeouts, etc.
41pub fn apply_accent(skin: &mut MadSkin, accent: Color) {
42    skin.set_headers_fg(accent);
43    skin.headers[0].align = Alignment::Center;
44    skin.bold.set_fg(accent);
45    skin.italic.set_fg(Color::DarkGrey);
46    skin.strikeout = CompoundStyle::with_fg(accent);
47    skin.scrollbar.thumb.set_fg(accent);
48    skin.table_border_chars = termimad::ROUNDED_TABLE_BORDER_CHARS;
49}