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