runa_tui/config/
display.rs

1use serde::Deserialize;
2
3#[derive(Deserialize, Debug)]
4pub struct LayoutConfig {
5    parent: u16,
6    main: u16,
7    preview: u16,
8}
9
10impl LayoutConfig {
11    fn parent_ratio(&self) -> u16 {
12        self.parent
13    }
14
15    fn main_ratio(&self) -> u16 {
16        self.main
17    }
18
19    fn preview_ratio(&self) -> u16 {
20        self.preview
21    }
22}
23
24#[derive(Deserialize, Debug)]
25#[serde(default)]
26pub struct Display {
27    selection_marker: bool,
28    dir_marker: bool,
29    borders: BorderStyle,
30    titles: bool,
31    separators: bool,
32    parent: bool,
33    preview: bool,
34    layout: LayoutConfig,
35    preview_underline: bool,
36    preview_underline_color: bool,
37    entry_padding: u8,
38    scroll_padding: usize,
39}
40
41#[derive(Deserialize, Debug, Clone, PartialEq)]
42#[serde(rename_all = "lowercase")]
43pub enum BorderStyle {
44    None,
45    Unified,
46    Split,
47}
48
49impl Display {
50    pub fn selection_marker(&self) -> bool {
51        self.selection_marker
52    }
53
54    pub fn dir_marker(&self) -> bool {
55        self.dir_marker
56    }
57
58    pub fn is_unified(&self) -> bool {
59        matches!(self.borders, BorderStyle::Unified)
60    }
61
62    pub fn is_split(&self) -> bool {
63        matches!(self.borders, BorderStyle::Split)
64    }
65
66    pub fn titles(&self) -> bool {
67        self.titles
68    }
69
70    pub fn separators(&self) -> bool {
71        self.separators
72    }
73
74    pub fn parent(&self) -> bool {
75        self.parent
76    }
77
78    pub fn preview(&self) -> bool {
79        self.preview
80    }
81
82    pub fn parent_ratio(&self) -> u16 {
83        self.layout.parent_ratio()
84    }
85
86    pub fn main_ratio(&self) -> u16 {
87        self.layout.main_ratio()
88    }
89
90    pub fn preview_ratio(&self) -> u16 {
91        self.layout.preview_ratio()
92    }
93
94    pub fn preview_underline(&self) -> bool {
95        self.preview_underline
96    }
97
98    pub fn preview_underline_color(&self) -> bool {
99        self.preview_underline_color
100    }
101
102    pub fn entry_padding(&self) -> u8 {
103        self.entry_padding
104    }
105
106    pub fn scroll_padding(&self) -> usize {
107        self.scroll_padding
108    }
109
110    pub fn padding_str(&self) -> &'static str {
111        // ASCII whitespaces
112        match self.entry_padding {
113            0 => "",
114            1 => " ",
115            2 => "  ",
116            3 => "   ",
117            _ => "    ",
118        }
119    }
120}
121
122impl Default for Display {
123    fn default() -> Self {
124        Display {
125            selection_marker: true,
126            dir_marker: true,
127            borders: BorderStyle::Split,
128            titles: false,
129            separators: true,
130            parent: true,
131            preview: true,
132            layout: LayoutConfig {
133                parent: 20,
134                main: 40,
135                preview: 40,
136            },
137            preview_underline: true,
138            preview_underline_color: false,
139            entry_padding: 1,
140            scroll_padding: 5,
141        }
142    }
143}