diff options
| -rw-r--r-- | README.md | 28 | ||||
| -rw-r--r-- | src/tui/ui.rs | 44 |
2 files changed, 56 insertions, 16 deletions
@@ -35,14 +35,30 @@ cargo install --path=. --locked ## Usage -You need to pass a single `.bib` file as first positional argument: +`bibiman` needs bibfiles (with `.bib` extension) passed as positional arguments. +You can pass a single file, multiple files, the path of a directory containing +bibfiles, or mix files and directories. -`bibiman /path/to/bibfile.bib` +Directories will be searched recursively for files with the `.bib` extension and +add them to the entry list. Other files will be ignored.Thus, be careful not to +pass a directory with multiple subdirectories (like eg `/home/usr/`), because +this could be to some delay while parsing GBs of data. -Of course, this can be aliased if you only use one main file. E.g. in -`.bashrc`/`.zshrc`: +The following are valid CLI calls to run `bibiman`: -`alias bibi=bibiman /path/to/bibfile.bib` +```bash +# single file +bibiman bibfile-1.bib + +# multiple files +bibiman bibfile-1.bib bibfile-2.bib + +# directory containing bibfiles +bibman /my/cool/library/ + +# mixed arguments +bibiman bibfile-1.bib /my/cool/library/ bibfile-2.bib +``` ## Features @@ -60,11 +76,11 @@ my personal workflow. There are more to come, the list will be updated: - [x] **Open related URL/DOI** with keypress. - [x] **Scrollbar** for better navigating. - [x] **Sort Entries** by each column (`Authors`, `Title`, `Year`, `Pubtype`) +- [x] **Load multiple files** into one session. - [ ] **Open related notes file** for specific entry. - [ ] **Add Entry via DOI** as formatted code. - [ ] **Implement config file** for setting some default values like main bibfile, PDF-opener, or editor -- [ ] **Implement logging** of important processes - [ ] **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)). diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 84a1c29..ddb9080 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -15,6 +15,8 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. ///// +use std::path::PathBuf; + use super::popup::PopupArea; use crate::bibiman::entries::EntryTableColumn; use crate::bibiman::{CurrentArea, FormerArea}; @@ -38,6 +40,7 @@ use ratatui::{ ScrollbarOrientation, Table, Wrap, }, }; +use walkdir::WalkDir; // Text colors const TEXT_FG_COLOR: Color = Color::Indexed(TEXT_FG_COLOR_INDEX); @@ -124,6 +127,23 @@ pub const fn color_list(list_item: i32, sel_item: i32, highlight: u8, max_diff: } } +fn count_files(files: &[PathBuf]) -> u16 { + let mut count = 0; + for f in files { + if f.is_file() { + count += 1 + } else if f.is_dir() { + for e in WalkDir::new(f) { + let f = e.unwrap().into_path(); + if f.is_file() && f.extension().unwrap() == "bib" { + count += 1 + } + } + } + } + count +} + pub fn render_ui(app: &mut App, args: &CLIArgs, frame: &mut Frame) { let [header_area, main_area, footer_area] = Layout::new( Direction::Vertical, @@ -347,16 +367,20 @@ pub fn render_file_info(app: &mut App, args: &CLIArgs, frame: &mut Frame, rect: .horizontal_margin(1) .areas(rect); - let file_info = Line::from(vec![ - Span::raw("File: ").bold(), - Span::raw( - // TODO: Only for testing! Need to replace with dir or files vec - args.fileargs[0].file_name().unwrap().to_string_lossy(), - ) - .bold(), - ]) - .bg(HEADER_FOOTER_BG); - // .render(file_area, buf); + let file_info = if args.fileargs.len() == 1 { + Line::from(vec![ + Span::raw("File: ").bold(), + Span::raw(args.fileargs[0].file_name().unwrap().to_string_lossy()).bold(), + ]) + .bg(HEADER_FOOTER_BG) + } else { + Line::from(vec![ + Span::raw("Multiple files (").bold(), + Span::raw(count_files(&args.fileargs).to_string()).bold(), + Span::raw(")"), + ]) + .bg(HEADER_FOOTER_BG) + }; let cur_keywords = Line::from(if !app.bibiman.tag_list.selected_keywords.is_empty() { vec