From fdfbf550144ef69ecc6003760fbb39466ec08637 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 29 Jun 2025 12:26:27 +0200 Subject: Some basic function rewriting for matching different file types --- tests/note_files/augustine.md | 8 ++++++++ tests/note_files/betram.txt | 1 + tests/pdf-files/aristotle:rhetoric.txt | 0 3 files changed, 9 insertions(+) create mode 100644 tests/note_files/augustine.md create mode 100644 tests/note_files/betram.txt create mode 100644 tests/pdf-files/aristotle:rhetoric.txt (limited to 'tests') diff --git a/tests/note_files/augustine.md b/tests/note_files/augustine.md new file mode 100644 index 0000000..7af8fa6 --- /dev/null +++ b/tests/note_files/augustine.md @@ -0,0 +1,8 @@ +--- +title: Notes about Augustine +author: Great scholar +--- + +# Augustine + +A crazy dude writing some interesting stuff diff --git a/tests/note_files/betram.txt b/tests/note_files/betram.txt new file mode 100644 index 0000000..54d31e5 --- /dev/null +++ b/tests/note_files/betram.txt @@ -0,0 +1 @@ +A simple text file with notes about this Betram dude diff --git a/tests/pdf-files/aristotle:rhetoric.txt b/tests/pdf-files/aristotle:rhetoric.txt new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 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/note-files/augustine.md | 8 ++++++++ tests/note-files/betram.txt | 1 + tests/note_files/augustine.md | 8 -------- tests/note_files/betram.txt | 1 - tests/test-config.toml | 8 +++++++- 5 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 tests/note-files/augustine.md create mode 100644 tests/note-files/betram.txt delete mode 100644 tests/note_files/augustine.md delete mode 100644 tests/note_files/betram.txt (limited to 'tests') diff --git a/tests/note-files/augustine.md b/tests/note-files/augustine.md new file mode 100644 index 0000000..7af8fa6 --- /dev/null +++ b/tests/note-files/augustine.md @@ -0,0 +1,8 @@ +--- +title: Notes about Augustine +author: Great scholar +--- + +# Augustine + +A crazy dude writing some interesting stuff diff --git a/tests/note-files/betram.txt b/tests/note-files/betram.txt new file mode 100644 index 0000000..54d31e5 --- /dev/null +++ b/tests/note-files/betram.txt @@ -0,0 +1 @@ +A simple text file with notes about this Betram dude diff --git a/tests/note_files/augustine.md b/tests/note_files/augustine.md deleted file mode 100644 index 7af8fa6..0000000 --- a/tests/note_files/augustine.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: Notes about Augustine -author: Great scholar ---- - -# Augustine - -A crazy dude writing some interesting stuff 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 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') 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 b10615ade6bb2710cf6716f05cc496cb082d24ad Mon Sep 17 00:00:00 2001 From: lukeflo Date: Mon, 30 Jun 2025 10:43:38 +0200 Subject: opening notes in set editor --- src/app.rs | 16 +------ src/bibiman.rs | 47 +++++++++++++++++++-- tests/biblatex-test.bib | 12 +++--- tests/note-files/aristotle:poetics.txt | 0 tests/note-files/aristotle:rhetoric.md | 0 tests/note-files/aristotle_poetics.txt | 1 + tests/note-files/aristotle_rhetoric.md | 0 .../annotated-pdfs/ARIStotle:rheTORIC.PDF | Bin 25294 -> 0 bytes .../annotated-pdfs/ARIStotle_rheTORIC.PDF | Bin 0 -> 25294 bytes tests/pdf-files/aristotle:physics.pdf | Bin 25294 -> 0 bytes tests/pdf-files/aristotle:rhetoric.pdf | Bin 25294 -> 0 bytes tests/pdf-files/aristotle:rhetoric.txt | 0 tests/pdf-files/aristotle_physics.pdf | Bin 0 -> 25294 bytes tests/pdf-files/aristotle_rhetoric.pdf | Bin 0 -> 25294 bytes tests/pdf-files/aristotle_rhetoric.txt | 0 15 files changed, 53 insertions(+), 23 deletions(-) delete mode 100644 tests/note-files/aristotle:poetics.txt delete mode 100644 tests/note-files/aristotle:rhetoric.md create mode 100644 tests/note-files/aristotle_poetics.txt create mode 100644 tests/note-files/aristotle_rhetoric.md delete mode 100644 tests/pdf-files/annotated-pdfs/ARIStotle:rheTORIC.PDF create mode 100644 tests/pdf-files/annotated-pdfs/ARIStotle_rheTORIC.PDF delete mode 100644 tests/pdf-files/aristotle:physics.pdf delete mode 100644 tests/pdf-files/aristotle:rhetoric.pdf delete mode 100644 tests/pdf-files/aristotle:rhetoric.txt create mode 100644 tests/pdf-files/aristotle_physics.pdf create mode 100644 tests/pdf-files/aristotle_rhetoric.pdf create mode 100644 tests/pdf-files/aristotle_rhetoric.txt (limited to 'tests') diff --git a/src/app.rs b/src/app.rs index f015494..496896a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -18,6 +18,7 @@ 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::tui::commands::InputCmdAction; @@ -279,7 +280,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(cfg)?; + self.bibiman.open_connected_res(cfg, tui)?; } else if let Some(PopupKind::AppendToFile) = self.bibiman.popup_area.popup_kind { self.bibiman.append_entry_to_file(cfg)? @@ -423,19 +424,6 @@ 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 1f19b24..e1e97ed 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -30,11 +30,12 @@ use crossterm::event::KeyCode; use editor_command::EditorBuilder; use ratatui::widgets::ScrollbarState; use regex::Regex; +use std::ffi::OsStr; use std::fs::{self, read_to_string}; use std::fs::{File, OpenOptions}; use std::io::Write; use std::path::PathBuf; -use std::process::Command; +use std::process::{Command, Stdio}; use std::result::Result::Ok; use tui_input::Input; @@ -512,6 +513,46 @@ impl Bibiman { Ok(()) } + pub fn open_connected_note( + &mut self, + cfg: &BibiConfig, + tui: &mut Tui, + file: &OsStr, + ) -> 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()] + .citekey + .clone(); + + // Exit TUI to enter editor + tui.exit()?; + // Use VISUAL or EDITOR. Set "vi" as last fallback + let mut cmd: Command = EditorBuilder::new() + .source(cfg.general.editor.as_ref()) + .environment() + .source(Some("vi")) + .build() + .unwrap(); + // Prepare arguments to open file at specific line + let status = cmd.arg(file).status()?; + if !status.success() { + eprintln!("Spawning editor failed with status {}", status); + } + + // Enter TUI again + tui.enter()?; + tui.terminal.clear()?; + + // Update the database and the lists to show changes + // Self::update_lists(self, cfg); + + // Select entry which was selected before entering editor + self.select_entry_by_citekey(citekey); + + Ok(()) + } + pub fn add_entry(&mut self) { if let CurrentArea::EntryArea = self.current_area { self.former_area = Some(FormerArea::EntryArea); @@ -662,7 +703,7 @@ impl Bibiman { Ok(()) } - pub fn open_connected_res(&mut self, cfg: &BibiConfig) -> Result<()> { + pub fn open_connected_res(&mut self, cfg: &BibiConfig, tui: &mut Tui) -> Result<()> { // Index of selected entry let entry_idx = self.entry_table.entry_table_state.selected().unwrap(); @@ -696,7 +737,7 @@ impl Bibiman { let file = expand_home(&PathBuf::from(popup_entry.clone())); // let object: OsString = popup_entry.into(); if file.is_file() { - app::open_connected_note(cfg, &file.into_os_string())?; + self.open_connected_note(cfg, tui, &file.into_os_string())?; self.close_popup(); } else { self.open_popup( diff --git a/tests/biblatex-test.bib b/tests/biblatex-test.bib index 4071dcb..692375e 100644 --- a/tests/biblatex-test.bib +++ b/tests/biblatex-test.bib @@ -9,7 +9,7 @@ model of particle physics.}, } -@collection{matuz:doody, +@collection{matuz_doody, title = {Contemporary Literary Criticism}, year = {1990}, location = {Detroit}, @@ -54,7 +54,7 @@ field}, } -@book{aristotle:anima, +@book{aristotle_anima, title = {De Anima}, author = {Aristotle}, location = {Cambridge}, @@ -68,7 +68,7 @@ editor}}, } -@book{aristotle:physics, +@book{aristotle_physics, title = {Physics}, shorttitle = {Physics}, author = {Aristotle}, @@ -84,7 +84,7 @@ annotation = {A \texttt{book} entry with a \texttt{translator} field}, } -@book{aristotle:poetics, +@book{aristotle_poetics, title = {Poetics}, shorttitle = {Poetics}, author = {Aristotle}, @@ -100,7 +100,7 @@ editor} as well as a \texttt{series} field}, } -@mvbook{aristotle:rhetoric, +@mvbook{aristotle_rhetoric, title = {The Rhetoric of {Aristotle} with a commentary by the late {Edward Meredith Cope}}, shorttitle = {Rhetoric}, @@ -441,7 +441,7 @@ @string{pup = {Princeton University Press}} -@incollection{westfahl:space, +@incollection{westfahl_space, title = {The True Frontier}, author = {Westfahl, Gary}, pages = {55--65}, diff --git a/tests/note-files/aristotle:poetics.txt b/tests/note-files/aristotle:poetics.txt deleted file mode 100644 index e69de29..0000000 diff --git a/tests/note-files/aristotle:rhetoric.md b/tests/note-files/aristotle:rhetoric.md deleted file mode 100644 index e69de29..0000000 diff --git a/tests/note-files/aristotle_poetics.txt b/tests/note-files/aristotle_poetics.txt new file mode 100644 index 0000000..a156c76 --- /dev/null +++ b/tests/note-files/aristotle_poetics.txt @@ -0,0 +1 @@ +Here some very boring information regarding Aristotle 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/pdf-files/annotated-pdfs/ARIStotle:rheTORIC.PDF b/tests/pdf-files/annotated-pdfs/ARIStotle:rheTORIC.PDF deleted file mode 100644 index 6aaba88..0000000 Binary files a/tests/pdf-files/annotated-pdfs/ARIStotle:rheTORIC.PDF and /dev/null differ diff --git a/tests/pdf-files/annotated-pdfs/ARIStotle_rheTORIC.PDF b/tests/pdf-files/annotated-pdfs/ARIStotle_rheTORIC.PDF new file mode 100644 index 0000000..6aaba88 Binary files /dev/null and b/tests/pdf-files/annotated-pdfs/ARIStotle_rheTORIC.PDF differ diff --git a/tests/pdf-files/aristotle:physics.pdf b/tests/pdf-files/aristotle:physics.pdf deleted file mode 100644 index 6aaba88..0000000 Binary files a/tests/pdf-files/aristotle:physics.pdf and /dev/null differ diff --git a/tests/pdf-files/aristotle:rhetoric.pdf b/tests/pdf-files/aristotle:rhetoric.pdf deleted file mode 100644 index 6aaba88..0000000 Binary files a/tests/pdf-files/aristotle:rhetoric.pdf and /dev/null differ diff --git a/tests/pdf-files/aristotle:rhetoric.txt b/tests/pdf-files/aristotle:rhetoric.txt deleted file mode 100644 index e69de29..0000000 diff --git a/tests/pdf-files/aristotle_physics.pdf b/tests/pdf-files/aristotle_physics.pdf new file mode 100644 index 0000000..6aaba88 Binary files /dev/null and b/tests/pdf-files/aristotle_physics.pdf differ diff --git a/tests/pdf-files/aristotle_rhetoric.pdf b/tests/pdf-files/aristotle_rhetoric.pdf new file mode 100644 index 0000000..6aaba88 Binary files /dev/null and b/tests/pdf-files/aristotle_rhetoric.pdf differ diff --git a/tests/pdf-files/aristotle_rhetoric.txt b/tests/pdf-files/aristotle_rhetoric.txt new file mode 100644 index 0000000..e69de29 -- 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') 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') 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 From e27069540a0bb22640974d0bd1a1bdf153b1b40d Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sat, 5 Jul 2025 22:32:41 +0200 Subject: succesfully tested note creation --- src/bibiman.rs | 1 + tests/note-files/doody.md | 0 2 files changed, 1 insertion(+) create mode 100644 tests/note-files/doody.md (limited to 'tests') diff --git a/src/bibiman.rs b/src/bibiman.rs index 71ac831..87963dc 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -774,6 +774,7 @@ impl Bibiman { File::create_new(new_file).unwrap(); self.close_popup(); + self.update_lists(cfg); Ok(()) } diff --git a/tests/note-files/doody.md b/tests/note-files/doody.md new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3