From 06991e6eee4c80f99c069ff1b928bcb2111b1c3d Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Mon, 2 Jan 2017 20:15:24 -0800 Subject: [PATCH] Better error message when xclip is not available Resolves #37. --- copypasta/src/x11.rs | 9 ++++++++- src/input.rs | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/copypasta/src/x11.rs b/copypasta/src/x11.rs index 3f64453c..32844753 100644 --- a/copypasta/src/x11.rs +++ b/copypasta/src/x11.rs @@ -45,7 +45,14 @@ impl ::std::error::Error for Error { impl ::std::fmt::Display for Error { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { match *self { - Error::Io(ref err) => write!(f, "error calling xclip: {}", err), + Error::Io(ref err) => { + match err.kind() { + io::ErrorKind::NotFound => { + write!(f, "Please install `xclip` to enable clipboard support") + }, + _ => write!(f, "error calling xclip: {}", err), + } + }, Error::Xclip(ref s) => write!(f, "error from xclip: {}", s), Error::Utf8(ref err) => write!(f, "error parsing xclip output: {}", err), } diff --git a/src/input.rs b/src/input.rs index 012163b8..61805071 100644 --- a/src/input.rs +++ b/src/input.rs @@ -151,7 +151,7 @@ impl Action { Clipboard::new() .and_then(|mut clipboard| clipboard.store_primary(buf)) .unwrap_or_else(|err| { - err_println!("Error storing selection to clipboard: {}", Red(err)); + err_println!("Error storing selection to clipboard. {}", Red(err)); }); } } @@ -170,7 +170,7 @@ impl Action { } }) .unwrap_or_else(|err| { - err_println!("Error loading data from clipboard {}", Red(err)); + err_println!("Error loading data from clipboard. {}", Red(err)); }); }, } @@ -278,7 +278,7 @@ impl<'a, N: Notify + 'a> Processor<'a, N> { Clipboard::new() .and_then(|mut clipboard| clipboard.store_selection(buf)) .unwrap_or_else(|err| { - err_println!("Error storing selection to clipboard: {}", Red(err)); + err_println!("Error storing selection to clipboard. {}", Red(err)); }); } }