use ratatui::
{
text::{ Line, Span },
backend::FromCrossterm,
style::
{
Color,
Modifier,
Style,
},
};
use crate::{ colors, config };
use super::state::Entry;
pub struct Theme {
pub disable_colors: bool,
pub disable_logo: bool,
pub show_id: bool,
}
impl Theme
{
pub fn load() -> Self
{
Self
{
disable_colors: config::read_config::<bool>("disable_colors"),
disable_logo: config::read_config::<bool>("disable_logo"),
show_id: config::read_config::<bool>("show_id"),
}
}
pub fn reload(&mut self) {
*self = Self::load();
}
pub fn render(&self, entry: &Entry) -> Line<'static>
{
match entry
{
Entry::Line(line) => line.clone(),
Entry::Message { username, id, text, colors } =>
{
let id = if self.show_id { format!(" ({id})") } else { String::new() };
Line::from(vec!
[
self.colorize(username.clone(), colors.username_color),
Span::styled(id, DIM),
Span::raw(": "),
self.colorize(text.clone(), colors.message_color),
])
},
Entry::History { username, text, colors } => Line::from(vec!
[
self.colorize(username.clone(), colors.username_color),
Span::raw(": "),
self.colorize(text.clone(), colors.message_color),
]),
}
}
pub fn colorize(&self, text: String, color: Option<u8>) -> Span<'static> {
match color.and_then(colors::u8_to_color)
{
Some(c) if !self.disable_colors => Span::styled(text, Style::new().fg(Color::from_crossterm(c))),
_ => Span::raw(text),
}
}
}
pub const TEXT: Style = Style::new().fg(Color::Rgb(0xEE, 0xD1, 0xD6)); pub const BORDER: Style = Style::new().fg(Color::Rgb(0xCA, 0xB4, 0xB7)); pub const BORDER_ACTIVE: Style = Style::new().fg(Color::Rgb(0x9D, 0xCE, 0xFF)); pub const TITLE: Style = Style::new().fg(Color::Rgb(0x9D, 0xCE, 0xFF)).add_modifier(Modifier::BOLD);
pub const DIM: Style = Style::new().fg(Color::Rgb(0xCA, 0xB4, 0xB7));
pub const ACCENT: Style = Style::new().fg(Color::Rgb(0x9D, 0xCE, 0xFF));
pub const NOTICE: Style = Style::new().fg(Color::Rgb(0xFF, 0xDD, 0xE2)); pub const ERROR: Style = Style::new().fg(Color::Rgb(0xF6, 0x46, 0xC6)); pub const OK: Style = Style::new().fg(Color::Rgb(0xFF, 0xBB, 0xBA)); pub const SPEAKING: Style = Style::new().fg(Color::Rgb(0xFF, 0xBB, 0xBA)).add_modifier(Modifier::BOLD);
pub const LOGO_COLOR: Color = Color::Rgb(0x5C, 0x46, 0x4B); pub const LOGO: Style = Style::new().fg(LOGO_COLOR); pub const LOGO_UNDER: Style = Style::new().bg(LOGO_COLOR);
pub const SELECTED: Style = Style::new().bg(Color::Rgb(0x00, 0x5F, 0x5F));
pub const ARG_REQUIRED: Style = Style::new().fg(Color::Rgb(0xD7, 0xAF, 0x87)); pub const ARG_OPTIONAL: Style = Style::new().fg(Color::Rgb(0xFF, 0xB4, 0xAB)); pub const ARG_ACTIVE: Style = Style::new().fg(Color::Rgb(0xFF, 0xAF, 0x5F)) .add_modifier(Modifier::BOLD)
.add_modifier(Modifier::UNDERLINED);