aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--src/app.rs89
-rw-r--r--src/bibiman.rs101
3 files changed, 78 insertions, 116 deletions
diff --git a/README.md b/README.md
index 7795e60..e00315e 100644
--- a/README.md
+++ b/README.md
@@ -64,6 +64,7 @@ my personal workflow. There are more to come, the list will be updated:
- [ ] **Add Entry via DOI** as formatted code.
- [ ] **Implement config file** for setting some default values like main
bibfile, PDF-opener, or editor
+- [ ] **Implement logging** of important processes
- [ ] **Support Hayagriva(`.yaml`)** format as input (_on hold for now_, because
the Hayagriva Yaml style doesn't offer keywords; s. issue in
[Hayagriva repo](https://github.com/typst/hayagriva/issues/240)).
@@ -142,8 +143,7 @@ or with `www...`.
## Issues and code improvement
This is my first Rust project and, thus, also a learning process. If you find
-any issues or code flaws, please open an issue. I plan to make PRs possible in
-the future when its a little bit less early alpha state.
+any issues or code flaws, please open an issue.
## Alternatives
diff --git a/src/app.rs b/src/app.rs
index 596420e..934a7b2 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -15,14 +15,15 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/////
-use crate::bibiman::{self, CurrentArea, FormerArea};
+use crate::bibiman::{CurrentArea, FormerArea};
+use color_eyre::eyre::{Context, Ok, Result};
// use super::Event;
use crate::cliargs::CLIArgs;
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::{Ok, Result};
+use std::process::{Command, Stdio};
use tui::Event;
use tui_input::backend::crossterm::EventHandler;
use tui_input::Input;
@@ -221,9 +222,30 @@ 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)?;
+ // Index of selected entry
+ let entry_idx = self
+ .bibiman
+ .entry_table
+ .entry_table_state
+ .selected()
+ .unwrap();
+
+ // Index of selected popup field
+ let popup_idx = self.bibiman.popup_area.popup_state.selected().unwrap();
+
+ // Choose ressource depending an selected popup field
+ if self.bibiman.popup_area.popup_list[popup_idx].contains("Weblink") {
+ let object = prepare_weblink(
+ self.bibiman.entry_table.entry_table_items[entry_idx].doi_url(),
+ );
+ open_connected_res(&object)?;
+ } else if self.bibiman.popup_area.popup_list[popup_idx].contains("File") {
+ let object =
+ self.bibiman.entry_table.entry_table_items[entry_idx].filepath();
+ open_connected_res(object)?;
+ } else {
+ eprintln!("Unable to find ressource to open");
+ };
// run command to open file/Url
self.bibiman.close_popup()
}
@@ -265,17 +287,19 @@ impl App {
.selected()
.unwrap();
let entry = self.bibiman.entry_table.entry_table_items[idx].clone();
- let mut items = vec![];
- if entry.doi_url.is_some() {
- items.push(entry.doi_url.unwrap())
- }
- if entry.filepath.is_some() {
- items.push(entry.filepath.unwrap())
+ if entry.filepath.is_some() || entry.doi_url.is_some() {
+ let mut items = vec![];
+ if entry.doi_url.is_some() {
+ items.push("Weblink (DOI/URL)".to_owned())
+ }
+ if entry.filepath.is_some() {
+ items.push("File (PDF/EPUB)".to_owned())
+ }
+ self.bibiman.popup_area.popup_selection(items);
+ self.bibiman.former_area = Some(FormerArea::EntryArea);
+ self.bibiman.current_area = CurrentArea::PopupArea;
+ self.bibiman.popup_area.popup_state.select(Some(0))
}
- self.bibiman.popup_area.popup_selection(items);
- self.bibiman.former_area = Some(FormerArea::EntryArea);
- self.bibiman.current_area = CurrentArea::PopupArea;
- self.bibiman.popup_area.popup_state.select(Some(0))
}
}
// match ressource {
@@ -302,3 +326,38 @@ impl App {
Ok(())
}
}
+
+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(())
+}
+
+pub fn prepare_weblink(url: &str) -> String {
+ if url.starts_with("10.") {
+ let prefix = "https://doi.org/".to_string();
+ prefix + url
+ } else if url.starts_with("www.") {
+ let prefix = "https://".to_string();
+ prefix + url
+ } else {
+ url.to_string()
+ }
+}
diff --git a/src/bibiman.rs b/src/bibiman.rs
index 0fde852..e65d5bc 100644
--- a/src/bibiman.rs
+++ b/src/bibiman.rs
@@ -15,7 +15,6 @@
// 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;
@@ -23,12 +22,11 @@ use crate::tui::popup::{PopupArea, PopupKind};
use crate::tui::Tui;
use crate::{bibiman::entries::EntryTable, bibiman::keywords::TagList};
use arboard::Clipboard;
-use color_eyre::eyre::{Context, Ok, Result};
-use core::panic;
+use color_eyre::eyre::{Ok, Result};
use editor_command::EditorBuilder;
use ratatui::widgets::ScrollbarState;
use std::path::PathBuf;
-use std::process::{Command, Stdio};
+use std::process::Command;
use tui_input::Input;
pub mod bibisetup;
@@ -383,78 +381,6 @@ impl Bibiman {
self.entry_table.entry_table_items.len(),
);
}
-
- // Open file connected with entry through 'file' or 'pdf' field
- 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
- .as_ref()
- .unwrap();
-
- // 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(filepath)
- .stdout(Stdio::null())
- .stderr(Stdio::null())
- .spawn()
- .wrap_err("Opening file not possible");
-
- Ok(())
- }
-
- 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
- .as_ref()
- .unwrap();
- // .clone();
-
- // Resolve strings using the resolving function of dx.doi.org, so the
- // terminal is not blocked by the resolving process
- let url = if web_adress.starts_with("10.") {
- let prefix = "https://doi.org/".to_string();
- prefix + web_adress
- } else if web_adress.starts_with("www.") {
- let prefix = "https://".to_string();
- prefix + web_adress
- } else {
- web_adress.to_string()
- };
-
- // Build command to execute browser. '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(url)
- .stdout(Stdio::null())
- .stderr(Stdio::null())
- .spawn()
- .wrap_err("Opening file not possible");
-
- Ok(())
- }
}
impl Bibiman {
@@ -646,26 +572,3 @@ 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(())
-}