summaryrefslogtreecommitdiffstats
path: root/src/clipboard.rs
diff options
context:
space:
mode:
authorStephan Dilly <dilly.stephan@gmail.com>2020-10-11 00:23:20 +0200
committerGitHub <noreply@github.com>2020-10-11 00:23:20 +0200
commit0b97c545eda4eda450d670609d7f9cfbc0f9502e (patch)
tree895605fb01d82824b6e6c4bbe6b6f8c759cf3eed /src/clipboard.rs
parent62573b9d7a564d21ef8b7c1852ade2c46e0fe14e (diff)
cleanup clipboard and add to changelog (#325)
Diffstat (limited to 'src/clipboard.rs')
-rw-r--r--src/clipboard.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/clipboard.rs b/src/clipboard.rs
index 11bd04ef..6730ceb1 100644
--- a/src/clipboard.rs
+++ b/src/clipboard.rs
@@ -2,12 +2,11 @@ use anyhow::Result;
use std::io::Write;
use std::process::{Command, Stdio};
-fn execute_copy_command(
- command: &mut Command,
- string: &str,
-) -> Result<()> {
+fn execute_copy_command(command: Command, text: &str) -> Result<()> {
use anyhow::anyhow;
+ let mut command = command;
+
let mut process = command
.stdin(Stdio::piped())
.stdout(Stdio::null())
@@ -18,7 +17,7 @@ fn execute_copy_command(
.stdin
.as_mut()
.ok_or_else(|| anyhow!("`{:?}`", command))?
- .write_all(string.as_bytes())
+ .write_all(text.as_bytes())
.map_err(|e| anyhow!("`{:?}`: {}", command, e))?;
process
@@ -30,18 +29,17 @@ fn execute_copy_command(
#[cfg(target_os = "linux")]
pub fn copy_string(string: &str) -> Result<()> {
- execute_copy_command(
- Command::new("xclip").arg("-selection").arg("clipboard"),
- string,
- )
+ let mut cmd = Command::new("xclip");
+ cmd.arg("-selection").arg("clipboard");
+ execute_copy_command(cmd, string)
}
#[cfg(target_os = "macos")]
pub fn copy_string(string: &str) -> Result<()> {
- execute_copy_command(&mut Command::new("pbcopy"), string)
+ execute_copy_command(Command::new("pbcopy"), string)
}
#[cfg(windows)]
pub fn copy_string(string: &str) -> Result<()> {
- execute_copy_command(&mut Command::new("clip"), string)
+ execute_copy_command(Command::new("clip"), string)
}