summaryrefslogtreecommitdiffstats
path: root/src/clipboard.rs
diff options
context:
space:
mode:
authorLouis Bourque <louis@louisbourque.ca>2023-02-14 20:24:23 -0700
committerextrawurst <776816+extrawurst@users.noreply.github.com>2023-03-05 12:44:01 +0100
commit45bb8a71b5196a44cc8b8b7aad68026d407d6b0d (patch)
treee0533f7f01620730b2d90d1292f0dcf05bc46cb5 /src/clipboard.rs
parentf8e1c26309bcac6c9dea05e9625993def45826fd (diff)
Fix freeze on copy when xclip is installed on Linux
Diffstat (limited to 'src/clipboard.rs')
-rw-r--r--src/clipboard.rs17
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(())