summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authororhun <orhun@archlinux.org>2021-06-02 23:50:01 +0300
committerorhun <orhun@archlinux.org>2021-06-02 23:50:01 +0300
commit6680296d36caadeee3eda129421ad06539fa5230 (patch)
treef4532568e6cc18a571c2acf043f461b799edc699
parenta3b2bec19df7df2878537c3133063072f5b1b242 (diff)
feat: Support xplr for file selection (closes #2)
-rw-r--r--src/app/handler.rs10
-rw-r--r--src/app/mod.rs3
-rw-r--r--src/app/util.rs22
3 files changed, 35 insertions, 0 deletions
diff --git a/src/app/handler.rs b/src/app/handler.rs
index 384a586..7df38ea 100644
--- a/src/app/handler.rs
+++ b/src/app/handler.rs
@@ -4,6 +4,7 @@ use crate::app::launcher::App;
use crate::app::mode::Mode;
use crate::app::prompt::OutputType;
use crate::app::tab::Tab;
+use crate::app::util;
use crate::gpg::key::KeyType;
use crate::term::tui::Tui;
use crate::widget::row::ScrollDirection;
@@ -375,6 +376,15 @@ fn handle_command_execution<B: Backend>(
Ok(Mode::Visual) => tui.disable_mouse_capture()?,
_ => {}
}
+ } else if option == "prompt" && value == ":import " {
+ tui.toggle_pause()?;
+ toggle_pause = true;
+ match util::run_xplr() {
+ Ok(files) => {
+ command = Command::ImportKeys(files, false);
+ }
+ Err(e) => println!("{:?}", e),
+ }
}
}
Command::ExportKeys(_, _)
diff --git a/src/app/mod.rs b/src/app/mod.rs
index 2014757..35e0d63 100644
--- a/src/app/mod.rs
+++ b/src/app/mod.rs
@@ -38,3 +38,6 @@ pub mod banner;
/// Application splash screen.
pub mod splash;
+
+/// Utilities.
+pub mod util;
diff --git a/src/app/util.rs b/src/app/util.rs
new file mode 100644
index 0000000..92e56c6
--- /dev/null
+++ b/src/app/util.rs
@@ -0,0 +1,22 @@
+use anyhow::{anyhow, Result};
+use std::process::{Command, Stdio};
+
+/// Runs [`xplr`] command and returns the selected files.
+///
+/// [`xplr`]: https://github.com/sayanarijit/xplr
+pub fn run_xplr() -> Result<Vec<String>> {
+ match Command::new("xplr").stdout(Stdio::piped()).spawn() {
+ Ok(child) => {
+ let output = child.wait_with_output()?;
+ if output.status.success() {
+ match String::from_utf8(output.stdout) {
+ Ok(s) => Ok(s.lines().map(String::from).collect()),
+ Err(e) => Err(anyhow!("UTF-8 error: {:?}", e)),
+ }
+ } else {
+ Err(anyhow!("xplr process exited with {:?}", output.status))
+ }
+ }
+ Err(e) => Err(anyhow!("cannot run xplr: {:?}", e)),
+ }
+}