diff options
| author | lukeflo | 2025-06-30 10:43:38 +0200 |
|---|---|---|
| committer | lukeflo | 2025-06-30 10:43:38 +0200 |
| commit | b10615ade6bb2710cf6716f05cc496cb082d24ad (patch) | |
| tree | a468b0766e1f3c32148e9eef5b8f0d75bf256fa8 /src/bibiman.rs | |
| parent | ae1667410b0a812fff8d464251548f23f88ae024 (diff) | |
| download | bibiman-b10615ade6bb2710cf6716f05cc496cb082d24ad.tar.gz bibiman-b10615ade6bb2710cf6716f05cc496cb082d24ad.zip | |
opening notes in set editor
Diffstat (limited to 'src/bibiman.rs')
| -rw-r--r-- | src/bibiman.rs | 47 |
1 files changed, 44 insertions, 3 deletions
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( |
