Skip to main content

entrust_dialog/
theme.rs

1use ratatui::prelude::Style;
2use std::borrow::Cow;
3use std::ops::Deref;
4use std::sync::LazyLock;
5
6#[derive(Clone, Debug, PartialEq)]
7pub struct Theme {
8    pub cursor_on_style: Style,
9    pub cursor_off_style: Style,
10    pub header_style: Style,
11    pub select_indicator: String,
12    pub placeholder_style: Style,
13    pub prompt_style: Style,
14    pub selected_style: Style,
15    pub match_style: Style,
16    pub completion_style: Style,
17}
18
19impl Default for Theme {
20    fn default() -> Self {
21        Theme {
22            cursor_on_style: Style::new().black().on_light_blue(),
23            cursor_off_style: Style::new(),
24            header_style: Style::new().light_blue().bold(),
25            placeholder_style: Style::new().dim(),
26            prompt_style: Style::new().light_yellow().bold(),
27            select_indicator: "• ".to_string(),
28            selected_style: Style::new().bold(),
29            match_style: Style::new().light_blue().underlined(),
30            completion_style: Style::new().dim().italic(),
31        }
32    }
33}
34
35impl Default for &'static Theme {
36    fn default() -> Self {
37        Theme::default_ref()
38    }
39}
40
41impl Theme {
42    pub fn default_ref() -> &'static Theme {
43        static THEME: LazyLock<Theme> = LazyLock::new(Theme::default);
44        THEME.deref()
45    }
46}
47
48impl From<Theme> for Cow<'static, Theme> {
49    fn from(value: Theme) -> Self {
50        Cow::Owned(value)
51    }
52}
53
54impl<'a> From<&'a Theme> for Cow<'a, Theme> {
55    fn from(value: &'a Theme) -> Self {
56        Cow::Borrowed(value)
57    }
58}