ghostscope_ui/components/command_panel/
style_builder.rs

1use ratatui::{
2    style::{Color, Modifier, Style},
3    text::{Line, Span},
4};
5
6/// Style presets for different UI elements
7pub struct StylePresets;
8
9impl StylePresets {
10    pub const TITLE: Style = Style::new().fg(Color::Green).add_modifier(Modifier::BOLD);
11    pub const SECTION: Style = Style::new().fg(Color::Cyan).add_modifier(Modifier::BOLD);
12    pub const KEY: Style = Style::new().fg(Color::Cyan);
13    pub const VALUE: Style = Style::new().fg(Color::White);
14    pub const ADDRESS: Style = Style::new().fg(Color::Yellow);
15    pub const TYPE: Style = Style::new().fg(Color::Blue);
16    pub const LOCATION: Style = Style::new().fg(Color::DarkGray);
17    pub const TIP: Style = Style::new().fg(Color::Blue);
18    pub const SUCCESS: Style = Style::new().fg(Color::Green);
19    pub const ERROR: Style = Style::new().fg(Color::Red);
20    pub const WARNING: Style = Style::new().fg(Color::Yellow);
21    pub const TREE: Style = Style::new().fg(Color::DarkGray);
22    pub const MARKER: Style = Style::new().fg(Color::Magenta);
23}
24
25/// Builder for creating styled lines
26#[derive(Default)]
27pub struct StyledLineBuilder {
28    spans: Vec<Span<'static>>,
29}
30
31impl StyledLineBuilder {
32    pub fn new() -> Self {
33        Self { spans: Vec::new() }
34    }
35
36    pub fn text(mut self, text: impl Into<String>) -> Self {
37        self.spans.push(Span::raw(text.into()));
38        self
39    }
40
41    pub fn styled(mut self, text: impl Into<String>, style: Style) -> Self {
42        self.spans.push(Span::styled(text.into(), style));
43        self
44    }
45
46    pub fn title(self, text: impl Into<String>) -> Self {
47        self.styled(text, StylePresets::TITLE)
48    }
49
50    pub fn key(self, text: impl Into<String>) -> Self {
51        self.styled(text, StylePresets::KEY)
52    }
53
54    pub fn value(self, text: impl Into<String>) -> Self {
55        self.styled(text, StylePresets::VALUE)
56    }
57
58    pub fn address(self, addr: u64) -> Self {
59        self.styled(format!("0x{addr:x}"), StylePresets::ADDRESS)
60    }
61
62    pub fn build(self) -> Line<'static> {
63        Line::from(self.spans)
64    }
65}