tmprl 0.1.0

A keyboard-driven terminal client for Temporal
//! Colours.
//!
//! Derived from the `twilight256` palette so the interface sits comfortably beside an editor
//! themed the same way. `theme.toml` loading arrives with the rest of the configuration.

use ratatui::style::Color;
use tmprl_core::Mode;
use tmprl_core::config::Accent;

pub struct Theme {
    pub fg: Color,
    pub dim: Color,
    pub faint: Color,
    pub accent: Color,
    pub ok: Color,
    pub warn: Color,
    pub err: Color,
    pub sel: Color,
}

impl Default for Theme {
    fn default() -> Self {
        Self {
            fg: Color::Rgb(0xd8, 0xdc, 0xe4),
            dim: Color::Rgb(0x8a, 0x93, 0xa3),
            faint: Color::Rgb(0x5a, 0x62, 0x70),
            accent: Color::Rgb(0x6b, 0x99, 0xe8), // Identifier
            ok: Color::Rgb(0xa7, 0xb8, 0x79),     // String
            warn: Color::Rgb(0xF0, 0xC6, 0x74),   // Function
            err: Color::Rgb(0xe0, 0x52, 0x52),
            sel: Color::Rgb(0x2c, 0x33, 0x40),
        }
    }
}

impl Theme {
    /// The colour a profile's `accent` names.
    ///
    /// The basic ANSI colours rather than the palette's RGB: this has to survive a
    /// 16-colour terminal, since the whole point is that production cannot be mistaken
    /// for SIT.
    pub fn accent_color(accent: Accent) -> Color {
        match accent {
            Accent::Red => Color::Red,
            Accent::Green => Color::Green,
            Accent::Yellow => Color::Yellow,
            Accent::Blue => Color::Blue,
            Accent::Magenta => Color::Magenta,
            Accent::Cyan => Color::Cyan,
        }
    }

    /// Mode indicator colour, matching the lualine convention of a distinct hue per mode.
    pub fn mode_color(&self, mode: Mode) -> Color {
        match mode {
            Mode::Normal => Color::Rgb(0xff, 0x00, 0x7c),
            Mode::Insert => Color::Rgb(0x00, 0xd7, 0x5f),
            Mode::Visual | Mode::VisualLine => Color::Rgb(0xff, 0xaf, 0x00),
            Mode::Command => Color::Rgb(0x8b, 0x5f, 0xff),
        }
    }
}