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
|
use tui::style::{Color, Modifier, Style};
use colour_utils::*;
use crate::{constants::*, utils::error};
mod colour_utils;
pub struct CanvasColours {
pub currently_selected_text_colour: Color,
pub currently_selected_bg_colour: Color,
pub currently_selected_text_style: Style,
pub table_header_style: Style,
pub ram_style: Style,
pub swap_style: Style,
pub rx_style: Style,
pub tx_style: Style,
pub total_rx_style: Style,
pub total_tx_style: Style,
pub all_colour_style: Style,
pub avg_colour_style: Style,
pub cpu_colour_styles: Vec<Style>,
pub border_style: Style,
pub highlighted_border_style: Style,
pub text_style: Style,
pub widget_title_style: Style,
pub graph_style: Style,
// Full, Medium, Low
pub battery_bar_styles: Vec<Style>,
pub invalid_query_style: Style,
}
impl Default for CanvasColours {
fn default() -> Self {
let text_colour = Color::Gray;
CanvasColours {
currently_selected_text_colour: Color::Black,
currently_selected_bg_colour: Color::Cyan,
currently_selected_text_style: Style::default()
.fg(Color::Black)
.bg(STANDARD_HIGHLIGHT_COLOUR),
table_header_style: Style::default().fg(STANDARD_HIGHLIGHT_COLOUR),
ram_style: Style::default().fg(STANDARD_FIRST_COLOUR),
swap_style: Style::default().fg(STANDARD_SECOND_COLOUR),
rx_style: Style::default().fg(STANDARD_FIRST_COLOUR),
tx_style: Style::default().fg(STANDARD_SECOND_COLOUR),
total_rx_style: Style::default().fg(STANDARD_THIRD_COLOUR),
total_tx_style: Style::default().fg(STANDARD_FOURTH_COLOUR),
all_colour_style: Style::default().fg(ALL_COLOUR),
avg_colour_style: Style::default().fg(AVG_COLOUR),
cpu_colour_styles: Vec::new(),
border_style: Style::default().fg(text_colour),
highlighted_border_style: Style::default().fg(STANDARD_HIGHLIGHT_COLOUR),
text_style: Style::default().fg(text_colour),
widget_title_style: Style::default().fg(text_colour),
graph_style: Style::default().fg(text_colour),
battery_bar_styles: vec![
Style::default().fg(Color::Red),
Style::default().fg(Color::Yellow),
Style::default().fg(Color::Yellow),
Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
],
invalid_query_style: tui::style::Style::default().fg(tui::style::Color::Red),
}
}
}
impl CanvasColours {
pub fn set_text_colour(&mut self, colour: &str) -> error::Result<()> {
self.text_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_border_colour(&mut self, colour: &str) -> error::Result<()> {
self.border_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_highlighted_border_colour(&mut self, colour: &str) -> error::Result<()> {
self.highlighted_border_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_table_header_colour(&mut self, colour: &str) -> error::Result<()> {
self.table_header_style = get_style_from_config(colour)?.modifier(Modifier::BOLD);
Ok(())
}
pub fn set_ram_colour(&mut self, colour: &str) -> error::Result<()> {
self.ram_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_swap_colour(&mut self, colour: &str) -> error::Result<()> {
self.swap_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_rx_colour(&mut self, colour: &str) -> error::Result<()> {
self.rx_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_tx_colour(&mut self, colour: &str) -> error::Result<()> {
self.tx_style = get_style_from_config(colour)?;
Ok(())
}
// pub fn set_rx_total_colour(&mut self, colour: &str) -> error::Result<()> {
// self.total_rx_style = get_style_from_config(colour)?;
// Ok(())
// }
// pub fn set_tx_total_colour(&mut self, colour: &str) -> error::Result<()> {
// self.total_tx_style = get_style_from_config(colour)?;
// Ok(())
// }
pub fn set_avg_cpu_colour(&mut self, colour: &str) -> error::Result<()> {
self.avg_colour_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_all_cpu_colour(&mut self, colour: &str) -> error::Result<()> {
self.all_colour_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_cpu_colours(&mut self, colours: &[String]) -> error::Result<()> {
let max_amount = std::cmp::min(colours.len(), NUM_COLOURS);
for (itx, colour) in colours.iter().enumerate() {
if itx >= max_amount {
break;
}
self.cpu_colour_styles.push(get_style_from_config(colour)?);
}
Ok(())
}
pub fn generate_remaining_cpu_colours(&mut self) {
let remaining_num_colours = NUM_COLOURS.saturating_sub(self.cpu_colour_styles.len());
self.cpu_colour_styles
.extend(gen_n_styles(remaining_num_colours));
}
pub fn set_scroll_entry_text_color(&mut self, colour: &str) -> error::Result<()> {
self.currently_selected_text_colour = get_colour_from_config(colour)?;
self.currently_selected_text_style = Style::default()
.fg(self.currently_selected_text_colour)
.bg(self.currently_selected_bg_colour);
Ok(())
}
pub fn set_scroll_entry_bg_color(&mut self, colour: &str) -> error::Result<()> {
self.currently_selected_bg_colour = get_colour_from_config(colour)?;
self.currently_selected_text_style = Style::default()
.fg(self.currently_selected_text_colour)
.bg(self.currently_selected_bg_colour);
Ok(())
}
pub fn set_widget_title_colour(&mut self, colour: &str) -> error::Result<()> {
self.widget_title_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_graph_colour(&mut self, colour: &str) -> error::Result<()> {
self.graph_style = get_style_from_config(colour)?;
Ok(())
}
pub fn set_battery_colours(&mut self, colours: &[String]) -> error::Result<()> {
if colours.is_empty() {
Err(error::BottomError::ConfigError(
"invalid colour config: battery colour list must have at least one colour!"
.to_string(),
))
} else {
let generated_colours: Result<Vec<_>, _> = colours
.iter()
.map(|colour| get_style_from_config(colour))
.collect();
self.battery_bar_styles = generated_colours?;
Ok(())
}
}
}
|