mirror of
https://github.com/xvxx/phetch
synced 2024-11-05 00:00:58 +00:00
slightly nicer clipboard/open errors
This commit is contained in:
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
|
||||
- [ ] catch SIGWINCH
|
||||
- [ ] disable ctrl-c outside of raw mode (telnet)
|
||||
- [ ] xdg-open
|
||||
- [ ] nicer error msg when there's no xclip/pbcopy
|
||||
|
||||
## bugs
|
||||
|
||||
|
21
src/utils.rs
21
src/utils.rs
@ -62,10 +62,13 @@ pub fn copy_to_clipboard(data: &str) -> Result<()> {
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let mut cmd = process::Command::new("xclip").args(&["-sel", "clip"]);
|
||||
|
||||
cmd.stdin(Stdio::piped()).spawn().and_then(|mut child| {
|
||||
let child_stdin = child.stdin.as_mut().unwrap();
|
||||
child_stdin.write_all(data.as_bytes())
|
||||
})
|
||||
cmd.stdin(Stdio::piped())
|
||||
.spawn()
|
||||
.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.
|
||||
@ -76,15 +79,17 @@ pub fn open_external(url: &str) -> Result<()> {
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
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() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(error!(
|
||||
"`open` error: {}",
|
||||
String::from_utf8(output.stderr)
|
||||
.unwrap_or_else(|_| "?".into())
|
||||
.trim_end()
|
||||
String::from_utf8_lossy(&output.stderr).trim_end()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user