rat_theme3/
lib.rs

1use crate::palettes::{
2    BASE16, BASE16_RELAX, BLACKWHITE, IMPERIAL, MONEKAI, MONOCHROME, OCEAN, OXOCARBON, RADIUM,
3    RUST, SOLARIZED, TUNDRA, VSCODE_DARK,
4};
5use rat_widget::button::ButtonStyle;
6use rat_widget::calendar::CalendarStyle;
7use rat_widget::checkbox::CheckboxStyle;
8use rat_widget::choice::ChoiceStyle;
9use rat_widget::clipper::ClipperStyle;
10use rat_widget::file_dialog::FileDialogStyle;
11use rat_widget::line_number::LineNumberStyle;
12use rat_widget::list::ListStyle;
13use rat_widget::menu::MenuStyle;
14use rat_widget::msgdialog::MsgDialogStyle;
15#[allow(deprecated)]
16use rat_widget::pager::PagerStyle;
17use rat_widget::paragraph::ParagraphStyle;
18use rat_widget::radio::RadioStyle;
19use rat_widget::scrolled::ScrollStyle;
20use rat_widget::shadow::ShadowStyle;
21use rat_widget::slider::SliderStyle;
22use rat_widget::splitter::SplitStyle;
23use rat_widget::statusline::StatusLineStyle;
24use rat_widget::tabbed::TabbedStyle;
25use rat_widget::table::TableStyle;
26use rat_widget::text::TextStyle;
27use rat_widget::view::ViewStyle;
28use ratatui::prelude::Style;
29
30mod dark_theme;
31mod palette;
32pub mod palettes;
33mod shell_theme;
34
35pub use dark_theme::*;
36pub use palette::*;
37use rat_widget::form::FormStyle;
38pub use shell_theme::*;
39
40/// Trait for a theme.
41pub trait SalsaTheme {
42    /// Theme name.
43    fn name(&self) -> &str;
44
45    /// Color palette.
46    fn palette(&self) -> &Palette;
47
48    /// Create a style from the given white shade.
49    /// n is `0..8`
50    fn white(&self, n: usize) -> Style;
51
52    /// Create a style from the given black shade.
53    /// n is `0..8`
54    fn black(&self, n: usize) -> Style;
55
56    /// Create a style from the given gray shade.
57    /// n is `0..8`
58    fn gray(&self, n: usize) -> Style;
59
60    /// Create a style from the given red shade.
61    /// n is `0..8`
62    fn red(&self, n: usize) -> Style;
63
64    /// Create a style from the given orange shade.
65    /// n is `0..8`
66    fn orange(&self, n: usize) -> Style;
67
68    /// Create a style from the given yellow shade.
69    /// n is `0..8`
70    fn yellow(&self, n: usize) -> Style;
71
72    /// Create a style from the given limegreen shade.
73    /// n is `0..8`
74    fn limegreen(&self, n: usize) -> Style;
75
76    /// Create a style from the given green shade.
77    /// n is `0..8`
78    fn green(&self, n: usize) -> Style;
79
80    /// Create a style from the given bluegreen shade.
81    /// n is `0..8`
82    fn bluegreen(&self, n: usize) -> Style;
83
84    /// Create a style from the given cyan shade.
85    /// n is `0..8`
86    fn cyan(&self, n: usize) -> Style;
87
88    /// Create a style from the given blue shade.
89    /// n is `0..8`
90    fn blue(&self, n: usize) -> Style;
91
92    /// Create a style from the given deepblue shade.
93    /// n is `0..8`
94    fn deepblue(&self, n: usize) -> Style;
95
96    /// Create a style from the given purple shade.
97    /// n is `0..8`
98    fn purple(&self, n: usize) -> Style;
99
100    /// Create a style from the given magenta shade.
101    /// n is `0..8`
102    fn magenta(&self, n: usize) -> Style;
103
104    /// Create a style from the given redpink shade.
105    /// n is `0..8`
106    fn redpink(&self, n: usize) -> Style;
107
108    /// Create a style from the given primary shade.
109    /// n is `0..8`
110    fn primary(&self, n: usize) -> Style;
111
112    /// Create a style from the given secondary shade.
113    /// n is `0..8`
114    fn secondary(&self, n: usize) -> Style;
115
116    /// Focused style.
117    fn focus(&self) -> Style;
118    /// Selection style.
119    fn select(&self) -> Style;
120
121    /// Text input base style.
122    fn text_input(&self) -> Style;
123    /// Text input with focus.
124    fn text_focus(&self) -> Style;
125    /// Text selection.
126    fn text_select(&self) -> Style;
127
128    /// Scroll style
129    fn scroll_style(&self) -> ScrollStyle;
130
131    /// Container base.
132    fn container_base(&self) -> Style;
133    /// Container border.
134    fn container_border(&self) -> Style;
135    /// Container scrollbar arrows.
136    fn container_arrow(&self) -> Style;
137
138    /// Background for popups.
139    fn popup_base(&self) -> Style;
140    /// Border for popups.
141    fn popup_border(&self) -> Style;
142    /// Popup scrollbar arrows.
143    fn popup_arrow(&self) -> Style;
144    /// Popup scroll style
145    fn popup_scroll_style(&self) -> ScrollStyle;
146
147    /// Background for dialogs.
148    fn dialog_base(&self) -> Style;
149    /// Border for dialogs.
150    fn dialog_border(&self) -> Style;
151    /// Dialog scrollbar arrows.
152    fn dialog_arrow(&self) -> Style;
153    /// Dialog scroll style
154    fn dialog_scroll_style(&self) -> ScrollStyle;
155
156    /// Style for the status line.
157    fn status_base(&self) -> Style;
158
159    /// Base style for buttons.
160    fn button_base(&self) -> Style;
161    /// Armed style for buttons.
162    fn button_armed(&self) -> Style;
163
164    /// Field label style.
165    fn label_style(&self) -> Style;
166
167    /// Any text fields as input widgets.
168    fn text_style(&self) -> TextStyle;
169
170    /// TextArea as input widget.
171    fn textarea_style(&self) -> TextStyle;
172
173    /// Choice.
174    fn choice_style(&self) -> ChoiceStyle;
175
176    /// Radiobutton.
177    fn radio_style(&self) -> RadioStyle;
178
179    /// Checkbox.
180    fn checkbox_style(&self) -> CheckboxStyle;
181
182    /// Slider.
183    fn slider_style(&self) -> SliderStyle;
184
185    /// Calendar.
186    fn month_style(&self) -> CalendarStyle;
187
188    /// Line numbers.
189    fn line_nr_style(&self) -> LineNumberStyle;
190
191    /// Buttons.
192    fn button_style(&self) -> ButtonStyle;
193
194    /// Table.
195    fn table_style(&self) -> TableStyle;
196
197    /// List.
198    fn list_style(&self) -> ListStyle;
199
200    /// Text style for view-only TextAreas.
201    fn textview_style(&self) -> TextStyle;
202
203    /// Paragraph.
204    fn paragraph_style(&self) -> ParagraphStyle;
205
206    /// Shadow.
207    fn shadow_style(&self) -> ShadowStyle;
208
209    /// Menus.
210    fn menu_style(&self) -> MenuStyle;
211
212    /// Split.
213    fn split_style(&self) -> SplitStyle;
214
215    /// View.
216    fn view_style(&self) -> ViewStyle;
217
218    /// Tabbed.
219    fn tabbed_style(&self) -> TabbedStyle;
220
221    /// Old school statusline styling.
222    fn statusline_style(&self) -> Vec<Style>;
223
224    /// Style for a StatusLine with 3 indicator fields.
225    fn statusline_style_ext(&self) -> StatusLineStyle;
226
227    /// FileDialog.
228    fn file_dialog_style(&self) -> FileDialogStyle;
229
230    /// MsgDialog.
231    fn msg_dialog_style(&self) -> MsgDialogStyle;
232
233    /// Pager.
234    #[allow(deprecated)]
235    fn pager_style(&self) -> PagerStyle;
236
237    /// Form.
238    fn form_style(&self) -> FormStyle;
239
240    /// Clipper.
241    fn clipper_style(&self) -> ClipperStyle;
242}
243
244// Create a theme + palette.
245pub fn create_theme(theme: &str) -> Option<Box<dyn SalsaTheme>> {
246    let theme: Box<dyn SalsaTheme> = match theme {
247        "Imperial Dark" => Box::new(DarkTheme::new(theme, IMPERIAL)),
248        "Radium Dark" => Box::new(DarkTheme::new(theme, RADIUM)),
249        "Tundra Dark" => Box::new(DarkTheme::new(theme, TUNDRA)),
250        "Ocean Dark" => Box::new(DarkTheme::new(theme, OCEAN)),
251        "Monochrome Dark" => Box::new(DarkTheme::new(theme, MONOCHROME)),
252        "Black&White Dark" => Box::new(DarkTheme::new(theme, BLACKWHITE)),
253        "Base16 Dark" => Box::new(DarkTheme::new(theme, BASE16)),
254        "Base16 Relax Dark" => Box::new(DarkTheme::new(theme, BASE16_RELAX)),
255        "Monekai Dark" => Box::new(DarkTheme::new(theme, MONEKAI)),
256        "Solarized Dark" => Box::new(DarkTheme::new(theme, SOLARIZED)),
257        "OxoCarbon Dark" => Box::new(DarkTheme::new(theme, OXOCARBON)),
258        "Rust Dark" => Box::new(DarkTheme::new(theme, RUST)),
259        "VSCode Dark" => Box::new(DarkTheme::new(theme, VSCODE_DARK)),
260        //
261        "Imperial Shell" => Box::new(ShellTheme::new(theme, IMPERIAL)),
262        "Radium Shell" => Box::new(ShellTheme::new(theme, RADIUM)),
263        "Tundra Shell" => Box::new(ShellTheme::new(theme, TUNDRA)),
264        "Ocean Shell" => Box::new(ShellTheme::new(theme, OCEAN)),
265        "Monochrome Shell" => Box::new(ShellTheme::new(theme, MONOCHROME)),
266        "Black&White Shell" => Box::new(ShellTheme::new(theme, BLACKWHITE)),
267        "Base16 Shell" => Box::new(ShellTheme::new(theme, BASE16)),
268        "Base16 Relax Shell" => Box::new(ShellTheme::new(theme, BASE16_RELAX)),
269        "Monekai Shell" => Box::new(ShellTheme::new(theme, MONEKAI)),
270        "Solarized Shell" => Box::new(ShellTheme::new(theme, SOLARIZED)),
271        "OxoCarbon Shell" => Box::new(ShellTheme::new(theme, OXOCARBON)),
272        "Rust Shell" => Box::new(ShellTheme::new(theme, RUST)),
273        "VSCode Shell" => Box::new(ShellTheme::new(theme, VSCODE_DARK)),
274
275        _ => return None,
276    };
277
278    Some(theme)
279}
280
281/// Get a Palette by name.
282pub fn create_palette(name: &str) -> Option<Palette> {
283    match name {
284        "Imperial" => Some(IMPERIAL),
285        "Radium" => Some(RADIUM),
286        "Tundra" => Some(TUNDRA),
287        "Ocean" => Some(OCEAN),
288        "Monochrome" => Some(MONOCHROME),
289        "Black & White" => Some(BLACKWHITE),
290        "Base16" => Some(BASE16),
291        "Base16 Relax" => Some(BASE16_RELAX),
292        "Monekai" => Some(MONEKAI),
293        "Solarized" => Some(SOLARIZED),
294        "OxoCarbon" => Some(OXOCARBON),
295        "Rust" => Some(RUST),
296        "VSCode" => Some(VSCODE_DARK),
297        _ => return None,
298    }
299}
300
301const PALETTES: &[&str] = &[
302    "Imperial",
303    "Radium",
304    "Tundra",
305    "Ocean",
306    "Monochrome",
307    "Black & White",
308    "Base16",
309    "Base16 Relax",
310    "Monekai",
311    "Solarized",
312    "OxoCarbon",
313    "Rust",
314    "VSCode",
315];
316
317const THEMES: &[&str] = &[
318    "Imperial Dark",
319    "Radium Dark",
320    "Tundra Dark",
321    "Ocean Dark",
322    "Monochrome Dark",
323    "Black & White Dark",
324    "Base16 Dark",
325    "Base16 Relax Dark",
326    "Monekai Dark",
327    "Solarized Dark",
328    "OxoCarbon Dark",
329    "Rust Dark",
330    "VSCode Dark",
331    //
332    "Imperial Shell",
333    "Radium Shell",
334    "Tundra Shell",
335    "Ocean Shell",
336    "Monochrome Shell",
337    "Black & White Shell",
338    "Base16 Shell",
339    "Base16 Relax Shell",
340    "Monekai Shell",
341    "Solarized Shell",
342    "OxoCarbon Shell",
343    "Rust Shell",
344    "VSCode Shell",
345];
346
347pub fn salsa_themes() -> Vec<&'static str> {
348    Vec::from(THEMES)
349}
350
351/// All currently existing color palettes.
352pub fn salsa_palettes() -> Vec<&'static str> {
353    Vec::from(PALETTES)
354}