diff options
| author | lukeflo | 2024-11-28 17:56:04 +0100 |
|---|---|---|
| committer | lukeflo | 2024-11-28 17:56:04 +0100 |
| commit | bb6f07dfb252eb74766051a750b9ae2696069bd5 (patch) | |
| tree | af32e78e59f5208933ea77cbebc94518740483bc | |
| parent | 87eefb8248ccf71eb43fd817f18a18af9f5c9083 (diff) | |
| download | bibiman-bb6f07dfb252eb74766051a750b9ae2696069bd5.tar.gz bibiman-bb6f07dfb252eb74766051a750b9ae2696069bd5.zip | |
color struct impl, integrated with cliargs
| -rw-r--r-- | src/cliargs.rs | 4 | ||||
| -rw-r--r-- | src/main.rs | 14 | ||||
| -rw-r--r-- | src/tui.rs | 1 | ||||
| -rw-r--r-- | src/tui/colors.rs | 72 | ||||
| -rw-r--r-- | src/tui/ui.rs | 74 |
5 files changed, 121 insertions, 44 deletions
diff --git a/src/cliargs.rs b/src/cliargs.rs index 3ac8616..d6c27c4 100644 --- a/src/cliargs.rs +++ b/src/cliargs.rs @@ -22,6 +22,8 @@ use std::env; use std::path::PathBuf; use walkdir::WalkDir; +use crate::tui::colors::AppColors; + // struct for CLIArgs #[derive(Debug, Default, Clone)] pub struct CLIArgs { @@ -29,6 +31,7 @@ pub struct CLIArgs { pub versionarg: bool, pub pos_args: Vec<PathBuf>, pub files: Vec<PathBuf>, + pub colors: AppColors, } impl CLIArgs { @@ -40,6 +43,7 @@ impl CLIArgs { match arg { Short('h') | Long("help") => args.helparg = true, Short('v') | Long("version") => args.versionarg = true, + Long("light-theme") => AppColors::light_colors(&mut args.colors), // Value(pos_arg) => parse_files(&mut args, pos_arg), Value(pos_arg) => args.pos_args.push(pos_arg.into()), _ => return Err(arg.unexpected()), diff --git a/src/main.rs b/src/main.rs index 79041fe..9140c7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,13 +27,13 @@ pub mod errorsetup; pub mod tui; // Color indices -const MAIN_ENTRY_COLOR_INDEX: u8 = 36; -const MAIN_KEYWORD_COLOR_INDEX: u8 = 101; -const MAIN_INFO_COLOR_INDEX: u8 = 99; -const CONFIRM_COLOR_INDEX: u8 = 47; -const WARN_COLOR_INDEX: u8 = 124; -const TEXT_HIGHLIGHT_COLOR_INDEX: u8 = 254; -const TEXT_FG_COLOR_INDEX: u8 = 250; +static MAIN_ENTRY_COLOR_INDEX: u8 = 36; +static MAIN_KEYWORD_COLOR_INDEX: u8 = 101; +static MAIN_INFO_COLOR_INDEX: u8 = 99; +static CONFIRM_COLOR_INDEX: u8 = 47; +static WARN_COLOR_INDEX: u8 = 124; +static TEXT_HIGHLIGHT_COLOR_INDEX: u8 = 254; +static TEXT_FG_COLOR_INDEX: u8 = 250; #[tokio::main] async fn main() -> Result<()> { @@ -15,6 +15,7 @@ // 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 new file mode 100644 index 0000000..cbb0617 --- /dev/null +++ b/src/tui/colors.rs @@ -0,0 +1,72 @@ +// 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 struct AppColors { + main_text_color: u8, + highlight_text_color: u8, + entry_color: u8, + keyword_color: u8, + info_color: u8, +} + +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, + } + } +} + +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 + } + + /// 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) + } +} diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 45dfbcc..7381f7a 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -43,73 +43,73 @@ use ratatui::{ use walkdir::WalkDir; // Text colors -const TEXT_FG_COLOR: Color = Color::Indexed(TEXT_FG_COLOR_INDEX); -const TEXT_BRIGHT_FG_COLOR: Color = Color::Indexed(TEXT_HIGHLIGHT_COLOR_INDEX); -const ENTRY_COLOR: Color = Color::Indexed(MAIN_ENTRY_COLOR_INDEX); -const KEYWORD_COLOR: Color = Color::Indexed(MAIN_KEYWORD_COLOR_INDEX); -const CONFIRM_COLOR: Color = Color::Indexed(CONFIRM_COLOR_INDEX); -const WARN_COLOR: Color = Color::Indexed(WARN_COLOR_INDEX); -const INFO_COLOR: Color = Color::Indexed(MAIN_INFO_COLOR_INDEX); +static TEXT_FG_COLOR: Color = Color::Indexed(TEXT_FG_COLOR_INDEX); +static TEXT_BRIGHT_FG_COLOR: Color = Color::Indexed(TEXT_HIGHLIGHT_COLOR_INDEX); +static ENTRY_COLOR: Color = Color::Indexed(MAIN_ENTRY_COLOR_INDEX); +static KEYWORD_COLOR: Color = Color::Indexed(MAIN_KEYWORD_COLOR_INDEX); +static CONFIRM_COLOR: Color = Color::Indexed(CONFIRM_COLOR_INDEX); +static WARN_COLOR: Color = Color::Indexed(WARN_COLOR_INDEX); +static INFO_COLOR: Color = Color::Indexed(MAIN_INFO_COLOR_INDEX); // Background colors -const HEADER_FOOTER_BG: Color = Color::Indexed(235); -const POPUP_BG: Color = Color::Indexed(234); +static HEADER_FOOTER_BG: Color = Color::Indexed(235); +static POPUP_BG: Color = Color::Indexed(234); // Box styles // Keyword Box -const KEYWORD_BOX_SELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_BRIGHT_FG_COLOR); -const KEYWORD_BOX_SELECTED_TITLE_STYLE: Style = +static KEYWORD_BOX_SELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_BRIGHT_FG_COLOR); +static KEYWORD_BOX_SELECTED_TITLE_STYLE: Style = Style::new().fg(KEYWORD_COLOR).add_modifier(Modifier::BOLD); -const KEYWORD_BOX_UNSELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_FG_COLOR); -const KEYWORD_BOX_UNSELECTED_TITLE_STYLE: Style = +static KEYWORD_BOX_UNSELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_FG_COLOR); +static KEYWORD_BOX_UNSELECTED_TITLE_STYLE: Style = Style::new().fg(KEYWORD_COLOR).add_modifier(Modifier::BOLD); // Entry box -const ENTRY_BOX_SELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_BRIGHT_FG_COLOR); -const ENTRY_BOX_SELECTED_TITLE_STYLE: Style = +static ENTRY_BOX_SELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_BRIGHT_FG_COLOR); +static ENTRY_BOX_SELECTED_TITLE_STYLE: Style = Style::new().fg(ENTRY_COLOR).add_modifier(Modifier::BOLD); -const ENTRY_BOX_UNSELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_FG_COLOR); -const ENTRY_BOX_UNSELECTED_TITLE_STYLE: Style = +static ENTRY_BOX_UNSELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_FG_COLOR); +static ENTRY_BOX_UNSELECTED_TITLE_STYLE: Style = Style::new().fg(ENTRY_COLOR).add_modifier(Modifier::BOLD); // Default box -// const BOX_SELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_BRIGHT_FG_COLOR); -const BOX_SELECTED_TITLE_STYLE: Style = Style::new() +// static BOX_SELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_BRIGHT_FG_COLOR); +static BOX_SELECTED_TITLE_STYLE: Style = Style::new() .fg(TEXT_BRIGHT_FG_COLOR) .add_modifier(Modifier::BOLD); -const BOX_UNSELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_FG_COLOR); -// const BOX_UNSELECTED_TITLE_STYLE: Style = +static BOX_UNSELECTED_BORDER_STYLE: Style = Style::new().fg(TEXT_FG_COLOR); +// static BOX_UNSELECTED_TITLE_STYLE: Style = // Style::new().fg(TEXT_FG_COLOR).add_modifier(Modifier::BOLD); // Popup box -const POPUP_HELP_BOX: Style = Style::new().fg(TEXT_FG_COLOR).bg(POPUP_BG); +static POPUP_HELP_BOX: Style = Style::new().fg(TEXT_FG_COLOR).bg(POPUP_BG); // Entry table styles -const ENTRY_SELECTED_ROW_STYLE: Style = Style::new() +static ENTRY_SELECTED_ROW_STYLE: Style = Style::new() .fg(ENTRY_COLOR) .add_modifier(Modifier::BOLD) .add_modifier(Modifier::REVERSED); -const KEYWORD_SELECTED_ROW_STYLE: Style = Style::new() +static KEYWORD_SELECTED_ROW_STYLE: Style = Style::new() .fg(KEYWORD_COLOR) .add_modifier(Modifier::BOLD) .add_modifier(Modifier::REVERSED); -const SELECTION_SELECTED_ROW_STYLE: Style = Style::new() +static SELECTION_SELECTED_ROW_STYLE: Style = Style::new() // .fg(ENTRY_COLOR) .add_modifier(Modifier::BOLD) .add_modifier(Modifier::REVERSED); -const SELECTED_TABLE_COL_STYLE: Style = Style::new().add_modifier(Modifier::BOLD); -const SELECTEC_TABLE_CELL_STYLE: Style = Style::new().add_modifier(Modifier::REVERSED); +static SELECTED_TABLE_COL_STYLE: Style = Style::new().add_modifier(Modifier::BOLD); +static SELECTEC_TABLE_CELL_STYLE: Style = Style::new().add_modifier(Modifier::REVERSED); // Symbols -const SORTED_ENTRIES: &str = "▼"; -const SORTED_ENTRIES_REVERSED: &str = "▲"; -const SCROLLBAR_UPPER_CORNER: Option<&str> = Some("┓"); -const SCROLLBAR_LOWER_CORNER: Option<&str> = Some("┛"); +static SORTED_ENTRIES: &str = "▼"; +static SORTED_ENTRIES_REVERSED: &str = "▲"; +static SCROLLBAR_UPPER_CORNER: Option<&str> = Some("┓"); +static SCROLLBAR_LOWER_CORNER: Option<&str> = Some("┛"); // Info area styles -const INFO_STYLE_AUTHOR: Style = Style::new().fg(INFO_COLOR); -const INFO_STYLE_TITLE: Style = Style::new().fg(ENTRY_COLOR).add_modifier(Modifier::ITALIC); -const INFO_STYLE_YEAR: Style = Style::new().fg(KEYWORD_COLOR); -const INFO_STYLE_DOI: Style = Style::new().fg(TEXT_FG_COLOR); -const INFO_STYLE_FILE: Style = Style::new().fg(TEXT_FG_COLOR); -const INFO_STYLE_ABSTRACT: Style = Style::new().fg(TEXT_FG_COLOR); +static INFO_STYLE_AUTHOR: Style = Style::new().fg(INFO_COLOR); +static INFO_STYLE_TITLE: Style = Style::new().fg(ENTRY_COLOR).add_modifier(Modifier::ITALIC); +static INFO_STYLE_YEAR: Style = Style::new().fg(KEYWORD_COLOR); +static INFO_STYLE_DOI: Style = Style::new().fg(TEXT_FG_COLOR); +static INFO_STYLE_FILE: Style = Style::new().fg(TEXT_FG_COLOR); +static INFO_STYLE_ABSTRACT: Style = Style::new().fg(TEXT_FG_COLOR); pub const fn color_list(list_item: i32, sel_item: i32, highlight: u8, max_diff: i32) -> Color { if list_item == sel_item { |
