use ratatui::style::{Color, Modifier, Style};
use crate::core::graph;
pub struct TuiTheme {
pub added: Style,
pub removed: Style,
pub context: Style,
pub hunk_header: Style,
pub file_selected: Style,
pub file_normal: Style,
pub status_bar: Style,
pub border: Style,
pub border_active: Style,
pub staged_status: Style,
pub unstaged_status: Style,
pub untracked_status: Style,
pub file_fully_staged: Style,
pub file_partially_staged: Style,
pub graph: Style,
pub branch: Style,
pub label: Style,
pub dim: Style,
pub dim_selected: Style,
pub message: Style,
pub shortid: Style,
pub untracked: Style,
pub remote_synced: Style,
pub remote_ahead: Style,
pub remote_gone: Style,
pub selection: Style,
pub source: Style,
pub branch_dots: Vec<Style>,
pub ok: Style,
pub warn: Style,
pub err: Style,
pub hint: Style,
pub highlight: Style,
pub cursor: Style,
pub pending_tag: Style,
}
impl TuiTheme {
pub fn from_graph_theme(theme: &graph::Theme) -> Self {
TuiTheme {
added: Style::default().fg(map_color(theme.staged)),
removed: Style::default().fg(map_color(theme.unstaged)),
context: Style::default().fg(map_color(theme.dim)),
hunk_header: Style::default().fg(Color::Blue),
file_selected: Style::default().bg(map_color(theme.selection_bg)),
file_normal: Style::default(),
status_bar: Style::default().fg(map_color(theme.dim)),
border: Style::default().fg(map_color(theme.graph)),
border_active: Style::default()
.fg(map_color(theme.message))
.add_modifier(Modifier::BOLD),
staged_status: Style::default().fg(map_color(theme.staged)),
unstaged_status: Style::default().fg(map_color(theme.unstaged)),
untracked_status: Style::default().fg(map_color(theme.unstaged)),
file_fully_staged: Style::default().fg(map_color(theme.staged)),
file_partially_staged: Style::default().fg(Color::Yellow),
graph: Style::default().fg(map_color(theme.graph)),
branch: Style::default()
.fg(map_color(theme.branch))
.add_modifier(Modifier::BOLD),
label: Style::default().fg(map_color(theme.label)),
dim: Style::default().fg(map_color(theme.dim)),
dim_selected: Style::default().fg(map_color(theme.dim_selected)),
message: Style::default().fg(map_color(theme.message)),
shortid: Style::default()
.fg(map_color(theme.shortid))
.add_modifier(Modifier::UNDERLINED),
untracked: Style::default().fg(map_color(theme.untracked)),
remote_synced: Style::default().fg(map_color(theme.remote_synced)),
remote_ahead: Style::default().fg(map_color(theme.remote_ahead)),
remote_gone: Style::default().fg(map_color(theme.remote_gone)),
selection: Style::default()
.fg(Color::Yellow)
.add_modifier(Modifier::BOLD),
source: Style::default()
.fg(Color::Cyan)
.add_modifier(Modifier::BOLD),
branch_dots: theme
.branch_dots
.iter()
.map(|c| Style::default().fg(map_color(*c)))
.collect(),
ok: Style::default().fg(Color::Green),
warn: Style::default().fg(Color::Yellow),
err: Style::default().fg(Color::Red),
hint: Style::default().fg(Color::Blue),
highlight: Style::default().fg(Color::Yellow),
cursor: Style::default().add_modifier(Modifier::REVERSED),
pending_tag: Style::default()
.fg(map_color(theme.label))
.add_modifier(Modifier::REVERSED | Modifier::BOLD),
}
}
}
fn map_color(c: colored::Color) -> Color {
match c {
colored::Color::Black => Color::Black,
colored::Color::Red => Color::Red,
colored::Color::Green => Color::Green,
colored::Color::Yellow => Color::Yellow,
colored::Color::Blue => Color::Blue,
colored::Color::Magenta => Color::Magenta,
colored::Color::Cyan => Color::Cyan,
colored::Color::White => Color::White,
colored::Color::BrightBlack => Color::DarkGray,
colored::Color::BrightRed => Color::LightRed,
colored::Color::BrightGreen => Color::LightGreen,
colored::Color::BrightYellow => Color::LightYellow,
colored::Color::BrightBlue => Color::LightBlue,
colored::Color::BrightMagenta => Color::LightMagenta,
colored::Color::BrightCyan => Color::LightCyan,
colored::Color::BrightWhite => Color::White,
colored::Color::AnsiColor(n) => Color::Indexed(n),
colored::Color::TrueColor { r, g, b } => Color::Rgb(r, g, b),
}
}