Skip to content

Commit b9eab12

Browse files
committed
Read background color from config
1 parent ad07d15 commit b9eab12

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/options/config/style.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use utils::{opt, set_colour, set_colour_list, set_style};
2828
use widgets::WidgetStyle;
2929

3030
use super::Config;
31-
use crate::options::{OptionError, OptionResult, args::BottomArgs};
31+
use crate::options::{OptionError, OptionResult, args::BottomArgs, config::style::utils::set_bg_colour};
3232

3333
#[derive(Clone, Debug, Deserialize, Serialize)]
3434
#[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))]
@@ -154,8 +154,6 @@ impl Styles {
154154
palette.set_styles_from_config(config_style)?;
155155
}
156156

157-
// For testing
158-
palette.bg_color_style = Style::default().bg(Color::White);
159157
Ok(palette)
160158
}
161159

@@ -213,6 +211,7 @@ impl Styles {
213211
set_style!(self.graph_legend_style, config.graphs, legend_text);
214212

215213
// General widget text.
214+
set_bg_colour!(self.bg_color_style, config.widgets, bg_color);
216215
set_style!(self.widget_title_style, config.widgets, widget_title);
217216
set_style!(self.text_style, config.widgets, text);
218217
set_style!(self.selected_text_style, config.widgets, selected_text);

src/options/config/style/utils.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,27 @@ macro_rules! set_colour {
233233
};
234234
}
235235

236+
macro_rules! set_bg_colour {
237+
($palette_field:expr, $config_location:expr, $field:tt) => {
238+
if let Some(colour) = &(opt!($config_location.as_ref()?.$field.as_ref())) {
239+
$palette_field = $palette_field.bg(
240+
crate::options::config::style::utils::str_to_colour(&colour.0).map_err(|err| {
241+
match stringify!($config_location).split_once(".") {
242+
Some((_, loc)) => crate::options::OptionError::config(format!(
243+
"Please update 'styles.{loc}.{}' in your config file. {err}",
244+
stringify!($field)
245+
)),
246+
None => crate::options::OptionError::config(format!(
247+
"Please update 'styles.{}' in your config file. {err}",
248+
stringify!($field)
249+
)),
250+
}
251+
})?,
252+
);
253+
}
254+
};
255+
}
256+
236257
/// Set `palette_field` to the value in `config_location` for `field`.
237258
macro_rules! set_colour_list {
238259
($palette_field:expr, $config_location:expr, $field:tt) => {
@@ -259,6 +280,7 @@ macro_rules! set_colour_list {
259280
}
260281

261282
pub(super) use opt;
283+
pub(super) use set_bg_colour;
262284
pub(super) use set_colour;
263285
pub(super) use set_colour_list;
264286
pub(super) use set_style;

0 commit comments

Comments
 (0)