slightly nicer clipboard/open errors

pull/14/head
chris west 4 years ago
parent c40997f0cd
commit 708e95b640

@ -114,8 +114,6 @@ To enable just TLS support, or just Tor support, use `--features`:
- [ ] don't create new strings for every Line - [ ] don't create new strings for every Line
- [ ] catch SIGWINCH - [ ] catch SIGWINCH
- [ ] disable ctrl-c outside of raw mode (telnet) - [ ] disable ctrl-c outside of raw mode (telnet)
- [ ] xdg-open
- [ ] nicer error msg when there's no xclip/pbcopy
## bugs ## bugs

@ -62,10 +62,13 @@ pub fn copy_to_clipboard(data: &str) -> Result<()> {
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
let mut cmd = process::Command::new("xclip").args(&["-sel", "clip"]); let mut cmd = process::Command::new("xclip").args(&["-sel", "clip"]);
cmd.stdin(Stdio::piped()).spawn().and_then(|mut child| { cmd.stdin(Stdio::piped())
let child_stdin = child.stdin.as_mut().unwrap(); .spawn()
child_stdin.write_all(data.as_bytes()) .and_then(|mut child| {
}) let child_stdin = child.stdin.as_mut().unwrap();
child_stdin.write_all(data.as_bytes())
})
.map_err(|e| error!("Clipboard error: {}", e))
} }
/// Used to open non-Gopher URLs. /// Used to open non-Gopher URLs.
@ -76,15 +79,17 @@ pub fn open_external(url: &str) -> Result<()> {
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
let cmd = "xdg-open"; let cmd = "xdg-open";
let output = process::Command::new(cmd).arg(url).output()?; let output = process::Command::new(cmd)
.arg(url)
.output()
.map_err(|e| error!("`open` error: {}", e))?;
if output.stderr.is_empty() { if output.stderr.is_empty() {
Ok(()) Ok(())
} else { } else {
Err(error!( Err(error!(
"`open` error: {}", "`open` error: {}",
String::from_utf8(output.stderr) String::from_utf8_lossy(&output.stderr).trim_end()
.unwrap_or_else(|_| "?".into())
.trim_end()
)) ))
} }
} }

Loading…
Cancel
Save