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,
}
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(Color::Blue),
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),
}
}
}
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),
}
}