diff options
| author | lukeflo | 2024-11-24 00:36:11 +0100 |
|---|---|---|
| committer | lukeflo | 2024-11-24 00:36:11 +0100 |
| commit | 637c5b3e3447aeb7593ba82ef76e7367f1e62213 (patch) | |
| tree | 94b23af78e4f26f42824645181024c09715143a8 /src/tui/ui.rs | |
| parent | eef6fb840046bb939c7c68bb305e4574a7647f16 (diff) | |
| download | bibiman-637c5b3e3447aeb7593ba82ef76e7367f1e62213.tar.gz bibiman-637c5b3e3447aeb7593ba82ef76e7367f1e62213.zip | |
open correct file in editor, show file info
Diffstat (limited to 'src/tui/ui.rs')
| -rw-r--r-- | src/tui/ui.rs | 44 |
1 files changed, 34 insertions, 10 deletions
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