diff options
| -rw-r--r-- | src/app.rs | 16 | ||||
| -rw-r--r-- | src/bibiman.rs | 47 | ||||
| -rw-r--r-- | tests/biblatex-test.bib | 12 | ||||
| -rw-r--r-- | tests/note-files/aristotle_poetics.txt | 1 | ||||
| -rw-r--r-- | tests/note-files/aristotle_rhetoric.md (renamed from tests/note-files/aristotle:poetics.txt) | 0 | ||||
| -rw-r--r-- | tests/pdf-files/annotated-pdfs/ARIStotle_rheTORIC.PDF (renamed from tests/pdf-files/annotated-pdfs/ARIStotle:rheTORIC.PDF) | bin | 25294 -> 25294 bytes | |||
| -rw-r--r-- | tests/pdf-files/aristotle:rhetoric.txt | 0 | ||||
| -rw-r--r-- | tests/pdf-files/aristotle_physics.pdf (renamed from tests/pdf-files/aristotle:physics.pdf) | bin | 25294 -> 25294 bytes | |||
| -rw-r--r-- | tests/pdf-files/aristotle_rhetoric.pdf (renamed from tests/pdf-files/aristotle:rhetoric.pdf) | bin | 25294 -> 25294 bytes | |||
| -rw-r--r-- | tests/pdf-files/aristotle_rhetoric.txt (renamed from tests/note-files/aristotle:rhetoric.md) | 0 |
10 files changed, 53 insertions, 23 deletions
@@ -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 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:poetics.txt b/tests/note-files/aristotle_rhetoric.md index e69de29..e69de29 100644 --- a/tests/note-files/aristotle:poetics.txt +++ b/tests/note-files/aristotle_rhetoric.md diff --git a/tests/pdf-files/annotated-pdfs/ARIStotle:rheTORIC.PDF b/tests/pdf-files/annotated-pdfs/ARIStotle_rheTORIC.PDF Binary files differindex 6aaba88..6aaba88 100644 --- a/tests/pdf-files/annotated-pdfs/ARIStotle:rheTORIC.PDF +++ b/tests/pdf-files/annotated-pdfs/ARIStotle_rheTORIC.PDF diff --git a/tests/pdf-files/aristotle:rhetoric.txt b/tests/pdf-files/aristotle:rhetoric.txt deleted file mode 100644 index e69de29..0000000 --- a/tests/pdf-files/aristotle:rhetoric.txt +++ /dev/null diff --git a/tests/pdf-files/aristotle:physics.pdf b/tests/pdf-files/aristotle_physics.pdf Binary files differindex 6aaba88..6aaba88 100644 --- a/tests/pdf-files/aristotle:physics.pdf +++ b/tests/pdf-files/aristotle_physics.pdf diff --git a/tests/pdf-files/aristotle:rhetoric.pdf b/tests/pdf-files/aristotle_rhetoric.pdf Binary files differindex 6aaba88..6aaba88 100644 --- a/tests/pdf-files/aristotle:rhetoric.pdf +++ b/tests/pdf-files/aristotle_rhetoric.pdf diff --git a/tests/note-files/aristotle:rhetoric.md b/tests/pdf-files/aristotle_rhetoric.txt index e69de29..e69de29 100644 --- a/tests/note-files/aristotle:rhetoric.md +++ b/tests/pdf-files/aristotle_rhetoric.txt |
