From 2f76849512fd36dc7c49b6c20cc9c598739c9176 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 29 Jun 2025 12:28:57 +0200 Subject: some test files for bibnotes --- tests/test-config.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests/test-config.toml') diff --git a/tests/test-config.toml b/tests/test-config.toml index 6d05b64..fd39b29 100644 --- a/tests/test-config.toml +++ b/tests/test-config.toml @@ -19,7 +19,13 @@ file_prefix = "/some/path/prefix" ## Path to folder (with subfolders) containing PDF files with the basename ## of the format "citekey.pdf". Other PDF basenames are not accepted. ## Use absolute paths (~ for HOME works). Otherwise, loading might not work. -pdf_path = "~/Documents/coding/projects/bibiman/tests/pdf-files" +pdf_path = "tests/pdf-files" + +## Path to folder (with subfolders) containing note files with the basename of +## the format "citekey.extension". Other basenames are not accepted. The possible +## extensions can be set through the "note_extensions" array. +note_path = "tests/note-files" +note_extensions = [ "md", "txt" ] # [colors] ## Default values for dark-themed terminal -- cgit v1.2.3 From ae1667410b0a812fff8d464251548f23f88ae024 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 29 Jun 2025 20:31:41 +0200 Subject: some more tests for notes, need to elaborate function for opening notes --- src/app.rs | 22 +++++++++++++--------- src/bibiman.rs | 5 ++--- tests/note-files/aristotle:poetics.txt | 0 tests/note-files/aristotle:rhetoric.md | 0 tests/note-files/bertram.txt | 1 + tests/note-files/betram.txt | 1 - tests/test-config.toml | 2 +- 7 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 tests/note-files/aristotle:poetics.txt create mode 100644 tests/note-files/aristotle:rhetoric.md create mode 100644 tests/note-files/bertram.txt delete mode 100644 tests/note-files/betram.txt (limited to 'tests/test-config.toml') diff --git a/src/app.rs b/src/app.rs index 5f2d16b..f015494 100644 --- a/src/app.rs +++ b/src/app.rs @@ -410,15 +410,6 @@ impl App { pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard let cmd = &cfg.general.pdf_opener; - // If necessary, replace ~ with /home dir - // let file = if cfg.general.file_prefix.is_some() { - // cfg.general.file_prefix.clone().unwrap().join(file) - // } else { - // PathBuf::from(file) - // }; - // let file = PathBuf::from(file); - - // let file = expand_home(&file).into_os_string(); // Pass filepath as argument, pipe stdout and stderr to /dev/null // to keep the TUI clean (where is it piped on Windows???) @@ -432,6 +423,19 @@ pub fn open_connected_file(cfg: &BibiConfig, file: &OsStr) -> Result<()> { Ok(()) } +pub fn open_connected_note(cfg: &BibiConfig, file: &OsStr) -> Result<()> { + // let cmd = cfg.general.editor.as_ref().unwrap(); + + let _ = Command::new("xdg-open") + .arg(file) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + .wrap_err("Opening file not possible"); + + Ok(()) +} + pub fn open_connected_link(cfg: &BibiConfig, link: &str) -> Result<()> { // Build command to execute pdf-reader. 'xdg-open' is Linux standard let cmd = &cfg.general.url_opener; diff --git a/src/bibiman.rs b/src/bibiman.rs index 96a733c..1f19b24 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -692,12 +692,11 @@ impl Bibiman { None, )?; } - } - if self.popup_area.popup_list[popup_idx].0.contains("Note") { + } else if self.popup_area.popup_list[popup_idx].0.contains("Note") { let file = expand_home(&PathBuf::from(popup_entry.clone())); // let object: OsString = popup_entry.into(); if file.is_file() { - app::open_connected_file(cfg, &file.into_os_string())?; + app::open_connected_note(cfg, &file.into_os_string())?; self.close_popup(); } else { self.open_popup( diff --git a/tests/note-files/aristotle:poetics.txt b/tests/note-files/aristotle:poetics.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/note-files/aristotle:rhetoric.md b/tests/note-files/aristotle:rhetoric.md new file mode 100644 index 0000000..e69de29 diff --git a/tests/note-files/bertram.txt b/tests/note-files/bertram.txt new file mode 100644 index 0000000..54d31e5 --- /dev/null +++ b/tests/note-files/bertram.txt @@ -0,0 +1 @@ +A simple text file with notes about this Betram dude diff --git a/tests/note-files/betram.txt b/tests/note-files/betram.txt deleted file mode 100644 index 54d31e5..0000000 --- a/tests/note-files/betram.txt +++ /dev/null @@ -1 +0,0 @@ -A simple text file with notes about this Betram dude diff --git a/tests/test-config.toml b/tests/test-config.toml index fd39b29..99d1d00 100644 --- a/tests/test-config.toml +++ b/tests/test-config.toml @@ -4,7 +4,7 @@ bibfiles = [ "tests/biblatex-test.bib" ] ## Default editor to use when editing files. Arguments are possible -# editor = "vim" # with args: "vim -y" +editor = "vim" # with args: "vim -y" ## Default app to open PDFs/Epubs # pdf_opener = "xdg-open" -- cgit v1.2.3 From 614a20a12138f6691f8472b8c8657cf62b6730fb Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 30 Jun 2025 15:45:14 +0200 Subject: implemented symbols for attachements --- src/bibiman/bibisetup.rs | 42 +++++++++++++++++------------------ src/config.rs | 11 +++++++++ src/tui/ui.rs | 34 +++++++++++++++------------- tests/note-files/aristotle_physics.md | 0 tests/test-config.toml | 11 +++++++++ 5 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 tests/note-files/aristotle_physics.md (limited to 'tests/test-config.toml') diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index 61d1fcf..1f8a912 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -56,16 +56,16 @@ pub struct BibiData { pub file_field: bool, pub subtitle: Option, pub notes: Option>, - pub symbols: [String; 3], + pub symbols: [Option; 3], } #[derive(Debug, Clone, PartialEq)] -pub struct BibiRow { - pub authors: String, - pub title: String, - pub year: String, - pub pubtype: String, - pub symbols: [String; 3], +pub struct BibiRow<'a> { + pub authors: &'a str, + pub title: &'a str, + pub year: &'a str, + pub pubtype: &'a str, + pub symbols: &'a [Option; 3], } impl BibiData { @@ -104,15 +104,15 @@ impl BibiData { BibiRow { authors: { if self.short_author.is_empty() { - self.authors().to_string() + self.authors() } else { - self.short_author.clone() + &self.short_author } }, - title: self.title().to_string(), - year: self.year().to_string(), - pubtype: self.pubtype().to_string(), - symbols: self.symbols.clone(), + title: self.title(), + year: self.year(), + pubtype: self.pubtype(), + symbols: &self.symbols, } } @@ -160,22 +160,22 @@ impl BibiData { self.subtitle.as_ref().unwrap() } - fn create_symbols(&self, cfg: &BibiConfig) -> [String; 3] { + fn create_symbols(&self, cfg: &BibiConfig) -> [Option; 3] { [ if self.file_field || self.filepath.is_some() { - cfg.general.file_symbol.clone() + Some(cfg.general.file_symbol.clone()) } else { - " ".to_string() + None }, if self.doi_url.is_some() { - cfg.general.link_symbol.clone() + Some(cfg.general.link_symbol.clone()) } else { - " ".to_string() + None }, if self.notes.is_some() { - cfg.general.note_symbol.clone() + Some(cfg.general.note_symbol.clone()) } else { - " ".to_string() + None }, ] } @@ -294,7 +294,7 @@ impl BibiSetup { } else { None }, - symbols: [String::new(), String::new(), String::new()], + symbols: [None, None, None], } }) .collect() diff --git a/src/config.rs b/src/config.rs index 6723ce0..f67cb9d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -62,6 +62,11 @@ const DEFAULT_CONFIG: &str = r##" # note_path = "/path/to/notes/folder" # note_extensions = [ "md", "txt", "org" ] +## Symbols/chars to show if not has specific attachement +# note_symbol = "N" +# file_symbol = "F" +# link_symbol = "L" + # [colors] ## Default values for dark-themed terminal ## Possible values are: @@ -78,6 +83,12 @@ const DEFAULT_CONFIG: &str = r##" # bar_bg_color = "234" # popup_bg_color = "234" # selected_row_bg_color = "237" +# note_color = "123" +# file_color = "209" +# link_color = "27" +# author_color = "38" +# title_color = "37" +# year_color = "135" "##; /// Main struct of the config file. Contains substructs/headings in toml diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 970a71d..5904f88 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -701,25 +701,24 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec .map(|(_i, data)| { let item = data.ref_vec(cfg); + let mut symbol_vec = vec![]; + + if let Some(f) = &item.symbols[0] { + symbol_vec.push(Span::styled(f, Style::new().fg(cfg.colors.file_color))); + } + if let Some(l) = &item.symbols[1] { + symbol_vec.push(Span::styled(l, Style::new().fg(cfg.colors.link_color))); + } + if let Some(n) = &item.symbols[2] { + symbol_vec.push(Span::styled(n, Style::new().fg(cfg.colors.note_color))) + } + let row = Row::new(vec![ Cell::from(Line::from(item.authors)), Cell::from(Line::from(item.title)), Cell::from(Line::from(item.year)), Cell::from(Line::from(item.pubtype)), - Cell::from(Line::from(vec![ - Span::styled( - item.symbols[0].clone(), - Style::new().fg(cfg.colors.file_color), - ), - Span::styled( - item.symbols[1].clone(), - Style::new().fg(cfg.colors.link_color), - ), - Span::styled( - item.symbols[2].clone(), - Style::new().fg(cfg.colors.note_color), - ), - ])), + Cell::from(Line::from(symbol_vec)), ]); // let row = item @@ -751,7 +750,12 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec }, ), Constraint::Percentage(10), - Constraint::Length(4), + Constraint::Length( + (cfg.general.file_symbol.chars().count() + + cfg.general.link_symbol.chars().count() + + cfg.general.note_symbol.chars().count() + + 1) as u16, + ), ], ) .block(block) diff --git a/tests/note-files/aristotle_physics.md b/tests/note-files/aristotle_physics.md new file mode 100644 index 0000000..e69de29 diff --git a/tests/test-config.toml b/tests/test-config.toml index 99d1d00..51bd4e6 100644 --- a/tests/test-config.toml +++ b/tests/test-config.toml @@ -27,6 +27,11 @@ pdf_path = "tests/pdf-files" note_path = "tests/note-files" note_extensions = [ "md", "txt" ] +## Symbols/chars to show if not has specific attachement + file_symbol = " " + link_symbol = "󰌹 " + note_symbol = "󰧮" + # [colors] ## Default values for dark-themed terminal ## Possible values are: @@ -43,3 +48,9 @@ note_extensions = [ "md", "txt" ] # bar_bg_color = "234" # popup_bg_color = "234" # selected_row_bg_color = "237" +# note_color = "123" +# file_color = "209" +# link_color = "27" +# author_color = "38" +# title_color = "37" +# year_color = "135" -- cgit v1.2.3 From 9bd2f6fef0d835ffb97e18993161e6639c98d2d1 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 30 Jun 2025 21:49:53 +0200 Subject: align resource symbols, update README --- README.md | 2 ++ src/app.rs | 13 +++++++++---- src/bibiman.rs | 2 +- src/tui/ui.rs | 19 +++++++++++++++++-- tests/test-config.toml | 6 +++--- 5 files changed, 32 insertions(+), 10 deletions(-) (limited to 'tests/test-config.toml') diff --git a/README.md b/README.md index 4f0e505..ed620e8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ Here's a small impression how it looks and works: [![bibiman.gif](https://i.postimg.cc/Y0mCNDMg/bibiman.gif)](https://postimg.cc/ct0W0mK4) +![screenshot with new note feature](https://codeberg.org/attachments/69d35f36-cff3-43e5-8bfd-361064ba8ab2) + ## Installation ### Crates.io diff --git a/src/app.rs b/src/app.rs index 18a97e6..f912614 100644 --- a/src/app.rs +++ b/src/app.rs @@ -16,15 +16,14 @@ ///// use crate::bibiman::CurrentArea; -use crate::config::BibiConfig; -use color_eyre::eyre::{Context, Ok, Result}; -use editor_command::EditorBuilder; -// use super::Event; use crate::cliargs::CLIArgs; +use crate::config::BibiConfig; use crate::tui::commands::InputCmdAction; use crate::tui::popup::PopupKind; use crate::tui::{self, Tui}; use crate::{bibiman::Bibiman, tui::commands::CmdAction}; +use color_eyre::eyre::{Context, Ok, Result}; +use crossterm::event::KeyCode; use std::ffi::OsStr; use std::path::PathBuf; use std::process::{Command, Stdio}; @@ -84,6 +83,12 @@ impl App { self.bibiman.popup_area.popup_kind { self.bibiman.fast_selection(cfg, &mut tui, key_event.code)?; + // if a fast match char was used, restart event-loop. + // otherwise, the fast match char will be executed as command + match key_event.code { + KeyCode::Char('o' | 'l' | 'n' | 'y') => continue, + _ => {} + } } let command = if self.input_mode { CmdAction::Input(InputCmdAction::parse(key_event, &self.input)) diff --git a/src/bibiman.rs b/src/bibiman.rs index 9cc9280..f95bbc0 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -35,7 +35,7 @@ use std::fs::{self, read_to_string}; use std::fs::{File, OpenOptions}; use std::io::Write; use std::path::PathBuf; -use std::process::{Command, Stdio}; +use std::process::Command; use std::result::Result::Ok; use tui_input::Input; diff --git a/src/tui/ui.rs b/src/tui/ui.rs index 3c83935..be53f61 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -300,7 +300,7 @@ pub fn render_popup(app: &mut App, cfg: &BibiConfig, frame: &mut Frame) { }; let bottom_info = if let Some(PopupKind::OpenRes) = app.bibiman.popup_area.popup_kind { - " (j,k|↓,↑) ━ (o,l) ━ (ENTER) ━ (ESC) ".bold() + " (j,k|↓,↑) ━ (o,l,n) ━ (ENTER) ━ (ESC) ".bold() } else if let Some(PopupKind::YankItem) = app.bibiman.popup_area.popup_kind { " (j,k|↓,↑) ━ (y) ━ (ENTER) ━ (ESC) ".bold() } else { @@ -580,7 +580,7 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec .bg(cfg.colors.bar_bg_color); let header = Row::new(vec![ - Cell::from(Line::from("")).bg(cfg.colors.bar_bg_color), + Cell::from(Line::from("Res.")).bg(cfg.colors.bar_bg_color), Cell::from( Line::from(vec![{ Span::raw("Author") }, { if let Some(EntryTableColumn::Authors) = @@ -703,23 +703,38 @@ pub fn render_entrytable(app: &mut App, cfg: &BibiConfig, frame: &mut Frame, rec let mut symbol_vec = vec![]; + // use default or custom symbols for resources + // if an entry has no, replace it with the correct number + // of whitespace to align the symbols correct if let Some(f) = &item.symbols[0] { symbol_vec.push(Span::styled( f, Style::new().fg(cfg.colors.file_color).bold(), )); + } else { + symbol_vec.push(Span::raw( + " ".repeat(cfg.general.file_symbol.chars().count()), + )); } if let Some(l) = &item.symbols[1] { symbol_vec.push(Span::styled( l, Style::new().fg(cfg.colors.link_color).bold(), )); + } else { + symbol_vec.push(Span::raw( + " ".repeat(cfg.general.link_symbol.chars().count()), + )); } if let Some(n) = &item.symbols[2] { symbol_vec.push(Span::styled( n, Style::new().fg(cfg.colors.note_color).bold(), )) + } else { + symbol_vec.push(Span::raw( + " ".repeat(cfg.general.note_symbol.chars().count()), + )); } let row = Row::new(vec![ diff --git a/tests/test-config.toml b/tests/test-config.toml index 51bd4e6..1d29043 100644 --- a/tests/test-config.toml +++ b/tests/test-config.toml @@ -28,9 +28,9 @@ note_path = "tests/note-files" note_extensions = [ "md", "txt" ] ## Symbols/chars to show if not has specific attachement - file_symbol = " " - link_symbol = "󰌹 " - note_symbol = "󰧮" +file_symbol = " " +link_symbol = "󰌹 " +note_symbol = "󰧮" # [colors] ## Default values for dark-themed terminal -- cgit v1.2.3