diff options
author | Stephan Dilly <dilly.stephan@gmail.com> | 2020-10-11 00:23:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-11 00:23:20 +0200 |
commit | 0b97c545eda4eda450d670609d7f9cfbc0f9502e (patch) | |
tree | 895605fb01d82824b6e6c4bbe6b6f8c759cf3eed /src/clipboard.rs | |
parent | 62573b9d7a564d21ef8b7c1852ade2c46e0fe14e (diff) |
cleanup clipboard and add to changelog (#325)
Diffstat (limited to 'src/clipboard.rs')
-rw-r--r-- | src/clipboard.rs | 20 |
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) } |