rat-theme3 2.6.1

dark theme and color-schemes
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
use crate::{Contrast, Palette, SalsaTheme};
use rat_widget::button::ButtonStyle;
use rat_widget::calendar::CalendarStyle;
use rat_widget::checkbox::CheckboxStyle;
use rat_widget::choice::ChoiceStyle;
use rat_widget::clipper::ClipperStyle;
use rat_widget::file_dialog::FileDialogStyle;
use rat_widget::form::FormStyle;
use rat_widget::line_number::LineNumberStyle;
use rat_widget::list::ListStyle;
use rat_widget::menu::MenuStyle;
use rat_widget::msgdialog::MsgDialogStyle;
use rat_widget::paragraph::ParagraphStyle;
use rat_widget::popup::PopupStyle;
use rat_widget::radio::{RadioLayout, RadioStyle};
use rat_widget::scrolled::ScrollStyle;
use rat_widget::shadow::{ShadowDirection, ShadowStyle};
use rat_widget::slider::SliderStyle;
use rat_widget::splitter::SplitStyle;
use rat_widget::statusline::StatusLineStyle;
use rat_widget::tabbed::TabbedStyle;
use rat_widget::table::TableStyle;
use rat_widget::text::TextStyle;
use rat_widget::view::ViewStyle;
use ratatui_core::layout::Alignment;
use ratatui_core::style::{Color, Style};
use ratatui_widgets::block::Block;
use ratatui_widgets::borders::Borders;
use std::borrow::Cow;
use std::time::Duration;

/// A sample theme for shell usage.
#[derive(Debug, Clone)]
pub struct ShellTheme {
    p: Palette,
    name: Box<str>,
}

impl ShellTheme {
    pub fn new(name: &str, p: Palette) -> Self {
        Self {
            p,
            name: Box::from(name),
        }
    }

    /// Create a style with only a text foreground color
    fn fg_style(&self, color: Color) -> Style {
        Style::new().fg(color)
    }
}

impl SalsaTheme for ShellTheme {
    fn name(&self) -> &str {
        &self.name
    }

    fn palette(&self) -> &Palette {
        &self.p
    }

    /// Create a style from the given white shade.
    /// n is `0..8`
    fn white(&self, n: usize) -> Style {
        self.p.white(n, Contrast::Normal)
    }

    /// Create a style from the given black shade.
    /// n is `0..8`
    fn black(&self, n: usize) -> Style {
        self.p.black(n, Contrast::Normal)
    }

    /// Create a style from the given gray shade.
    /// n is `0..8`
    fn gray(&self, n: usize) -> Style {
        self.p.gray(n, Contrast::Normal)
    }

    /// Create a style from the given red shade.
    /// n is `0..8`
    fn red(&self, n: usize) -> Style {
        self.p.red(n, Contrast::Normal)
    }

    /// Create a style from the given orange shade.
    /// n is `0..8`
    fn orange(&self, n: usize) -> Style {
        self.p.orange(n, Contrast::Normal)
    }

    /// Create a style from the given yellow shade.
    /// n is `0..8`
    fn yellow(&self, n: usize) -> Style {
        self.p.yellow(n, Contrast::Normal)
    }

    /// Create a style from the given limegreen shade.
    /// n is `0..8`
    fn limegreen(&self, n: usize) -> Style {
        self.p.limegreen(n, Contrast::Normal)
    }

    /// Create a style from the given green shade.
    /// n is `0..8`
    fn green(&self, n: usize) -> Style {
        self.p.green(n, Contrast::Normal)
    }

    /// Create a style from the given bluegreen shade.
    /// n is `0..8`
    fn bluegreen(&self, n: usize) -> Style {
        self.p.bluegreen(n, Contrast::Normal)
    }

    /// Create a style from the given cyan shade.
    /// n is `0..8`
    fn cyan(&self, n: usize) -> Style {
        self.p.cyan(n, Contrast::Normal)
    }

    /// Create a style from the given blue shade.
    /// n is `0..8`
    fn blue(&self, n: usize) -> Style {
        self.p.blue(n, Contrast::Normal)
    }

    /// Create a style from the given deepblue shade.
    /// n is `0..8`
    fn deepblue(&self, n: usize) -> Style {
        self.p.deepblue(n, Contrast::Normal)
    }

    /// Create a style from the given purple shade.
    /// n is `0..8`
    fn purple(&self, n: usize) -> Style {
        self.p.purple(n, Contrast::Normal)
    }

    /// Create a style from the given magenta shade.
    /// n is `0..8`
    fn magenta(&self, n: usize) -> Style {
        self.p.magenta(n, Contrast::Normal)
    }

    /// Create a style from the given redpink shade.
    /// n is `0..8`
    fn redpink(&self, n: usize) -> Style {
        self.p.redpink(n, Contrast::Normal)
    }

    /// Create a style from the given primary shade.
    /// n is `0..8`
    fn primary(&self, n: usize) -> Style {
        self.p.primary(n, Contrast::Normal)
    }

    /// Create a style from the given secondary shade.
    /// n is `0..8`
    fn secondary(&self, n: usize) -> Style {
        self.p.secondary(n, Contrast::Normal)
    }

    fn focus(&self) -> Style {
        self.p.high_contrast(self.p.primary[Palette::BRIGHT_2])
    }

    fn select(&self) -> Style {
        self.p.high_contrast(self.p.secondary[Palette::BRIGHT_2])
    }

    fn text_input(&self) -> Style {
        self.p.normal_contrast(self.p.gray[Palette::BRIGHT_0])
    }

    fn text_focus(&self) -> Style {
        self.p.normal_contrast(self.p.gray[Palette::BRIGHT_3])
    }

    fn text_select(&self) -> Style {
        self.p.normal_contrast(self.p.secondary[Palette::BRIGHT_0])
    }

    /// Container base
    fn container_base(&self) -> Style {
        Default::default()
    }

    /// Container border
    fn container_border(&self) -> Style {
        Default::default()
    }

    /// Container arrows
    fn container_arrow(&self) -> Style {
        Default::default()
    }

    /// Background for popups.
    fn popup_base(&self) -> Style {
        self.p
            .style(self.p.gray[Palette::BRIGHT_0], Contrast::Normal)
    }

    /// Dialog arrows
    fn popup_border(&self) -> Style {
        self.popup_base().fg(self.p.gray[Palette::BRIGHT_0])
    }

    /// Dialog arrows
    fn popup_arrow(&self) -> Style {
        self.popup_base().fg(self.p.gray[Palette::BRIGHT_0])
    }

    /// Background for dialogs.
    fn dialog_base(&self) -> Style {
        self.p
            .style(self.p.gray[Palette::BRIGHT_1], Contrast::Normal)
    }

    /// Dialog arrows
    fn dialog_border(&self) -> Style {
        self.dialog_base().fg(self.p.white[Palette::BRIGHT_0])
    }

    /// Dialog arrows
    fn dialog_arrow(&self) -> Style {
        self.dialog_base().fg(self.p.white[Palette::BRIGHT_0])
    }

    /// Style for the status line.
    fn status_base(&self) -> Style {
        Default::default()
    }

    /// Base style for buttons.
    fn button_base(&self) -> Style {
        self.p
            .style(self.p.gray[Palette::BRIGHT_2], Contrast::Normal)
    }

    /// Armed style for buttons.
    fn button_armed(&self) -> Style {
        self.p
            .style(self.p.secondary[Palette::BRIGHT_0], Contrast::Normal)
    }

    /// Complete MonthStyle.
    fn month_style(&self) -> CalendarStyle {
        CalendarStyle {
            style: Default::default(),
            title: None,
            weeknum: Some(Style::new().fg(self.p.limegreen[Palette::BRIGHT_0])),
            weekday: Some(Style::new().fg(self.p.limegreen[Palette::BRIGHT_0])),
            day: None,
            select: Some(self.select()),
            focus: Some(self.focus()),
            ..CalendarStyle::default()
        }
    }

    /// Style for shadows.
    fn shadow_style(&self) -> ShadowStyle {
        ShadowStyle {
            style: Style::new().bg(self.p.black[Palette::DARK_0]),
            dir: ShadowDirection::BottomRight,
            ..ShadowStyle::default()
        }
    }

    /// Style for LineNumbers.
    fn line_nr_style(&self) -> LineNumberStyle {
        LineNumberStyle {
            style: self.container_base(),
            cursor: Some(self.text_select()),
            ..LineNumberStyle::default()
        }
    }

    /// Complete TextAreaStyle
    fn textarea_style(&self) -> TextStyle {
        TextStyle {
            style: self.text_input(),
            select: Some(self.text_select()),
            scroll: Some(self.scroll_style()),
            border_style: Some(self.container_border()),
            ..TextStyle::default()
        }
    }

    /// Complete TextInputStyle
    fn text_style(&self) -> TextStyle {
        TextStyle {
            style: self.text_input(),
            focus: Some(self.text_focus()),
            select: Some(self.text_select()),
            invalid: Some(self.fg_style(self.p.red[Palette::BRIGHT_3])),
            ..TextStyle::default()
        }
    }

    /// Text-label style.
    fn label_style(&self) -> Style {
        self.container_base()
    }

    fn paragraph_style(&self) -> ParagraphStyle {
        ParagraphStyle {
            style: self.container_base(),
            focus: Some(self.focus()),
            scroll: Some(self.scroll_style()),
            ..Default::default()
        }
    }

    fn choice_style(&self) -> ChoiceStyle {
        ChoiceStyle {
            style: self.text_input(),
            select: Some(self.text_select()),
            focus: Some(self.text_focus()),
            popup: PopupStyle::default(),
            popup_style: Some(self.popup_base()),
            popup_border: Some(self.popup_border()),
            popup_scroll: Some(self.popup_scroll_style()),
            popup_block: Some(
                Block::bordered()
                    .borders(Borders::LEFT)
                    .border_style(self.popup_border()),
            ),
            ..Default::default()
        }
    }

    fn radio_style(&self) -> RadioStyle {
        RadioStyle {
            layout: Some(RadioLayout::Stacked),
            style: self.text_input(),
            focus: Some(self.text_focus()),
            ..Default::default()
        }
    }

    /// Complete CheckboxStyle
    fn checkbox_style(&self) -> CheckboxStyle {
        CheckboxStyle {
            style: self.text_input(),
            focus: Some(self.text_focus()),
            ..Default::default()
        }
    }

    /// Slider Style
    fn slider_style(&self) -> SliderStyle {
        SliderStyle {
            style: self.text_input(),
            bounds: Some(self.gray(2)),
            knob: Some(self.select()),
            focus: Some(self.focus()),
            text_align: Some(Alignment::Center),
            ..Default::default()
        }
    }

    /// Complete MenuStyle
    fn menu_style(&self) -> MenuStyle {
        MenuStyle {
            style: self.status_base(),
            title: Some(self.fg_style(self.p.yellow[Palette::BRIGHT_2])),
            focus: Some(self.focus()),
            right: Some(self.fg_style(self.p.green[Palette::BRIGHT_3])),
            disabled: Some(self.fg_style(self.p.gray[Palette::BRIGHT_2])),
            highlight: Some(Style::default().underlined()),
            popup_block: Some(Block::bordered().style(self.popup_border())),
            popup_focus: Some(self.focus()),
            popup_right: Some(self.fg_style(self.p.green[Palette::BRIGHT_3])),
            popup_disabled: Some(self.fg_style(self.p.gray[Palette::BRIGHT_2])),
            popup_highlight: Some(Style::default().underlined()),
            ..Default::default()
        }
    }

    /// Complete ButtonStyle
    fn button_style(&self) -> ButtonStyle {
        ButtonStyle {
            style: self.button_base(),
            focus: Some(self.focus()),
            armed: Some(self.select()),
            armed_delay: Some(Duration::from_millis(50)),
            ..Default::default()
        }
    }

    /// Complete TableStyle
    fn table_style(&self) -> TableStyle {
        TableStyle {
            style: self.container_base(),
            select_row: Some(self.select()),
            show_row_focus: true,
            focus_style: Some(self.focus()),
            border_style: Some(self.container_border()),
            scroll: Some(self.scroll_style()),
            header: Some(self.fg_style(self.p.green[Palette::BRIGHT_2])),
            footer: Some(self.fg_style(self.p.green[Palette::BRIGHT_2])),
            ..Default::default()
        }
    }

    /// Complete ListStyle
    fn list_style(&self) -> ListStyle {
        ListStyle {
            style: self.container_base(),
            select: Some(self.select()),
            focus: Some(self.focus()),
            scroll: Some(self.scroll_style()),
            ..Default::default()
        }
    }

    /// Scroll style
    fn scroll_style(&self) -> ScrollStyle {
        ScrollStyle {
            thumb_style: Some(self.container_border()),
            track_style: Some(self.container_border()),
            min_style: Some(self.container_border()),
            begin_style: Some(self.container_arrow()),
            end_style: Some(self.container_arrow()),
            ..Default::default()
        }
    }

    /// Popup scroll style
    fn popup_scroll_style(&self) -> ScrollStyle {
        ScrollStyle {
            thumb_style: Some(self.popup_border()),
            track_style: Some(self.popup_border()),
            min_style: Some(self.popup_border()),
            begin_style: Some(self.popup_arrow()),
            end_style: Some(self.popup_arrow()),
            ..Default::default()
        }
    }

    /// Dialog scroll style
    fn dialog_scroll_style(&self) -> ScrollStyle {
        ScrollStyle {
            thumb_style: Some(self.dialog_border()),
            track_style: Some(self.dialog_border()),
            min_style: Some(self.dialog_border()),
            begin_style: Some(self.dialog_arrow()),
            end_style: Some(self.dialog_arrow()),
            ..Default::default()
        }
    }

    /// Split style
    fn split_style(&self) -> SplitStyle {
        SplitStyle {
            style: self.container_border(),
            arrow_style: Some(self.container_arrow()),
            drag_style: Some(self.focus()),
            ..Default::default()
        }
    }

    /// View style
    fn view_style(&self) -> ViewStyle {
        ViewStyle {
            scroll: Some(self.scroll_style()),
            ..Default::default()
        }
    }

    /// Tabbed style
    fn tabbed_style(&self) -> TabbedStyle {
        TabbedStyle {
            style: self.container_base(),
            tab: Some(self.button_base()),
            select: Some(self.button_armed()),
            focus: Some(self.focus()),
            ..Default::default()
        }
    }

    /// Complete StatusLineStyle for a StatusLine with 3 indicator fields.
    fn statusline_style(&self) -> Vec<Style> {
        vec![
            self.status_base(),
            self.fg_style(self.p.blue[Palette::BRIGHT_2]),
            self.fg_style(self.p.blue[Palette::BRIGHT_2]),
            self.fg_style(self.p.blue[Palette::BRIGHT_2]),
        ]
    }

    /// StatusLineStyle for a StatusLine with 3 indicator fields.
    fn statusline_style_ext(&self) -> StatusLineStyle {
        StatusLineStyle {
            sep: Some(Cow::Borrowed("|")),
            styles: vec![
                self.status_base(),
                self.status_base().fg(self.p.blue[Palette::BRIGHT_2]),
                self.status_base().fg(self.p.blue[Palette::BRIGHT_2]),
                self.status_base().fg(self.p.blue[Palette::BRIGHT_2]),
            ],
            ..Default::default()
        }
    }

    /// FileDialog style.
    fn file_dialog_style(&self) -> FileDialogStyle {
        FileDialogStyle {
            style: self.dialog_base(),
            list: Some(self.list_style()),
            roots: Some(ListStyle {
                style: self.dialog_base(),
                ..self.list_style()
            }),
            text: Some(self.text_style()),
            button: Some(self.button_style()),
            block: Some(Block::bordered()),
            ..Default::default()
        }
    }

    /// Complete MsgDialogStyle.
    fn msg_dialog_style(&self) -> MsgDialogStyle {
        MsgDialogStyle {
            style: self.dialog_base(),
            button: Some(self.button_style()),
            ..Default::default()
        }
    }

    /// Form style.
    fn form_style(&self) -> FormStyle {
        FormStyle {
            style: self.container_base(),
            navigation: Some(self.container_arrow()),
            block: Some(
                Block::default()
                    .borders(Borders::TOP)
                    .border_style(self.container_border()),
            ),
            ..Default::default()
        }
    }

    /// Clipper style.
    fn clipper_style(&self) -> ClipperStyle {
        ClipperStyle {
            style: self.container_base(),
            scroll: Some(self.scroll_style()),
            ..Default::default()
        }
    }

    fn textview_style(&self) -> TextStyle {
        TextStyle {
            style: self.container_base(),
            focus: Some(self.container_base()),
            select: Some(self.text_select()),
            scroll: Some(self.scroll_style()),
            border_style: Some(self.container_border()),
            ..TextStyle::default()
        }
    }
}