diff options
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 74 |
1 files changed, 50 insertions, 24 deletions
diff --git a/src/config.rs b/src/config.rs index 8d50d93..f5f2dd0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -118,30 +118,37 @@ impl Default for BibiConfig { file_prefix: None, pdf_path: None, }, - colors: Colors { - main_text_color: Color::Indexed(250), - highlight_text_color: Color::Indexed(254), - entry_color: Color::Indexed(36), - keyword_color: Color::Indexed(101), - info_color: Color::Indexed(99), - confirm_color: Color::Indexed(47), - warn_color: Color::Indexed(124), - bar_bg_color: Color::Indexed(235), - popup_bg_color: Color::Indexed(234), - selected_row_bg_color: Color::Indexed(237), - }, + colors: Self::dark_colors(), } } } impl BibiConfig { + pub fn new(args: &CLIArgs) -> Self { + Self { + general: General { + bibfiles: None, + editor: None, + pdf_opener: select_opener(), + url_opener: select_opener(), + file_prefix: None, + pdf_path: None, + }, + colors: if args.light_theme { + Self::light_colors() + } else { + Self::dark_colors() + }, + } + } + pub fn parse_config(args: &CLIArgs) -> Result<BibiConfig> { let cfg_file: BibiConfig = if args.cfg_path.as_ref().unwrap().is_file() { - Figment::from(Serialized::defaults(BibiConfig::default())) + Figment::from(Serialized::defaults(BibiConfig::new(args))) .merge(Toml::file(&args.cfg_path.as_ref().unwrap())) .extract()? } else { - BibiConfig::default() + BibiConfig::new(args) }; Ok(cfg_file) @@ -155,17 +162,36 @@ impl BibiConfig { } } + /// Standard color scheme for terminals with dark background (default) + pub fn dark_colors() -> Colors { + Colors { + main_text_color: Color::Indexed(250), + highlight_text_color: Color::Indexed(254), + entry_color: Color::Indexed(36), + keyword_color: Color::Indexed(101), + info_color: Color::Indexed(99), + confirm_color: Color::Indexed(47), + warn_color: Color::Indexed(124), + bar_bg_color: Color::Indexed(235), + popup_bg_color: Color::Indexed(234), + selected_row_bg_color: Color::Indexed(237), + } + } + /// Activates the default color scheme for light background terminals - pub fn light_colors(&mut self) { - self.colors.main_text_color = Color::Indexed(235); - self.colors.highlight_text_color = Color::Indexed(232); - self.colors.entry_color = Color::Indexed(23); - self.colors.keyword_color = Color::Indexed(58); - self.colors.info_color = Color::Indexed(57); - self.colors.bar_bg_color = Color::Indexed(144); - self.colors.popup_bg_color = Color::Indexed(187); - self.colors.confirm_color = Color::Indexed(22); - self.colors.selected_row_bg_color = Color::Indexed(107); + pub fn light_colors() -> Colors { + Colors { + main_text_color: Color::Indexed(235), + highlight_text_color: Color::Indexed(232), + entry_color: Color::Indexed(23), + keyword_color: Color::Indexed(58), + info_color: Color::Indexed(57), + bar_bg_color: Color::Indexed(144), + popup_bg_color: Color::Indexed(187), + confirm_color: Color::Indexed(22), + warn_color: Color::Indexed(124), + selected_row_bg_color: Color::Indexed(107), + } } /// Function which offers the user to create a default config |
