diff options
| author | lukeflo | 2025-06-08 20:57:49 +0200 |
|---|---|---|
| committer | lukeflo | 2025-06-08 20:57:49 +0200 |
| commit | 9653a63d8ad5a6cc2b5edaab971ece69440e5a52 (patch) | |
| tree | 62b85d5c30bc6e187971f4839840a3ea3e4cfa39 | |
| parent | 14e1613f81e5b35aef4f3f9627802e86f1716c64 (diff) | |
| download | bibiman-9653a63d8ad5a6cc2b5edaab971ece69440e5a52.tar.gz bibiman-9653a63d8ad5a6cc2b5edaab971ece69440e5a52.zip | |
Fix: light terminal flag, rm obsolete color.rs file
| -rw-r--r-- | src/config.rs | 74 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/tui.rs | 1 | ||||
| -rw-r--r-- | src/tui/colors.rs | 121 | ||||
| -rw-r--r-- | src/tui/ui.rs | 10 |
5 files changed, 57 insertions, 151 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 diff --git a/src/main.rs b/src/main.rs index add1f2e..c956d7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,7 @@ async fn main() -> Result<()> { let mut cfg = if parsed_args.cfg_path.is_some() { BibiConfig::parse_config(&parsed_args)? } else { - BibiConfig::default() + BibiConfig::new(&parsed_args) }; cfg.cli_overwrite(&parsed_args); @@ -15,7 +15,6 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. ///// -pub mod colors; pub mod commands; pub mod popup; pub mod ui; diff --git a/src/tui/colors.rs b/src/tui/colors.rs deleted file mode 100644 index 1eb75ef..0000000 --- a/src/tui/colors.rs +++ /dev/null @@ -1,121 +0,0 @@ -// bibiman - a TUI for managing BibLaTeX databases -// Copyright (C) 2024 lukeflo -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. -///// - -#[derive(Debug, Clone)] -pub enum AppColorScheme { - Light, - Dark, -} - -#[derive(Debug, Clone)] -pub struct AppColors { - pub main_text_color: u8, - pub highlight_text_color: u8, - pub entry_color: u8, - pub keyword_color: u8, - pub info_color: u8, - pub confirm_color: u8, - pub warn_color: u8, - pub bar_bg_color: u8, - pub popup_bg_color: u8, - pub selected_row_bg_color: u8, - pub color_scheme: AppColorScheme, -} - -impl Default for AppColors { - fn default() -> Self { - Self { - main_text_color: 250, - highlight_text_color: 254, - entry_color: 36, - keyword_color: 101, - info_color: 99, - confirm_color: 47, - warn_color: 124, - bar_bg_color: 235, - popup_bg_color: 234, - selected_row_bg_color: 237, - color_scheme: AppColorScheme::Dark, - } - } -} - -impl AppColors { - pub fn new() -> Self { - Self::default() - } - - pub fn main_text_color(&mut self, index: u8) { - self.main_text_color = index - } - - pub fn highlight_text_color(&mut self, index: u8) { - self.highlight_text_color = index - } - - pub fn entry_color(&mut self, index: u8) { - self.entry_color = index - } - - pub fn keyword_color(&mut self, index: u8) { - self.keyword_color = index - } - - pub fn info_color(&mut self, index: u8) { - self.info_color = index - } - - pub fn confirm_color(&mut self, index: u8) { - self.confirm_color = index - } - - pub fn warn_color(&mut self, index: u8) { - self.warn_color = index - } - - pub fn bar_bg_color(&mut self, index: u8) { - self.bar_bg_color = index - } - - pub fn popup_bg_color(&mut self, index: u8) { - self.popup_bg_color = index - } - - pub fn selected_row_bg_color(&mut self, index: u8) { - self.selected_row_bg_color = index - } - - pub fn toggle_color_scheme(&mut self) { - match self.color_scheme { - AppColorScheme::Light => self.color_scheme = AppColorScheme::Dark, - AppColorScheme::Dark => self.color_scheme = AppColorScheme::Light, - } - } - - /// Activates the default color scheme for light background terminals - pub fn light_colors(&mut self) { - self.main_text_color(235); - self.highlight_text_color(232); - self.entry_color(23); - self.keyword_color(58); - self.info_color(57); - self.bar_bg_color(144); - self.popup_bg_color(187); - self.confirm_color(22); - self.selected_row_bg_color(107) - } -} diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 2126135..7a121bf 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -420,9 +420,7 @@ pub fn render_file_info(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect .border_style(if let CurrentArea::EntryArea = app.bibiman.current_area { Style::new().fg(cfg.colors.highlight_text_color) } else { - Style::new() - .fg(cfg.colors.entry_color) - .add_modifier(Modifier::BOLD) + Style::new().fg(cfg.colors.main_text_color) }); frame.render_widget(block, rect); @@ -708,7 +706,11 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec // args.colors.highlight_text_color, // 20, // )), - Style::new().fg(cfg.colors.highlight_text_color), + Style::new().fg(if let CurrentArea::EntryArea = app.bibiman.current_area { + cfg.colors.highlight_text_color + } else { + cfg.colors.main_text_color + }), ) .height(1) }); |
