use okf_core::{ActorKind, Status, TrustTier};
use ratatui::style::{Color, Modifier, Style};
pub const GLYPH_CONCEPT: &str = "●";
pub const GLYPH_COMPUTATION: &str = "⚙";
pub const GLYPH_INDEX: &str = "◈";
pub const GLYPH_LOG: &str = "≡";
pub const GLYPH_BROKEN: &str = "✗";
pub const GLYPH_WARN: &str = "⚠";
pub const GLYPH_STALE_SOON: &str = "⏳";
pub const GLYPH_FIXABLE: &str = "✚";
pub const GLYPH_OK: &str = "✔";
pub const SPINNER_FRAMES: [&str; 10] = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
#[derive(Clone, Copy, Debug)]
pub struct Theme {
pub color: bool,
}
impl Default for Theme {
fn default() -> Self {
Self::from_env()
}
}
impl Theme {
#[must_use]
pub fn from_env() -> Self {
Self {
color: std::env::var_os("NO_COLOR").is_none_or(|v| v.is_empty()),
}
}
#[must_use]
pub const fn with_color(color: bool) -> Self {
Self { color }
}
fn fg(self, color: Color) -> Style {
if self.color {
Style::default().fg(color)
} else {
Style::default()
}
}
#[must_use]
pub fn accent(self) -> Style {
self.fg(Color::Cyan)
}
#[must_use]
pub fn dim(self) -> Style {
Style::default().add_modifier(Modifier::DIM)
}
#[must_use]
pub fn error(self) -> Style {
self.fg(Color::Red)
}
#[must_use]
pub fn warn(self) -> Style {
self.fg(Color::Yellow)
}
#[must_use]
pub fn ok(self) -> Style {
self.fg(Color::Green)
}
#[must_use]
pub fn selection(self) -> Style {
Style::default().add_modifier(Modifier::REVERSED)
}
#[must_use]
pub fn tier(self, tier: TrustTier) -> Style {
match tier {
TrustTier::HumanReviewed => self.fg(Color::Green),
TrustTier::MachineConfirmed => self.fg(Color::Blue),
TrustTier::Unverified => self.fg(Color::DarkGray),
}
}
#[must_use]
pub fn actor(self, kind: ActorKind) -> Style {
match kind {
ActorKind::Human => self.fg(Color::Cyan),
ActorKind::Process => self.fg(Color::Magenta),
ActorKind::Agent => self.fg(Color::Blue),
ActorKind::Other => Style::default(),
}
}
#[must_use]
pub fn status(self, status: &Status) -> Style {
match status {
Status::Draft => self.fg(Color::Yellow),
Status::Deprecated => self.dim().add_modifier(Modifier::CROSSED_OUT),
Status::Stable | Status::Other(_) => Style::default(),
}
}
}
#[must_use]
pub const fn tier_glyph(tier: TrustTier) -> &'static str {
match tier {
TrustTier::HumanReviewed => "◆",
TrustTier::MachineConfirmed => "●",
TrustTier::Unverified => "○",
}
}
#[must_use]
pub const fn status_glyph(status: &Status) -> &'static str {
match status {
Status::Draft => "◐",
Status::Deprecated => "◌",
Status::Stable | Status::Other(_) => "●",
}
}