aboutsummaryrefslogtreecommitdiff
path: root/src/tui
diff options
context:
space:
mode:
authorlukeflo2024-11-28 17:56:04 +0100
committerlukeflo2024-11-28 17:56:04 +0100
commitbb6f07dfb252eb74766051a750b9ae2696069bd5 (patch)
treeaf32e78e59f5208933ea77cbebc94518740483bc /src/tui
parent87eefb8248ccf71eb43fd817f18a18af9f5c9083 (diff)
downloadbibiman-bb6f07dfb252eb74766051a750b9ae2696069bd5.tar.gz
bibiman-bb6f07dfb252eb74766051a750b9ae2696069bd5.zip
color struct impl, integrated with cliargs
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/colors.rs72
-rw-r--r--src/tui/ui.rs74
2 files changed, 109 insertions, 37 deletions
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 {