diff --git a/src/lib.rs b/src/lib.rs index df58a83..c51ebb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,6 @@ pub mod colors; pub mod error; pub mod model; pub mod output_destination; -pub mod process; pub mod regexes; pub mod selection; pub mod tmux; diff --git a/src/process.rs b/src/process.rs deleted file mode 100644 index 5ef5825..0000000 --- a/src/process.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::process::Command; - -use crate::error::ParseError; - -/// Execute an arbitrary Unix command and return the stdout as a `String` if -/// successful. -pub fn execute(command: &str, args: &[&str]) -> Result { - let output = Command::new(command).args(args).output()?; - - if !output.status.success() { - let msg = String::from_utf8_lossy(&output.stderr); - return Err(ParseError::ProcessFailure(format!( - "Process failure: {} {}, error {}", - command, - args.join(" "), - msg - ))); - } - - Ok(String::from_utf8_lossy(&output.stdout).to_string()) -} diff --git a/src/tmux.rs b/src/tmux.rs index 529e74d..1649af1 100644 --- a/src/tmux.rs +++ b/src/tmux.rs @@ -5,7 +5,6 @@ use std::fmt; use std::str::FromStr; use crate::error::ParseError; -use crate::process; #[derive(Debug, PartialEq)] pub struct Pane { @@ -145,7 +144,7 @@ pub fn list_panes() -> Result, ParseError> { "#{pane_id}:#{?pane_in_mode,true,false}:#{pane_height}:#{scroll_position}:#{?pane_active,true,false}", ]; - let output = process::execute("tmux", &args)?; + let output = duct::cmd("tmux", &args).read()?; // Each call to `Pane::parse` returns a `Result`. All results // are collected into a Result, _>, thanks to `collect()`. @@ -165,9 +164,7 @@ pub fn list_panes() -> Result, ParseError> { /// # Example /// ```get_options("@copyrat-")``` pub fn get_options(prefix: &str) -> Result, ParseError> { - let args = vec!["show", "-g"]; - - let output = process::execute("tmux", &args)?; + let output = duct::cmd!("tmux", "show", "-g").read()?; let lines: Vec<&str> = output.split('\n').collect(); let pattern = format!(r#"{prefix}([\w\-0-9]+) "?(\w+)"?"#, prefix = prefix); @@ -223,16 +220,14 @@ pub fn capture_pane(pane: &Pane, region: &CaptureRegion) -> Result = args.split(' ').collect(); - let output = process::execute("tmux", &args)?; + let output = duct::cmd("tmux", &args).read()?; Ok(output) } /// Ask tmux to swap the current Pane with the target_pane (uses Tmux format). pub fn swap_pane_with(target_pane: &str) -> Result<(), ParseError> { // -Z: keep the window zoomed if it was zoomed. - let args = vec!["swap-pane", "-Z", "-s", target_pane]; - - process::execute("tmux", &args)?; + duct::cmd!("tmux", "swap-pane", "-Z", "-s", target_pane).run()?; Ok(()) } diff --git a/src/ui.rs b/src/ui.rs index 11ee285..bcc0d6d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -8,7 +8,7 @@ use sequence_trie::SequenceTrie; use termion::{self, color, cursor, event, style}; use crate::error::ParseError; -use crate::{colors, model, output_destination::OutputDestination, process, selection::Selection}; +use crate::{colors, model, output_destination::OutputDestination, selection::Selection}; pub struct Ui<'a> { model: &'a mut model::Model<'a>, @@ -493,8 +493,8 @@ impl<'a> Ui<'a> { event::Key::Char(_ch @ ' ') => { output_destination.toggle(); let message = format!("output destination: `{}`", output_destination); - let args = vec!["display-message", &message]; - process::execute("tmux", &args) + duct::cmd!("tmux", "display-message", &message) + .run() .expect("could not make tmux display the message."); continue; }