From de0e6fcde0f4fdd9a08255dac52629bec28a0ca3 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 17 Feb 2025 21:43:18 +0100 Subject: Update README --- README.md | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 8285e37..deb65d8 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,35 @@ Here is how the light terminal scheme looks: ![bibiman-light-theme.png](https://codeberg.org/attachments/7fe9d58d-7e90-4043-9402-5e4664c4e22a) +## Configuration + +### Location of Config File + +`bibiman` can be configured through a config file. The standard location is the user's config dir following the XDG scheme. On Linux systems this defaults to: + +```bash +# XDG scheme: +$XDG_CONFIG_HOME/bibiman/bibiman.toml + +# Fallback: +$HOME/.config/bibiman/bibiman.toml + +``` + +### Values + +At the moment, the following values can be set through the config file: + +```toml +[general] +# Default files/dirs which are loaded on startup +bibfiles = [ "/path/to/bibfile", "path/to/dir/with/bibfiles" ] +# Default editor to use when editing files. Arguments are possible +editor = "vim" # with args: "vim -y" +``` + +Paths to bibfiles/dirs passed through the CLI will be added to the ones provided by the config file. + ## Features These are the current features, the list will be updated: @@ -113,9 +142,9 @@ These are the current features, the list will be updated: position in bibfile. - [x] **Load multiple files** into one session. - [x] **Add Entry via DOI**. -- [ ] **Open related notes file** for specific entry. -- [ ] **Implement config file** for setting some default values like main +- [x] **Implement config file** for setting some default values like main bibfile, PDF-opener, or editor +- [ ] **Open related notes file** for specific entry. - [ ] **Support Hayagriva(`.yaml`)** format as input (_on hold for now_, because the Hayagriva Yaml style doesn't offer keywords; s. issue in [Hayagriva repo](https://github.com/typst/hayagriva/issues/240)). @@ -158,10 +187,10 @@ enabled by default. You can use some special chars to alter pattern matching: ## Edit bib entry -For now, the TUI only supports editors set through the environment variables -`VISUAL` and `EDITOR` in this order. The fallback solution is `vi`. +The main editor can be set through the [config file](#values). Otherwise, the environment variables +`VISUAL` and `EDITOR` will be used in this order. The last fallback solution is `vi`. -I've tested the following editors (set as value of `VISUAL`): +I've tested the following editors (set as value of `VISUAL` and through the config file): - [x] **Helix**: `export VISUAL="hx"` - [x] **Vim/Neovim**: `export VISUAL="vim/nvim"` -- cgit v1.2.3 From 3bdd57994d94839aef04871bd0247f2b82b71d35 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 17 Feb 2025 21:56:20 +0100 Subject: Update README --- README.md | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index deb65d8..725cd8e 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,8 @@ Here is how the light terminal scheme looks: ### Location of Config File -`bibiman` can be configured through a config file. The standard location is the user's config dir following the XDG scheme. On Linux systems this defaults to: +`bibiman` can be configured through a config file. The standard location is the +user's config dir following the XDG scheme. On Linux systems this defaults to: ```bash # XDG scheme: @@ -107,7 +108,13 @@ $XDG_CONFIG_HOME/bibiman/bibiman.toml # Fallback: $HOME/.config/bibiman/bibiman.toml +``` + +You can set a custom config file through the CLI (`-c`/`--config-file=` flag) +which takes precedence over the standard one for the active session: +```bash +bibiman --config-file="/path/to/temporary/config" ``` ### Values @@ -122,32 +129,33 @@ bibfiles = [ "/path/to/bibfile", "path/to/dir/with/bibfiles" ] editor = "vim" # with args: "vim -y" ``` -Paths to bibfiles/dirs passed through the CLI will be added to the ones provided by the config file. +Paths to bibfiles/dirs passed through the CLI will be added to the ones provided +by the config file. ## Features These are the current features, the list will be updated: - [x] **Browse** through the bib entries using _Vim-like keybindings_ and a - _fuzzy search_ mode. + _fuzzy search_ mode. - [x] **Filter** the bib entries by _keywords_ (and afterwards filter further by - fuzzy searching). + fuzzy searching). - [x] **Edit** the current entry by opening a _terminal-based editor_ at the - specific line. + specific line. - [x] **Yank/Copy** the citekey of the current entry to the system clipboard. - [x] **Open related PDF** file (`file` BibLaTeX key) with keypress. - [x] **Open related URL/DOI** with keypress. - [x] **Scrollbar** for better navigating. - [x] **Sort Entries** by column (`Authors`, `Title`, `Year`, `Pubtype`), or by - position in bibfile. + position in bibfile. - [x] **Load multiple files** into one session. - [x] **Add Entry via DOI**. - [x] **Implement config file** for setting some default values like main - bibfile, PDF-opener, or editor + bibfile, PDF-opener, or editor - [ ] **Open related notes file** for specific entry. - [ ] **Support Hayagriva(`.yaml`)** format as input (_on hold for now_, because - the Hayagriva Yaml style doesn't offer keywords; s. issue in - [Hayagriva repo](https://github.com/typst/hayagriva/issues/240)). + the Hayagriva Yaml style doesn't offer keywords; s. issue in + [Hayagriva repo](https://github.com/typst/hayagriva/issues/240)). **Please feel free to suggest further features through the issue functionality.** @@ -187,17 +195,19 @@ enabled by default. You can use some special chars to alter pattern matching: ## Edit bib entry -The main editor can be set through the [config file](#values). Otherwise, the environment variables -`VISUAL` and `EDITOR` will be used in this order. The last fallback solution is `vi`. +The main editor can be set through the [config file](#values). Otherwise, the +environment variables `VISUAL` and `EDITOR` will be used in this order. The last +fallback solution is `vi`. -I've tested the following editors (set as value of `VISUAL` and through the config file): +I've tested the following editors (set as value of `VISUAL` and through the +config file): - [x] **Helix**: `export VISUAL="hx"` - [x] **Vim/Neovim**: `export VISUAL="vim/nvim"` - [x] **Emacs (Terminal)**: `export VISUAL="emacs -nw"` - [x] **Nano**: `export VISUAL="nano"` - [x] **Emacs (GUI)**: `export VISUAL="emacs"` (open emacs in separate window, - blocks the terminal running `bibiman` as long as emacs is opened) + blocks the terminal running `bibiman` as long as emacs is opened) Feel free to try other editors and report. Important is that the editor supports the argument `+..` to set the line number that the cursor should be placed at. -- cgit v1.2.3 From dc5ded8160177864963a31476c2a7afe8ca8e834 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Wed, 19 Feb 2025 21:13:50 +0100 Subject: resource opener in config + implement config field `pdf_opener` for setting app to open PDFs/Epubs + implement config field `url_opener` for setting app to open URLs/DOIs + function to select fallback if no field is provided in config --- README.md | 2 ++ example-config.toml | 2 ++ src/app.rs | 55 +++++++++++++++++++++++++++++++++++------------------ src/bibiman.rs | 10 ++++++---- src/config.rs | 26 +++++++++++++++++++++---- src/main.rs | 2 +- 6 files changed, 69 insertions(+), 28 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 725cd8e..47d57de 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ POSITIONAL ARGS: FLAGS: -h, --help Show this help and exit -v, --version Show the version and exit + -c, --config-file Path to config file for current session + Takes precedence over standard config file --light-terminal Enable color mode for light terminal background ``` diff --git a/example-config.toml b/example-config.toml index 989350e..9d110ed 100644 --- a/example-config.toml +++ b/example-config.toml @@ -1,3 +1,5 @@ [general] bibfiles = ["./tests/biblatex-test.bib"] # files and dirs are possible editor = "vim" # arguments are possible: "vim -y" +# pdf_opener = "xdg-open" +# url_opener = "xdg-open" diff --git a/src/app.rs b/src/app.rs index b49e883..e03f8d7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -275,7 +275,7 @@ impl App { if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup(); } else if let Some(PopupKind::OpenRes) = self.bibiman.popup_area.popup_kind { - self.bibiman.open_connected_res()?; + self.bibiman.open_connected_res(cfg)?; } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind { self.bibiman.append_entry_to_file(args)? @@ -362,16 +362,20 @@ impl App { } } -pub fn open_connected_file(file: &OsStr) -> Result<()> { +pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard // TODO: make custom opener command possible through config - let cmd = { - match std::env::consts::OS { - "linux" => String::from("xdg-open"), - "macos" => String::from("open"), - "windows" => String::from("start"), - _ => panic!("Couldn't detect OS for setting correct opener"), - } + // let cmd = { + // match std::env::consts::OS { + // "linux" => String::from("xdg-open"), + // "macos" => String::from("open"), + // "windows" => String::from("start"), + // _ => panic!("Couldn't detect OS for setting correct opener"), + // } + // }; + let cmd = match &cfg.general.pdf_opener { + Some(c) => c, + None => &select_opener(), }; // If necessary, replace ~ with /home dir @@ -381,7 +385,7 @@ pub fn open_connected_file(file: &OsStr) -> Result<()> { // Pass filepath as argument, pipe stdout and stderr to /dev/null // to keep the TUI clean (where is it piped on Windows???) - let _ = Command::new(&cmd) + let _ = Command::new(cmd) .arg(file) .stdout(Stdio::null()) .stderr(Stdio::null()) @@ -391,21 +395,25 @@ pub fn open_connected_file(file: &OsStr) -> Result<()> { Ok(()) } -pub fn open_connected_link(link: &str) -> Result<()> { +pub fn open_connected_link(cfg: &BibiConfig, link: &str) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard // TODO: make custom opener command possible through config - let cmd = { - match std::env::consts::OS { - "linux" => String::from("xdg-open"), - "macos" => String::from("open"), - "windows" => String::from("start"), - _ => panic!("Couldn't detect OS for setting correct opener"), - } + // let cmd = { + // match std::env::consts::OS { + // "linux" => String::from("xdg-open"), + // "macos" => String::from("open"), + // "windows" => String::from("start"), + // _ => panic!("Couldn't detect OS for setting correct opener"), + // } + // }; + let cmd = match &cfg.general.url_opener { + Some(c) => c, + None => &select_opener(), }; // Pass filepath as argument, pipe stdout and stderr to /dev/null // to keep the TUI clean (where is it piped on Windows???) - let _ = Command::new(&cmd) + let _ = Command::new(cmd) .arg(link) .stdout(Stdio::null()) .stderr(Stdio::null()) @@ -437,6 +445,15 @@ fn expand_home(path: &PathBuf) -> PathBuf { } } +fn select_opener() -> String { + match std::env::consts::OS { + "linux" => String::from("xdg-open"), + "macos" => String::from("open"), + "windows" => String::from("start"), + _ => panic!("Couldn't detect OS for setting correct opener"), + } +} + #[cfg(test)] mod test { use super::*; diff --git a/src/bibiman.rs b/src/bibiman.rs index 20cdfc6..ecddc4c 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -85,7 +85,9 @@ impl Bibiman { // Constructs a new instance of [`App`]. pub fn new(args: &mut CLIArgs, cfg: &mut BibiConfig) -> Result { let mut main_bibfiles: Vec = args.pos_args.clone(); - main_bibfiles.append(&mut cfg.general.bibfiles); + if cfg.general.bibfiles.is_some() { + main_bibfiles.append(cfg.general.bibfiles.as_mut().unwrap()) + }; let main_bibfiles = cliargs::parse_files(main_bibfiles); let main_biblio = BibiSetup::new(&main_bibfiles); let tag_list = TagList::new(main_biblio.keyword_list.clone()); @@ -542,7 +544,7 @@ impl Bibiman { Ok(()) } - pub fn open_connected_res(&mut self) -> Result<()> { + pub fn open_connected_res(&mut self, cfg: &BibiConfig) -> Result<()> { // Index of selected entry let entry_idx = self.entry_table.entry_table_state.selected().unwrap(); @@ -553,10 +555,10 @@ impl Bibiman { if self.popup_area.popup_list[popup_idx].contains("Weblink") { let object = self.entry_table.entry_table_items[entry_idx].doi_url(); let url = app::prepare_weblink(object); - app::open_connected_link(&url)?; + app::open_connected_link(cfg, &url)?; } else if self.popup_area.popup_list[popup_idx].contains("File") { let object = self.entry_table.entry_table_items[entry_idx].filepath(); - app::open_connected_file(object)?; + app::open_connected_file(cfg, object)?; } else { eprintln!("Unable to find ressource to open"); }; diff --git a/src/config.rs b/src/config.rs index a80cc13..abb610b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,33 +17,51 @@ use std::path::PathBuf; +use color_eyre::eyre::Result; use config::{ConfigError, FileFormat}; use serde::Deserialize; use crate::cliargs::CLIArgs; +/// Main struct of the config file. Contains substructs/headings in toml #[derive(Debug, Clone, Deserialize)] pub struct BibiConfig { pub general: General, } +/// Substruct [general] in config.toml #[derive(Debug, Clone, Deserialize)] pub struct General { - pub bibfiles: Vec, + pub bibfiles: Option>, pub editor: Option, + pub pdf_opener: Option, + pub url_opener: Option, } impl BibiConfig { - pub fn default(args: &CLIArgs) -> Self { + pub fn default() -> Self { Self { general: General { - bibfiles: args.pos_args.clone(), + bibfiles: None, editor: None, + pdf_opener: None, + url_opener: None, }, } } - pub fn new(args: &CLIArgs) -> Result { + pub fn new(args: &CLIArgs) -> Result { + // let mut cfg = config::Config::builder(); + // cfg = cfg.add_source( + // config::File::from(args.cfg_path.clone()) + // .format(FileFormat::Toml) + // .required(false), + // ); + // cfg.build()?.try_deserialize() + Ok(Self::parse_cfg_file(args)?) + } + + fn parse_cfg_file(args: &CLIArgs) -> Result { let mut cfg = config::Config::builder(); cfg = cfg.add_source( config::File::from(args.cfg_path.clone()) diff --git a/src/main.rs b/src/main.rs index 37bead0..d53aaab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ async fn main() -> Result<()> { let mut cfg = if parsed_args.cfg_path.is_file() { BibiConfig::new(&parsed_args)? } else { - BibiConfig::default(&parsed_args) + BibiConfig::default() }; init_error_hooks()?; -- cgit v1.2.3 From f60be8b6b1e5987613081c9ad8d63a26a1a1bac9 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Wed, 19 Feb 2025 21:42:57 +0100 Subject: remove some comments, update README --- README.md | 13 ++++++++++--- example-config.toml | 2 +- src/app.rs | 22 ++-------------------- src/cliargs.rs | 7 +++++++ 4 files changed, 20 insertions(+), 24 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 47d57de..d62c847 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ POSITIONAL ARGS: FLAGS: -h, --help Show this help and exit -v, --version Show the version and exit - -c, --config-file Path to config file for current session + -c, --config-file= Path to config file for current session needed as argument. Takes precedence over standard config file --light-terminal Enable color mode for light terminal background @@ -129,10 +129,17 @@ At the moment, the following values can be set through the config file: bibfiles = [ "/path/to/bibfile", "path/to/dir/with/bibfiles" ] # Default editor to use when editing files. Arguments are possible editor = "vim" # with args: "vim -y" +# Default app to open PDFs/Epubs +pdf_opener = "xdg-open" +# Default app to open URLs/DOIs +url_opener = "xdg-open" ``` -Paths to bibfiles/dirs passed through the CLI will be added to the ones provided -by the config file. +No value *needs* to be set. For every one exists a default value. Only exception +is the `bibfiles` key. If no file or dir is set, you *have to* add a path via +CLI interface. If the `bibfiles` value is set *and* a further path (or multiple) +is provided through the CLI call, the entries of all those files will be opened +in the started `bibiman` session. ## Features diff --git a/example-config.toml b/example-config.toml index 9d110ed..50c0467 100644 --- a/example-config.toml +++ b/example-config.toml @@ -1,5 +1,5 @@ [general] -bibfiles = ["./tests/biblatex-test.bib"] # files and dirs are possible +bibfiles = ["./tests/biblatex-test.bib"] # multiple files and dirs are possible editor = "vim" # arguments are possible: "vim -y" # pdf_opener = "xdg-open" # url_opener = "xdg-open" diff --git a/src/app.rs b/src/app.rs index e03f8d7..55f49de 100644 --- a/src/app.rs +++ b/src/app.rs @@ -364,15 +364,6 @@ impl App { pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard - // TODO: make custom opener command possible through config - // let cmd = { - // match std::env::consts::OS { - // "linux" => String::from("xdg-open"), - // "macos" => String::from("open"), - // "windows" => String::from("start"), - // _ => panic!("Couldn't detect OS for setting correct opener"), - // } - // }; let cmd = match &cfg.general.pdf_opener { Some(c) => c, None => &select_opener(), @@ -397,15 +388,6 @@ pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { pub fn open_connected_link(cfg: &BibiConfig, link: &str) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard - // TODO: make custom opener command possible through config - // let cmd = { - // match std::env::consts::OS { - // "linux" => String::from("xdg-open"), - // "macos" => String::from("open"), - // "windows" => String::from("start"), - // _ => panic!("Couldn't detect OS for setting correct opener"), - // } - // }; let cmd = match &cfg.general.url_opener { Some(c) => c, None => &select_opener(), @@ -433,8 +415,8 @@ pub fn prepare_weblink(url: &str) -> String { } } -fn expand_home(path: &PathBuf) -> PathBuf { - // let path = PathBuf::from(path); +/// Expand leading tilde (`~`) to `/home/user` +pub fn expand_home(path: &PathBuf) -> PathBuf { if path.starts_with("~") { let mut home = dirs::home_dir().unwrap(); let path = path.strip_prefix("~").unwrap(); diff --git a/src/cliargs.rs b/src/cliargs.rs index 895f116..bb3c8d1 100644 --- a/src/cliargs.rs +++ b/src/cliargs.rs @@ -23,6 +23,7 @@ use std::env; use std::path::PathBuf; use walkdir::WalkDir; +use crate::app; use crate::tui::colors::AppColors; // struct for CLIArgs @@ -76,6 +77,12 @@ pub fn parse_files(args: Vec) -> Vec { let mut files: Vec = Vec::new(); // If pos arg is file, just push it to path vec for i in args { + // Expand tilde to /home/user + let i = if i.starts_with("~") { + app::expand_home(&i) + } else { + i + }; if i.is_file() { files.push(i); // If pos arg is dir, walk dir and collect bibfiles -- cgit v1.2.3 From c34412d9e3725bed48af925646110f2ca34b1bd4 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Fri, 21 Feb 2025 21:55:17 +0100 Subject: implement working config file construct, error handling should be improved --- README.md | 58 ++++++++---- example-config.toml | 12 +++ src/app.rs | 32 ++----- src/bibiman.rs | 6 +- src/cliargs.rs | 11 +-- src/config.rs | 26 ++--- src/main.rs | 13 +-- src/tui.rs | 6 +- src/tui/popup.rs | 33 ++++--- src/tui/ui.rs | 266 ++++++++++++++++++++++++++++------------------------ 10 files changed, 255 insertions(+), 208 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index d62c847..41ebdfc 100644 --- a/README.md +++ b/README.md @@ -87,16 +87,6 @@ bibman tests/multi-files/ bibiman tests/biblatex-test.bib tests/multi-files/ ``` -Furthermore, in issue #3 it was asked to enable a color customization to run -`bibiman` also in terminal setups with light background. Thus, now it is -possible to enable a light terminal mode with the `--light-terminal` flag. Full -color customization is not possible right now, but maybe will be added with the -implementation of a config file. - -Here is how the light terminal scheme looks: - -![bibiman-light-theme.png](https://codeberg.org/attachments/7fe9d58d-7e90-4043-9402-5e4664c4e22a) - ## Configuration ### Location of Config File @@ -119,13 +109,14 @@ which takes precedence over the standard one for the active session: bibiman --config-file="/path/to/temporary/config" ``` -### Values +### General Configuration -At the moment, the following values can be set through the config file: +The following general values can be set through the config file: ```toml [general] # Default files/dirs which are loaded on startup +# Use absolute paths (~ for HOME works). Otherwise, loading might not work. bibfiles = [ "/path/to/bibfile", "path/to/dir/with/bibfiles" ] # Default editor to use when editing files. Arguments are possible editor = "vim" # with args: "vim -y" @@ -135,11 +126,44 @@ pdf_opener = "xdg-open" url_opener = "xdg-open" ``` -No value *needs* to be set. For every one exists a default value. Only exception -is the `bibfiles` key. If no file or dir is set, you *have to* add a path via -CLI interface. If the `bibfiles` value is set *and* a further path (or multiple) -is provided through the CLI call, the entries of all those files will be opened -in the started `bibiman` session. +If no file or dir is set as `bibfiles` value, you *have to* add a path via CLI +interface. If the `bibfiles` value is set *and* a further path (or multiple) is +provided through the CLI call, the entries of all those files will be opened in +the started `bibiman` session. + +### Color Configuration + +Furthermore, it is now possible to customize the colors. The following values +can be changed: + +```toml +[colors] +# Default values for dark-themed terminal +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 = "234" +popup_bg_color = "234" +selected_row_bg_color = "237" +``` + +Colors can be set through three different methods: +[ANSI color names](https://docs.rs/ratatui/latest/ratatui/style/enum.Color.html), +[256-color indices](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) and +[HEX codes](https://www.w3schools.com/colors/colors_hexadecimal.asp). For +example, the following definitions are all valid: + +```toml +selected_row_bg_color = "darkgray" # ANSI color name (light_black or bright_black would also work) +selected_row_bg_color = "237" # 256-color index +selected_row_bg_color = "#3a3a3a" # HEX code +``` + +To run `bibiman` with some default values for a light-colored terminal use the `--light-terminal` flag. ## Features diff --git a/example-config.toml b/example-config.toml index 50c0467..d6d2aa8 100644 --- a/example-config.toml +++ b/example-config.toml @@ -3,3 +3,15 @@ bibfiles = ["./tests/biblatex-test.bib"] # multiple files and dirs are possible editor = "vim" # arguments are possible: "vim -y" # pdf_opener = "xdg-open" # url_opener = "xdg-open" + +# [colors] +# 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 = "234" +# popup_bg_color = "234" +# selected_row_bg_color = "237" diff --git a/src/app.rs b/src/app.rs index b3778af..7869304 100644 --- a/src/app.rs +++ b/src/app.rs @@ -24,7 +24,6 @@ use crate::tui::commands::InputCmdAction; use crate::tui::popup::PopupKind; use crate::tui::{self, Tui}; use crate::{bibiman::Bibiman, tui::commands::CmdAction}; -use core::panic; use std::ffi::OsStr; use std::path::PathBuf; use std::process::{Command, Stdio}; @@ -60,14 +59,14 @@ impl App { }) } - pub async fn run(&mut self, args: &mut CLIArgs, cfg: &BibiConfig) -> Result<()> { + pub async fn run(&mut self, cfg: &BibiConfig) -> Result<()> { let mut tui = tui::Tui::new()?; tui.enter()?; // Start the main loop. while self.running { // Render the user interface. - tui.draw(self, args)?; + tui.draw(self, cfg)?; // Handle events. match tui.next().await? { Event::Tick => self.tick(), @@ -86,10 +85,10 @@ impl App { } else { CmdAction::from(key_event) }; - self.run_command(command, args, cfg, &mut tui)? + self.run_command(command, cfg, &mut tui)? } Event::Mouse(mouse_event) => { - self.run_command(CmdAction::from(mouse_event), args, cfg, &mut tui)? + self.run_command(CmdAction::from(mouse_event), cfg, &mut tui)? } Event::Resize(_, _) => {} @@ -111,13 +110,7 @@ impl App { self.running = false; } - pub fn run_command( - &mut self, - cmd: CmdAction, - args: &mut CLIArgs, - cfg: &BibiConfig, - tui: &mut Tui, - ) -> Result<()> { + pub fn run_command(&mut self, cmd: CmdAction, cfg: &BibiConfig, tui: &mut Tui) -> Result<()> { match cmd { CmdAction::Input(cmd) => match cmd { InputCmdAction::Nothing => {} @@ -149,7 +142,7 @@ impl App { || doi.starts_with("http://doi.org") || doi.starts_with("http://dx.doi.org") { - self.bibiman.handle_new_entry_submission(args, doi); + self.bibiman.handle_new_entry_submission(doi); } else { self.bibiman.popup_area.popup_message( "No valid DOI pattern: ", @@ -278,7 +271,7 @@ impl App { self.bibiman.open_connected_res(cfg)?; } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind { - self.bibiman.append_entry_to_file(args)? + self.bibiman.append_entry_to_file()? } } } @@ -310,7 +303,7 @@ impl App { } CmdAction::EditFile => { if let CurrentArea::EntryArea = self.bibiman.current_area { - self.bibiman.run_editor(cfg, args, tui)?; + self.bibiman.run_editor(cfg, tui)?; } } CmdAction::Open => { @@ -419,15 +412,6 @@ pub fn expand_home(path: &PathBuf) -> PathBuf { } } -fn select_opener() -> String { - match std::env::consts::OS { - "linux" => String::from("xdg-open"), - "macos" => String::from("open"), - "windows" => String::from("start"), - _ => panic!("Couldn't detect OS for setting correct opener"), - } -} - #[cfg(test)] mod test { use super::*; diff --git a/src/bibiman.rs b/src/bibiman.rs index b68b0fa..b8ef2c6 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -330,7 +330,7 @@ impl Bibiman { self.entry_table.entry_table_state.select(Some(idx_count)); } - pub fn run_editor(&mut self, cfg: &BibiConfig, args: &CLIArgs, tui: &mut Tui) -> Result<()> { + pub fn run_editor(&mut self, cfg: &BibiConfig, tui: &mut Tui) -> Result<()> { // get filecontent and citekey for calculating line number let citekey: &str = &self.entry_table.entry_table_items [self.entry_table.entry_table_state.selected().unwrap()] @@ -418,7 +418,7 @@ impl Bibiman { ///the new entry via `append_to_file()` function. If not, show error popup /// ///The method needs two arguments: the CLIArgs struct and the `str` containing the DOI - pub fn handle_new_entry_submission(&mut self, args: &CLIArgs, doi_string: &str) { + pub fn handle_new_entry_submission(&mut self, doi_string: &str) { let doi_string = if doi_string.starts_with("10.") { "https://doi.org/".to_string() + doi_string } else { @@ -466,7 +466,7 @@ impl Bibiman { self.popup_area.popup_selection(items); } - pub fn append_entry_to_file(&mut self, args: &mut CLIArgs) -> Result<()> { + pub fn append_entry_to_file(&mut self) -> Result<()> { // Index of selected popup field let popup_idx = self.popup_area.popup_state.selected().unwrap(); diff --git a/src/cliargs.rs b/src/cliargs.rs index bb3c8d1..3c302f4 100644 --- a/src/cliargs.rs +++ b/src/cliargs.rs @@ -24,7 +24,6 @@ use std::path::PathBuf; use walkdir::WalkDir; use crate::app; -use crate::tui::colors::AppColors; // struct for CLIArgs #[derive(Debug, Default, Clone)] @@ -32,11 +31,8 @@ pub struct CLIArgs { pub helparg: bool, pub versionarg: bool, pub pos_args: Vec, - // pub files: Vec, pub cfg_path: PathBuf, - // INFO: AppColors struct later should be moved to config/app struct - // when config file is implemented - pub colors: AppColors, + pub light_theme: bool, } impl CLIArgs { @@ -56,10 +52,7 @@ impl CLIArgs { Short('h') | Long("help") => args.helparg = true, Short('v') | Long("version") => args.versionarg = true, Short('c') | Long("config-file") => args.cfg_path = parser.value()?.parse()?, - Long("light-terminal") => { - args.colors.light_colors(); - args.colors.toggle_color_scheme() - } + Long("light-terminal") => args.light_theme = true, // 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/config.rs b/src/config.rs index 22873dd..faba5d8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -72,7 +72,7 @@ impl Default for BibiConfig { info_color: Some(Color::Indexed(99)), confirm_color: Some(Color::Indexed(47)), warn_color: Some(Color::Indexed(124)), - bar_bg_color: Some(Color::Indexed(234)), + bar_bg_color: Some(Color::Indexed(235)), popup_bg_color: Some(Color::Indexed(234)), selected_row_bg_color: Some(Color::Indexed(237)), }), @@ -138,17 +138,6 @@ impl BibiConfig { Ok(()) } - pub fn new(args: &CLIArgs) -> Result { - // let mut cfg = config::Config::builder(); - // cfg = cfg.add_source( - // config::File::from(args.cfg_path.clone()) - // .format(FileFormat::Toml) - // .required(false), - // ); - // cfg.build()?.try_deserialize() - Ok(Self::parse_cfg_file(args)?) - } - fn parse_cfg_file(args: &CLIArgs) -> Result { let mut cfg = config::Config::builder(); cfg = cfg.add_source( @@ -158,6 +147,19 @@ impl BibiConfig { ); cfg.build()?.try_deserialize() } + + /// Activates the default color scheme for light background terminals + pub fn light_colors(&mut self) { + self.colors.as_mut().unwrap().main_text_color = Some(Color::Indexed(235)); + self.colors.as_mut().unwrap().highlight_text_color = Some(Color::Indexed(232)); + self.colors.as_mut().unwrap().entry_color = Some(Color::Indexed(23)); + self.colors.as_mut().unwrap().keyword_color = Some(Color::Indexed(58)); + self.colors.as_mut().unwrap().info_color = Some(Color::Indexed(57)); + self.colors.as_mut().unwrap().bar_bg_color = Some(Color::Indexed(144)); + self.colors.as_mut().unwrap().popup_bg_color = Some(Color::Indexed(187)); + self.colors.as_mut().unwrap().confirm_color = Some(Color::Indexed(22)); + self.colors.as_mut().unwrap().selected_row_bg_color = Some(Color::Indexed(107)); + } } fn select_opener() -> String { diff --git a/src/main.rs b/src/main.rs index 8ec3b77..3325f80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,12 +45,13 @@ async fn main() -> Result<()> { std::process::exit(0); } - // let mut cfg = if parsed_args.cfg_path.is_file() { - // BibiConfig::new(&parsed_args)? - // } else { - // BibiConfig::default() - // }; + // Build default config let mut cfg = BibiConfig::default(); + + if parsed_args.light_theme { + cfg.light_colors(); + } + // Merge values from config file if present cfg.parse_config(&parsed_args)?; init_error_hooks()?; @@ -58,6 +59,6 @@ async fn main() -> Result<()> { // Create an application. let mut app = App::new(&mut parsed_args, &mut cfg)?; - app.run(&mut parsed_args, &cfg).await?; + app.run(&cfg).await?; Ok(()) } diff --git a/src/tui.rs b/src/tui.rs index b39b5c4..1e3061f 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -20,7 +20,7 @@ pub mod commands; pub mod popup; pub mod ui; -use crate::{cliargs::CLIArgs, App}; +use crate::{config::BibiConfig, App}; use crossterm::{ cursor, event::{ @@ -195,11 +195,11 @@ impl Tui { // // [`Draw`]: ratatui::Terminal::draw // [`rendering`]: crate::ui::render - pub fn draw(&mut self, app: &mut App, args: &CLIArgs) -> Result<()> { + pub fn draw(&mut self, app: &mut App, cfg: &BibiConfig) -> Result<()> { // self.terminal.draw(|frame| ui::render(app, frame))?; self.terminal // .draw(|frame| frame.render_widget(app, frame.area()))?; - .draw(|frame| ui::render_ui(app, args, frame))?; + .draw(|frame| ui::render_ui(app, cfg, frame))?; Ok(()) } diff --git a/src/tui/popup.rs b/src/tui/popup.rs index 4ef9fc3..6a2e8ff 100644 --- a/src/tui/popup.rs +++ b/src/tui/popup.rs @@ -16,12 +16,12 @@ ///// use ratatui::{ - style::{Color, Stylize}, + style::Stylize, text::{Line, Span, Text}, widgets::ListState, }; -use crate::cliargs::CLIArgs; +use crate::config::BibiConfig; #[derive(Debug)] pub enum PopupKind { @@ -47,7 +47,7 @@ pub struct PopupArea { } impl PopupArea { - pub fn popup_help<'a>(args: &CLIArgs) -> Text<'a> { + pub fn popup_help<'a>(cfg: &BibiConfig) -> Text<'a> { let help = [ ("General", "first"), ("TAB: ", "Toggle areas (Entries, Keywords)"), @@ -89,22 +89,31 @@ impl PopupArea { for (keys, help) in help { if help == "first" { helptext.push(Line::from( - Span::raw(keys) - .bold() - .fg(Color::Indexed(args.colors.main_text_color)), + Span::raw(keys).bold().fg(cfg + .colors + .as_ref() + .unwrap() + .main_text_color + .unwrap()), )) } else if help == "sub" { helptext.push(Line::from("")); helptext.push(Line::from( - Span::raw(keys) - .bold() - .fg(Color::Indexed(args.colors.main_text_color)), + Span::raw(keys).bold().fg(cfg + .colors + .as_ref() + .unwrap() + .main_text_color + .unwrap()), )) } else { helptext.push(Line::from(vec![ - Span::raw(keys) - .bold() - .fg(Color::Indexed(args.colors.keyword_color)), + Span::raw(keys).bold().fg(cfg + .colors + .as_ref() + .unwrap() + .main_text_color + .unwrap()), Span::raw(help), ])) } diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 52d2d9a..5fbe283 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -17,11 +17,11 @@ use std::path::PathBuf; -use super::colors::AppColorScheme; use super::popup::PopupArea; use crate::bibiman::entries::EntryTableColumn; use crate::bibiman::{CurrentArea, FormerArea}; use crate::cliargs::CLIArgs; +use crate::config::BibiConfig; use crate::tui::popup::PopupKind; use crate::App; use ratatui::layout::{Direction, Position}; @@ -52,8 +52,8 @@ pub fn color_list( highlight: u8, max_diff: i32, ) -> Color { - match args.colors.color_scheme { - AppColorScheme::Dark => { + match args.light_theme { + false => { if list_item == sel_item { Color::Indexed(highlight) } else if (list_item - sel_item) > max_diff @@ -68,7 +68,7 @@ pub fn color_list( Color::Indexed(highlight - (list_item - sel_item) as u8) } } - AppColorScheme::Light => { + true => { if list_item == sel_item { Color::Indexed(highlight) } else if (list_item - sel_item) > max_diff @@ -103,7 +103,7 @@ fn count_files(files: &[PathBuf]) -> u16 { count } -pub fn render_ui(app: &mut App, args: &CLIArgs, frame: &mut Frame) { +pub fn render_ui(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { let [header_area, main_area, footer_area] = Layout::new( Direction::Vertical, [ @@ -128,20 +128,20 @@ pub fn render_ui(app: &mut App, args: &CLIArgs, frame: &mut Frame) { let [tag_area, info_area] = Layout::horizontal([Constraint::Max(25), Constraint::Min(35)]).areas(item_area); - render_header(args, frame, header_area); + render_header(cfg, frame, header_area); if let CurrentArea::SearchArea = app.bibiman.current_area { - render_footer(app, args, frame, footer_area); + render_footer(app, cfg, frame, footer_area); } - render_entrytable(app, args, frame, entry_area); - render_selected_item(app, args, frame, info_area); - render_taglist(app, args, frame, tag_area); - render_file_info(app, args, frame, entry_info_area); + render_entrytable(app, cfg, frame, entry_area); + render_selected_item(app, cfg, frame, info_area); + render_taglist(app, cfg, frame, tag_area); + render_file_info(app, cfg, frame, entry_info_area); if app.bibiman.popup_area.is_popup { - render_popup(app, args, frame); + render_popup(app, cfg, frame); } } -pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { +pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { match app.bibiman.popup_area.popup_kind { Some(PopupKind::Help) => { let block = Block::bordered() @@ -150,13 +150,13 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { .title_alignment(Alignment::Center) .style( Style::new() - .fg(Color::Indexed(args.colors.main_text_color)) - .bg(Color::Indexed(args.colors.popup_bg_color)), + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) + .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()), ) .border_set(symbols::border::THICK) - .border_style(Style::new().fg(Color::Indexed(args.colors.entry_color))); + .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())); - let text: Text = PopupArea::popup_help(args); + let text: Text = PopupArea::popup_help(cfg); // Calculate max scroll position depending on hight of terminal window // Needed length is number of text lines plus two for borders at bottom and top @@ -191,23 +191,23 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { .title_alignment(Alignment::Center) .style( Style::new() - .fg(Color::Indexed(args.colors.main_text_color)) - .bg(Color::Indexed(args.colors.popup_bg_color)), + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) + .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()), ) .border_set(symbols::border::THICK) - .border_style(Style::new().fg(Color::Indexed(args.colors.entry_color))); + .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().entry_color.unwrap())); // Prepare the input fields let content = vec![Line::from(vec![ Span::styled( "DOI: ", - Style::new().fg(Color::Indexed(args.colors.entry_color)), + Style::new().fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()), ), Span::raw(app.input.value().to_string().clone()), ])]; let paragraph = Paragraph::new(content) .block(block.clone()) - .style(Style::new().fg(Color::Indexed(args.colors.main_text_color))) + .style(Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())) .wrap(Wrap { trim: false }); let doi_lines = paragraph.line_count(area.width / 2); @@ -228,18 +228,18 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { .title_top( " Message " .bold() - .fg(Color::Indexed(args.colors.confirm_color)), + .fg(cfg.colors.as_ref().unwrap().confirm_color.unwrap()), ) - .border_style(Style::new().fg(Color::Indexed(args.colors.confirm_color))) + .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().confirm_color.unwrap())) .style( Style::new() - .fg(Color::Indexed(args.colors.main_text_color)) - .bg(Color::Indexed(args.colors.popup_bg_color)), + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) + .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()), ); let content = Paragraph::new(app.bibiman.popup_area.popup_message.clone()) .block(block) - .style(Style::new().fg(Color::Indexed(args.colors.confirm_color))); + .style(Style::new().fg(cfg.colors.as_ref().unwrap().confirm_color.unwrap())); // Calculate popup size. Width is number of string chars plus 2 for border let popup_area = popup_area( @@ -259,18 +259,18 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { .title_top( " Warning " .bold() - .fg(Color::Indexed(args.colors.warn_color)), + .fg(cfg.colors.as_ref().unwrap().warn_color.unwrap()), ) .border_style(Style::new().fg(Color::Red)) .style( Style::new() - .fg(Color::Indexed(args.colors.main_text_color)) - .bg(Color::Indexed(args.colors.popup_bg_color)), + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) + .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()), ); let content = Paragraph::new(app.bibiman.popup_area.popup_message.clone()) .block(block) - .style(Style::new().fg(Color::Indexed(args.colors.warn_color))); + .style(Style::new().fg(cfg.colors.as_ref().unwrap().warn_color.unwrap())); // Calculate popup size. Width is number of string chars plus 2 for border let popup_area = popup_area( @@ -306,15 +306,15 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { .title_alignment(Alignment::Center) .style( Style::new() - .fg(Color::Indexed(args.colors.main_text_color)) - .bg(Color::Indexed(args.colors.popup_bg_color)), + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) + .bg(cfg.colors.as_ref().unwrap().popup_bg_color.unwrap()), ) .border_set(symbols::border::THICK) - .border_style(Style::new().fg(Color::Indexed(args.colors.keyword_color))); + .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap())); let list = List::new(list_items).block(block).highlight_style( Style::new() - // .fg(Color::Indexed(args.colors.entry_color)) + // .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::BOLD) .add_modifier(Modifier::REVERSED), ); @@ -330,15 +330,15 @@ pub fn render_popup(app: &mut App, args: &CLIArgs, frame: &mut Frame) { } } -pub fn render_header(args: &CLIArgs, frame: &mut Frame, rect: Rect) { +pub fn render_header(cfg: &BibiConfig, frame: &mut Frame, rect: Rect) { let main_header = Paragraph::new("BIBIMAN – BibLaTeX manager TUI") .bold() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .centered(); frame.render_widget(main_header, rect) } -pub fn render_footer(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Rect) { +pub fn render_footer(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect: Rect) { let search_title = { match app.bibiman.former_area { Some(FormerArea::EntryArea) => "Search Entries: ".to_string(), @@ -349,29 +349,36 @@ pub fn render_footer(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Rec let title_lenght: u16 = search_title.chars().count() as u16; - let block = Block::new() - .padding(Padding::horizontal(1)) - .bg(Color::Indexed(args.colors.bar_bg_color)); + let block = Block::new().padding(Padding::horizontal(1)).bg(cfg + .colors + .as_ref() + .unwrap() + .bar_bg_color + .unwrap()); let search_string = Paragraph::new(Line::from(vec![ Span::styled( search_title, if let Some(FormerArea::EntryArea) = app.bibiman.former_area { Style::new() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::BOLD) } else if let Some(FormerArea::TagArea) = app.bibiman.former_area { Style::new() - .fg(Color::Indexed(args.colors.keyword_color)) + .fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap()) .add_modifier(Modifier::BOLD) } else { Style::new() - .fg(Color::Indexed(args.colors.highlight_text_color)) + .fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap()) .add_modifier(Modifier::BOLD) }, ), - Span::raw(app.bibiman.search_struct.search_string.clone()) - .fg(Color::Indexed(args.colors.highlight_text_color)), + Span::raw(app.bibiman.search_struct.search_string.clone()).fg(cfg + .colors + .as_ref() + .unwrap() + .highlight_text_color + .unwrap()), ])) .block(block); @@ -383,7 +390,7 @@ pub fn render_footer(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Rec // 1. Basename of the currently loaded file // 2. Keyword by which the entries are filtered at the moment // 3. Currently selected entry and total count of entries -pub fn render_file_info(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Rect) { +pub fn render_file_info(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect: Rect) { let block = Block::new() // can also be Block::new // Leave Top empty to simulate one large box with borders of entry list .borders(Borders::LEFT | Borders::RIGHT | Borders::BOTTOM) @@ -393,10 +400,10 @@ pub fn render_file_info(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: symbols::border::PLAIN }) .border_style(if let CurrentArea::EntryArea = app.bibiman.current_area { - Style::new().fg(Color::Indexed(args.colors.highlight_text_color)) + Style::new().fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap()) } else { Style::new() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::BOLD) }); @@ -415,7 +422,7 @@ pub fn render_file_info(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: { Line::from(vec![ Span::raw("File: ") - .fg(Color::Indexed(args.colors.main_text_color)) + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) .bold(), Span::raw( app.bibiman.main_bibfiles[0] @@ -423,28 +430,33 @@ pub fn render_file_info(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: .unwrap() .to_string_lossy(), ) - .fg(Color::Indexed(args.colors.main_text_color)) + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) .bold(), ]) - .bg(Color::Indexed(args.colors.bar_bg_color)) + .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()) } else { Line::from(vec![ Span::raw("Multiple files (") - .fg(Color::Indexed(args.colors.main_text_color)) + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) .bold(), Span::raw(count_files(&app.bibiman.main_bibfiles).to_string()) - .fg(Color::Indexed(args.colors.main_text_color)) + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) .bold(), Span::raw(")") - .fg(Color::Indexed(args.colors.main_text_color)) + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) .bold(), ]) - .bg(Color::Indexed(args.colors.bar_bg_color)) + .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()) }; let cur_keywords = Line::from(if !app.bibiman.tag_list.selected_keywords.is_empty() { vec![ - Span::raw("Selected keywords: ").fg(Color::Indexed(args.colors.main_text_color)), + Span::raw("Selected keywords: ").fg(cfg + .colors + .as_ref() + .unwrap() + .main_text_color + .unwrap()), // Show all keywords in correct order if list is filtered // successively by multiple keywords Span::raw(app.bibiman.tag_list.selected_keywords.join(" → ")) @@ -454,7 +466,7 @@ pub fn render_file_info(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: } else { vec![Span::raw(" ")] }) - .bg(Color::Indexed(args.colors.bar_bg_color)); + .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()); // .render(keyword_area, buf); let item_count = Line::from( @@ -490,38 +502,42 @@ pub fn render_file_info(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: .to_string() }, ) - .fg(Color::Indexed(args.colors.main_text_color)) + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) .bold(), - Span::raw("/").fg(Color::Indexed(args.colors.main_text_color)), - Span::raw(app.bibiman.entry_table.entry_table_items.len().to_string()) - .fg(Color::Indexed(args.colors.main_text_color)), + Span::raw("/").fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()), + Span::raw(app.bibiman.entry_table.entry_table_items.len().to_string()).fg(cfg + .colors + .as_ref() + .unwrap() + .main_text_color + .unwrap()), ] } else { vec![Span::raw("No entries")] }, ) .right_aligned() - .bg(Color::Indexed(args.colors.bar_bg_color)); + .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()); frame.render_widget(file_info, file_area); frame.render_widget(cur_keywords, keyword_area); frame.render_widget(item_count, count_area); } -pub fn render_entrytable(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Rect) { +pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect: Rect) { let entry_box_selected_border_style: Style = - Style::new().fg(Color::Indexed(args.colors.highlight_text_color)); + Style::new().fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap()); let entry_box_selected_title_style: Style = Style::new() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::BOLD); let entry_box_unselected_border_style: Style = - Style::new().fg(Color::Indexed(args.colors.main_text_color)); + Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()); let entry_box_unselected_title_style: Style = Style::new() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::BOLD); let selected_table_col_style: Style = Style::new().add_modifier(Modifier::BOLD); let selectec_table_cell_style: Style = Style::new().add_modifier(Modifier::REVERSED); let entry_selected_row_style: Style = Style::new() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::BOLD) .add_modifier(Modifier::REVERSED); @@ -551,8 +567,8 @@ pub fn render_entrytable(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: let header_style = Style::default() .bold() - .fg(Color::Indexed(args.colors.main_text_color)) - .bg(Color::Indexed(args.colors.bar_bg_color)); + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) + .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()); let header = Row::new(vec![ Cell::from( @@ -576,9 +592,9 @@ pub fn render_entrytable(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: if let EntryTableColumn::Authors = app.bibiman.entry_table.entry_table_selected_column { - Color::Indexed(args.colors.selected_row_bg_color) + cfg.colors.as_ref().unwrap().selected_row_bg_color.unwrap() } else { - Color::Indexed(args.colors.bar_bg_color) + cfg.colors.as_ref().unwrap().bar_bg_color.unwrap() }, ), ), @@ -602,9 +618,9 @@ pub fn render_entrytable(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: .bg( if let EntryTableColumn::Title = app.bibiman.entry_table.entry_table_selected_column { - Color::Indexed(args.colors.selected_row_bg_color) + cfg.colors.as_ref().unwrap().selected_row_bg_color.unwrap() } else { - Color::Indexed(args.colors.bar_bg_color) + cfg.colors.as_ref().unwrap().bar_bg_color.unwrap() }, ), ), @@ -628,9 +644,9 @@ pub fn render_entrytable(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: .bg( if let EntryTableColumn::Year = app.bibiman.entry_table.entry_table_selected_column { - Color::Indexed(args.colors.selected_row_bg_color) + cfg.colors.as_ref().unwrap().selected_row_bg_color.unwrap() } else { - Color::Indexed(args.colors.bar_bg_color) + cfg.colors.as_ref().unwrap().bar_bg_color.unwrap() }, ), ), @@ -655,9 +671,9 @@ pub fn render_entrytable(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: if let EntryTableColumn::Pubtype = app.bibiman.entry_table.entry_table_selected_column { - Color::Indexed(args.colors.selected_row_bg_color) + cfg.colors.as_ref().unwrap().selected_row_bg_color.unwrap() } else { - Color::Indexed(args.colors.bar_bg_color) + cfg.colors.as_ref().unwrap().bar_bg_color.unwrap() }, ), ), @@ -672,23 +688,24 @@ pub fn render_entrytable(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: .entry_table_items .iter_mut() .enumerate() - .map(|(i, data)| { + .map(|(_i, data)| { let item = data.ref_vec(); item.into_iter() .map(|content| Cell::from(Text::from(content.to_string()))) .collect::() .style( - Style::new().fg(color_list( - args, - i as i32, - app.bibiman - .entry_table - .entry_table_state - .selected() - .unwrap_or(0) as i32, - args.colors.highlight_text_color, - 20, - )), + // Style::new().fg(color_list( + // args, + // i as i32, + // app.bibiman + // .entry_table + // .entry_table_state + // .selected() + // .unwrap_or(0) as i32, + // args.colors.highlight_text_color, + // 20, + // )), + Style::new().fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap()), ) .height(1) }); @@ -741,11 +758,11 @@ pub fn render_entrytable(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: } } -pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Rect) { +pub fn render_selected_item(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect: Rect) { // We get the info depending on the item's state. let style_value = Style::new() .bold() - .fg(Color::Indexed(args.colors.main_text_color)); + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()); let lines = { if app .bibiman @@ -767,7 +784,7 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re // Span::styled(cur_entry.authors.clone(), Style::new().green()), Span::styled( cur_entry.authors(), - Style::new().fg(Color::Indexed(args.colors.info_color)), + Style::new().fg(cfg.colors.as_ref().unwrap().info_color.unwrap()), ), ])); if cur_entry.subtitle.is_some() { @@ -776,19 +793,19 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re Span::styled( cur_entry.title(), Style::new() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::ITALIC), ), Span::styled( ": ", Style::new() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::ITALIC), ), Span::styled( cur_entry.subtitle(), Style::new() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::ITALIC), ), ])); @@ -798,7 +815,7 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re Span::styled( cur_entry.title(), Style::new() - .fg(Color::Indexed(args.colors.entry_color)) + .fg(cfg.colors.as_ref().unwrap().entry_color.unwrap()) .add_modifier(Modifier::ITALIC), ), ])); @@ -807,7 +824,7 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re Span::styled("Year: ", style_value), Span::styled( cur_entry.year(), - Style::new().fg(Color::Indexed(args.colors.keyword_color)), + Style::new().fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap()), ), ])); // Render keywords in info box in Markdown code style @@ -821,11 +838,13 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re let mut content = vec![Span::styled("Keywords: ", style_value)]; for k in kw { // Add half block highlighted in bg color to enlarge block - content.push(Span::raw("▐").fg(Color::Indexed(args.colors.bar_bg_color))); + content.push( + Span::raw("▐").fg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()), + ); content.push(Span::styled( k, Style::default() - .bg(Color::Indexed(args.colors.bar_bg_color)) + .bg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()) .fg( // Highlight selected keyword green if app @@ -837,11 +856,13 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re { Color::Green } else { - Color::Indexed(args.colors.main_text_color) + cfg.colors.as_ref().unwrap().main_text_color.unwrap() }, ), )); - content.push(Span::raw("▌").fg(Color::Indexed(args.colors.bar_bg_color))); + content.push( + Span::raw("▌").fg(cfg.colors.as_ref().unwrap().bar_bg_color.unwrap()), + ); } lines.push(Line::from(content)) } @@ -854,7 +875,7 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re Span::styled( cur_entry.doi_url(), Style::new() - .fg(Color::Indexed(args.colors.main_text_color)) + .fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()) .underlined(), ), ])); @@ -864,14 +885,14 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re Span::styled("File: ", style_value), Span::styled( cur_entry.filepath().to_string_lossy(), - Style::new().fg(Color::Indexed(args.colors.main_text_color)), + Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()), ), ])); } lines.push(Line::from("")); lines.push(Line::from(vec![Span::styled( cur_entry.abstract_text.clone(), - Style::new().fg(Color::Indexed(args.colors.main_text_color)), + Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()), )])); lines } else { @@ -888,7 +909,7 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re let block = Block::bordered() .title(Line::raw(" Entry Information ").centered().bold()) .border_set(symbols::border::PLAIN) - .border_style(Style::new().fg(Color::Indexed(args.colors.main_text_color))) + .border_style(Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap())) .padding(Padding::horizontal(1)); // INFO: '.line_count' method only possible with unstable-rendered-line-info feature -> API might change: https://github.com/ratatui/ratatui/issues/293#ref-pullrequest-2027056434 @@ -941,19 +962,19 @@ pub fn render_selected_item(app: &mut App, args: &CLIArgs, frame: &mut Frame, re frame.render_widget(item_info, rect); } -pub fn render_taglist(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Rect) { +pub fn render_taglist(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rect: Rect) { let keyword_box_selected_border_style: Style = - Style::new().fg(Color::Indexed(args.colors.highlight_text_color)); + Style::new().fg(cfg.colors.as_ref().unwrap().highlight_text_color.unwrap()); let keyword_box_selected_title_style: Style = Style::new() - .fg(Color::Indexed(args.colors.keyword_color)) + .fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap()) .add_modifier(Modifier::BOLD); let keyword_box_unselected_border_style: Style = - Style::new().fg(Color::Indexed(args.colors.main_text_color)); + Style::new().fg(cfg.colors.as_ref().unwrap().main_text_color.unwrap()); let keyword_box_unselected_title_style: Style = Style::new() - .fg(Color::Indexed(args.colors.keyword_color)) + .fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap()) .add_modifier(Modifier::BOLD); let keyword_selected_row_style: Style = Style::new() - .fg(Color::Indexed(args.colors.keyword_color)) + .fg(cfg.colors.as_ref().unwrap().keyword_color.unwrap()) .add_modifier(Modifier::BOLD) .add_modifier(Modifier::REVERSED); @@ -987,18 +1008,19 @@ pub fn render_taglist(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: Re .tag_list_items .iter() .enumerate() - .map(|(i, keyword)| { + .map(|(_i, keyword)| { ListItem::from(keyword.to_owned()).style(Style::new().fg( if app.bibiman.tag_list.tag_list_state.selected().is_some() { - color_list( - args, - i as i32, - app.bibiman.tag_list.tag_list_state.selected().unwrap() as i32, - args.colors.highlight_text_color, - 20, - ) + // color_list( + // args, + // i as i32, + // app.bibiman.tag_list.tag_list_state.selected().unwrap() as i32, + // args.colors.highlight_text_color, + // 20, + // ) + cfg.colors.as_ref().unwrap().highlight_text_color.unwrap() } else { - Color::Indexed(args.colors.main_text_color) + cfg.colors.as_ref().unwrap().main_text_color.unwrap() }, )) //.bg(color) }) -- cgit v1.2.3 From ff1208968e99dbd5906be449850203b554e02e17 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 24 Feb 2025 16:24:22 +0100 Subject: toc in readme --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 41ebdfc..d3b32e9 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ + + ## TL;DR `bibiman` is a simple terminal user interface for handling your BibLaTeX @@ -163,7 +165,8 @@ selected_row_bg_color = "237" # 256-color index selected_row_bg_color = "#3a3a3a" # HEX code ``` -To run `bibiman` with some default values for a light-colored terminal use the `--light-terminal` flag. +To run `bibiman` with some default values for a light-colored terminal use the +`--light-terminal` flag. ## Features @@ -228,9 +231,9 @@ enabled by default. You can use some special chars to alter pattern matching: ## Edit bib entry -The main editor can be set through the [config file](#values). Otherwise, the -environment variables `VISUAL` and `EDITOR` will be used in this order. The last -fallback solution is `vi`. +The main editor can be set through the [config file](#general-configuration). +Otherwise, the environment variables `VISUAL` and `EDITOR` will be used in this +order. The last fallback solution is `vi`. I've tested the following editors (set as value of `VISUAL` and through the config file): -- cgit v1.2.3 From aff7c398da005029a293178e487cf5323e507fb4 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 24 Feb 2025 16:26:27 +0100 Subject: toc in readme --- README.md | 55 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 18 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index d3b32e9..6907af4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
-# Bibiman +# Bibiman @@ -8,9 +8,28 @@
- - -## TL;DR + + +- [Bibiman](#bibiman) + - [TL;DR](#tldr) + - [Installation](#installation) + - [Usage](#usage) + - [Configuration](#configuration) + - [Location of Config File](#location-of-config-file) + - [General Configuration](#general-configuration) + - [Color Configuration](#color-configuration) + - [Features](#features) + - [Keybindings](#keybindings) + - [Search](#search) + - [Edit bib entry](#edit-bib-entry) + - [Open connected files or links](#open-connected-files-or-links) + - [Issues and code improvement](#issues-and-code-improvement) + - [Alternatives](#alternatives) + - [Comparison](#comparison) + + + +## TL;DR `bibiman` is a simple terminal user interface for handling your BibLaTeX database as part of a terminal-based scientific workflow. @@ -19,7 +38,7 @@ Here's a small impression how it looks and works: [![bibiman.gif](https://i.postimg.cc/d0Mb9vMY/bibiman.gif)](https://postimg.cc/zyj2JsXt) -## Installation +## Installation You can install `bibiman` directly from `crates.io` using `cargo`: @@ -43,7 +62,7 @@ cargo install --path=. --locked ``` -## Usage +## Usage The following arguments are possible: @@ -89,9 +108,9 @@ bibman tests/multi-files/ bibiman tests/biblatex-test.bib tests/multi-files/ ``` -## Configuration +## Configuration -### Location of Config File +### Location of Config File `bibiman` can be configured through a config file. The standard location is the user's config dir following the XDG scheme. On Linux systems this defaults to: @@ -111,7 +130,7 @@ which takes precedence over the standard one for the active session: bibiman --config-file="/path/to/temporary/config" ``` -### General Configuration +### General Configuration The following general values can be set through the config file: @@ -133,7 +152,7 @@ interface. If the `bibfiles` value is set *and* a further path (or multiple) is provided through the CLI call, the entries of all those files will be opened in the started `bibiman` session. -### Color Configuration +### Color Configuration Furthermore, it is now possible to customize the colors. The following values can be changed: @@ -168,7 +187,7 @@ selected_row_bg_color = "#3a3a3a" # HEX code To run `bibiman` with some default values for a light-colored terminal use the `--light-terminal` flag. -## Features +## Features These are the current features, the list will be updated: @@ -196,7 +215,7 @@ These are the current features, the list will be updated: **Please feel free to suggest further features through the issue functionality.** -## Keybindings +## Keybindings Use the following keybindings to manage the TUI: @@ -220,7 +239,7 @@ Use the following keybindings to manage the TUI: | `ESC` | Abort search / Reset current list | | `q`, `Ctrl-c` | Quit TUI | -## Search +## Search The search mode uses the `nucleo-matcher` crate. Thus, _fuzzy searching_ is enabled by default. You can use some special chars to alter pattern matching: @@ -229,7 +248,7 @@ enabled by default. You can use some special chars to alter pattern matching: - `...$` matches literally at end of the string. - `'...` matches literally everywhere in string. -## Edit bib entry +## Edit bib entry The main editor can be set through the [config file](#general-configuration). Otherwise, the environment variables `VISUAL` and `EDITOR` will be used in this @@ -253,7 +272,7 @@ While this behaviour is most likely supported on UNIX-based systems (Linux, MacOS), it might not work under Windows. I can't test it on a Windows machine, thus, there might be unexpected errors with it. -## Open connected files or links +## Open connected files or links `bibiman` also provides the possibility to open PDFs (as value of the `file` BibLaTeX field), as well as DOIs and URLs. @@ -269,12 +288,12 @@ Furthermore, DOIs have to begin with either `https://doi...` as full URL or `10.(...)` as regular DOI style. URLs work if they begin with either `http...` or with `www...`. -## Issues and code improvement +## Issues and code improvement This is my first Rust project and, thus, also a learning process. If you find any issues or code flaws, please open an issue. -## Alternatives +## Alternatives `bibiman` is a project tailored to my personal needs. I use a single main file for all my bib entries and want to use `bibiman` mainly as kind of @@ -301,7 +320,7 @@ Maybe one of these might fit _your_ personal needs better: - [papis](https://github.com/papis/papis): Powerful CLI tool for managing bibliographies and documents. Has also some TUI features. -### Comparison +### Comparison I compared `bibiman` only free-hand to `bibman` (Haskell) and `bibman` (Perl), since there is no simple benchmark test for TUIs. At least, I couldn't find one. -- cgit v1.2.3