Skip to main content

schwab_cli/ui/
theme.rs

1//! Shared ratatui styling for the options watch dashboard.
2
3use ratatui::style::{Color, Modifier, Style};
4use ratatui::widgets::{Block, BorderType, Borders};
5
6pub const ACCENT: Color = Color::Cyan;
7pub const MUTED: Color = Color::DarkGray;
8pub const PROFIT: Color = Color::Green;
9pub const LOSS: Color = Color::Red;
10pub const WARN: Color = Color::Yellow;
11
12pub fn panel_block(title: &str) -> Block<'_> {
13    Block::default()
14        .borders(Borders::ALL)
15        .border_type(BorderType::Rounded)
16        .title(format!(" {title} "))
17        .title_style(
18            Style::default()
19                .fg(ACCENT)
20                .add_modifier(Modifier::BOLD),
21        )
22        .border_style(Style::default().fg(Color::Rgb(60, 66, 82)))
23}
24
25pub fn chrome_block(title: &str) -> Block<'_> {
26    Block::default()
27        .borders(Borders::ALL)
28        .border_type(BorderType::Rounded)
29        .title(format!(" {title} "))
30        .title_style(
31            Style::default()
32                .fg(ACCENT)
33                .add_modifier(Modifier::BOLD),
34        )
35        .border_style(Style::default().fg(Color::Rgb(45, 50, 64)))
36}
37
38pub fn footer_block() -> Block<'static> {
39    Block::default()
40        .borders(Borders::TOP)
41        .border_type(BorderType::Plain)
42        .border_style(Style::default().fg(Color::Rgb(45, 50, 64)))
43}
44
45pub fn pnl_color(profit_pct: f64) -> Color {
46    if profit_pct >= 25.0 {
47        PROFIT
48    } else if profit_pct <= -25.0 {
49        LOSS
50    } else if profit_pct >= 0.0 {
51        Color::LightGreen
52    } else {
53        WARN
54    }
55}
56
57pub fn gauge_color(ratio: f64) -> Color {
58    if ratio > 0.8 {
59        LOSS
60    } else if ratio > 0.5 {
61        WARN
62    } else {
63        PROFIT
64    }
65}
66
67pub fn label_style() -> Style {
68    Style::default().fg(MUTED)
69}
70
71pub fn value_style() -> Style {
72    Style::default().fg(Color::White)
73}
74
75pub fn key_style() -> Style {
76    Style::default()
77        .fg(Color::Rgb(130, 170, 255))
78        .add_modifier(Modifier::BOLD)
79}