use crate::rhei_viz_model::Machine;
use ratatui::style::Color;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum Category {
Done,
Blocked,
Failed,
Gate,
Retired,
Idle,
Active,
}
pub(super) fn category(machine: &Machine, state: &str) -> Category {
let def = machine.states.iter().find(|s| s.name == state);
if state == "completed" {
return Category::Done;
}
if state == "failed" {
return Category::Failed;
}
if state == "blocked" {
return Category::Blocked;
}
if def.map(|d| d.gating).unwrap_or(false) || state == "human-review" {
return Category::Gate;
}
if def.map(|d| d.terminal).unwrap_or(false) {
return Category::Retired;
}
if state == "cancelled" || state == "archived" {
return Category::Retired;
}
let is_initial = def.map(|d| d.initial).unwrap_or(false);
if state == "draft" || state == "pending" || is_initial {
return Category::Idle;
}
Category::Active
}
pub(super) fn category_glyph(category: Category) -> char {
match category {
Category::Done => '✓',
Category::Blocked => '⊘',
Category::Failed => '✗',
Category::Gate => '⏸',
Category::Retired => '⊝',
Category::Idle => '·',
Category::Active => '●',
}
}
#[derive(Clone, Copy)]
pub(super) struct Theme {
pub(super) color: bool,
}
impl Theme {
pub(super) fn from_env() -> Self {
let color = std::env::var_os("NO_COLOR").map(|v| v.is_empty()).unwrap_or(true);
Self { color }
}
pub(super) fn reduced_motion(&self) -> bool {
!self.color
}
pub(super) fn category_color(&self, category: Category) -> Color {
if !self.color {
return Color::Reset;
}
match category {
Category::Done => Color::Green,
Category::Blocked => Color::Red,
Category::Failed => Color::Red,
Category::Gate => Color::LightCyan,
Category::Retired => Color::DarkGray,
Category::Idle => Color::Gray,
Category::Active => Color::Blue,
}
}
pub(super) fn live_color(&self) -> Color {
if self.color {
Color::Cyan
} else {
Color::Reset
}
}
pub(super) fn program_color(&self) -> Color {
if self.color {
Color::Yellow
} else {
Color::Reset
}
}
pub(super) fn accent(&self) -> Color {
if self.color {
Color::Cyan
} else {
Color::Reset
}
}
pub(super) fn dim(&self) -> Color {
if self.color {
Color::DarkGray
} else {
Color::Reset
}
}
}