diff options
| author | lukeflo | 2024-11-17 21:04:19 +0100 |
|---|---|---|
| committer | lukeflo | 2024-11-17 21:04:19 +0100 |
| commit | dc250eac78d3806f587c77a42735ae65e455b71f (patch) | |
| tree | f3395b32012c843dda732689808532c78ae8fc96 | |
| parent | 13bb655e3d63cf9e324ca055720d2fdb65e6b76e (diff) | |
| download | bibiman-dc250eac78d3806f587c77a42735ae65e455b71f.tar.gz bibiman-dc250eac78d3806f587c77a42735ae65e455b71f.zip | |
working selection popup, but ugly field values
| -rw-r--r-- | src/app.rs | 9 | ||||
| -rw-r--r-- | src/bibiman.rs | 35 | ||||
| -rw-r--r-- | src/tui/ui.rs | 2 |
3 files changed, 37 insertions, 9 deletions
@@ -15,7 +15,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. ///// -use crate::bibiman::{CurrentArea, FormerArea}; +use crate::bibiman::{self, CurrentArea, FormerArea}; // use super::Event; use crate::cliargs::CLIArgs; use crate::tui::commands::InputCmdAction; @@ -23,7 +23,6 @@ use crate::tui::popup::PopupKind; use crate::tui::{self, Tui}; use crate::{bibiman::Bibiman, tui::commands::CmdAction}; use color_eyre::eyre::{Ok, Result}; -use color_eyre::owo_colors::colors::css::LemonChiffon; use tui::Event; use tui_input::backend::crossterm::EventHandler; use tui_input::Input; @@ -222,6 +221,9 @@ impl App { if let Some(PopupKind::Help) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup(); } else if let Some(PopupKind::Selection) = self.bibiman.popup_area.popup_kind { + let idx = self.bibiman.popup_area.popup_state.selected().unwrap(); + let object = self.bibiman.popup_area.popup_list[idx].as_str(); + bibiman::open_connected_res(object)?; // run command to open file/Url self.bibiman.close_popup() } @@ -272,7 +274,8 @@ impl App { } self.bibiman.popup_area.popup_selection(items); self.bibiman.former_area = Some(FormerArea::EntryArea); - self.bibiman.current_area = CurrentArea::PopupArea + self.bibiman.current_area = CurrentArea::PopupArea; + self.bibiman.popup_area.popup_state.select(Some(0)) } } // match ressource { diff --git a/src/bibiman.rs b/src/bibiman.rs index 767dec1..0fde852 100644 --- a/src/bibiman.rs +++ b/src/bibiman.rs @@ -15,6 +15,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. ///// +use crate::app::App; use crate::bibiman::entries::EntryTableColumn; use crate::bibiman::{bibisetup::*, search::BibiSearch}; use crate::cliargs::CLIArgs; @@ -384,9 +385,12 @@ impl Bibiman { } // Open file connected with entry through 'file' or 'pdf' field - pub fn open_connected_file(&mut self) -> Result<()> { + pub fn open_connected_file(&self) -> Result<()> { let idx = self.entry_table.entry_table_state.selected().unwrap(); - let filepath = &self.entry_table.entry_table_items[idx].filepath.clone(); + let filepath = self.entry_table.entry_table_items[idx] + .filepath + .as_ref() + .unwrap(); // Build command to execute pdf-reader. 'xdg-open' is Linux standard let cmd = { @@ -401,7 +405,7 @@ impl Bibiman { // Pass filepath as argument, pipe stdout and stderr to /dev/null // to keep the TUI clean (where is it piped on Windows???) let _ = Command::new(&cmd) - .arg(filepath.as_ref().unwrap()) + .arg(filepath) .stdout(Stdio::null()) .stderr(Stdio::null()) .spawn() @@ -410,7 +414,7 @@ impl Bibiman { Ok(()) } - pub fn open_doi_url(&mut self) -> Result<()> { + pub fn open_doi_url(&self) -> Result<()> { let idx = self.entry_table.entry_table_state.selected().unwrap(); let web_adress = self.entry_table.entry_table_items[idx] .doi_url @@ -642,3 +646,26 @@ impl Bibiman { } } } + +pub fn open_connected_res(object: &str) -> Result<()> { + // Build command to execute pdf-reader. 'xdg-open' is Linux standard + let cmd = { + match std::env::consts::OS { + "linux" => String::from("xdg-open"), + "macos" => String::from("open"), + "windows" => String::from("start"), + _ => panic!("Couldn't detect OS for setting correct opener"), + } + }; + + // Pass filepath as argument, pipe stdout and stderr to /dev/null + // to keep the TUI clean (where is it piped on Windows???) + let _ = Command::new(&cmd) + .arg(object) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .spawn() + .wrap_err("Opening file not possible"); + + Ok(()) +} diff --git a/src/tui/ui.rs b/src/tui/ui.rs index daeba7f..ec0b412 100644 --- a/src/tui/ui.rs +++ b/src/tui/ui.rs @@ -239,8 +239,6 @@ pub fn render_popup(app: &mut App, frame: &mut Frame) { .block(block) .highlight_style(SELECTION_SELECTED_ROW_STYLE); - app.bibiman.popup_area.popup_state.select(Some(0)); - let popup_width = frame.area().width / 2; let popup_heigth = list.len() + 2; let popup_area = popup_area(frame.area(), popup_width, popup_heigth as u16); |
