diff options
author | Louis Bourque <louis@louisbourque.ca> | 2023-02-14 20:24:23 -0700 |
---|---|---|
committer | extrawurst <776816+extrawurst@users.noreply.github.com> | 2023-03-05 12:44:01 +0100 |
commit | 45bb8a71b5196a44cc8b8b7aad68026d407d6b0d (patch) | |
tree | e0533f7f01620730b2d90d1292f0dcf05bc46cb5 /src/clipboard.rs | |
parent | f8e1c26309bcac6c9dea05e9625993def45826fd (diff) |
Fix freeze on copy when xclip is installed on Linux
Diffstat (limited to 'src/clipboard.rs')
-rw-r--r-- | src/clipboard.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/clipboard.rs b/src/clipboard.rs index 61170fe2..2d492701 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -8,6 +8,7 @@ fn exec_copy_with_args( command: &str, args: &[&str], text: &str, + pipe_stderr: bool, ) -> Result<()> { let binary = which(command) .ok() @@ -17,7 +18,11 @@ fn exec_copy_with_args( .args(args) .stdin(Stdio::piped()) .stdout(Stdio::null()) - .stderr(Stdio::piped()) + .stderr(if pipe_stderr { + Stdio::piped() + } else { + Stdio::null() + }) .spawn() .map_err(|e| anyhow!("`{:?}`: {}", command, e))?; @@ -45,7 +50,7 @@ fn exec_copy_with_args( } fn exec_copy(command: &str, text: &str) -> Result<()> { - exec_copy_with_args(command, &[], text) + exec_copy_with_args(command, &[], text, true) } #[cfg(all(target_family = "unix", not(target_os = "macos")))] @@ -58,10 +63,16 @@ pub fn copy_string(text: &str) -> Result<()> { "xclip", &["-selection", "clipboard"], text, + false, ) .is_err() { - return exec_copy_with_args("xsel", &["--clipboard"], text); + return exec_copy_with_args( + "xsel", + &["--clipboard"], + text, + true, + ); } Ok(()) |