Fix freeze on copy when xclip is installed on Linux

This commit is contained in:
Louis Bourque 2023-02-14 20:24:23 -07:00 committed by extrawurst
parent f8e1c26309
commit 45bb8a71b5
2 changed files with 15 additions and 3 deletions

View file

@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* crash on branches popup in small terminal ([#1470](https://github.com/extrawurst/gitui/issues/1470)) * crash on branches popup in small terminal ([#1470](https://github.com/extrawurst/gitui/issues/1470))
* `edit` command duplication ([#1489](https://github.com/extrawurst/gitui/issues/1489)) * `edit` command duplication ([#1489](https://github.com/extrawurst/gitui/issues/1489))
* syntax errors in `key_bindings.ron` will be logged ([#1491](https://github.com/extrawurst/gitui/issues/1491)) * syntax errors in `key_bindings.ron` will be logged ([#1491](https://github.com/extrawurst/gitui/issues/1491))
* Fix UI freeze when copying with xclip installed on Linux ([#1497](https://github.com/extrawurst/gitui/issues/1497))
* commit hooks report "command not found" on Windows with wsl2 installed ([#1528](https://github.com/extrawurst/gitui/issues/1528)) * commit hooks report "command not found" on Windows with wsl2 installed ([#1528](https://github.com/extrawurst/gitui/issues/1528))
* crashes on entering submodules ([#1510](https://github.com/extrawurst/gitui/issues/1510)) * crashes on entering submodules ([#1510](https://github.com/extrawurst/gitui/issues/1510))
* fix race issue: revlog messages sometimes appear empty ([#1473](https://github.com/extrawurst/gitui/issues/1473)) * fix race issue: revlog messages sometimes appear empty ([#1473](https://github.com/extrawurst/gitui/issues/1473))

View file

@ -8,6 +8,7 @@ fn exec_copy_with_args(
command: &str, command: &str,
args: &[&str], args: &[&str],
text: &str, text: &str,
pipe_stderr: bool,
) -> Result<()> { ) -> Result<()> {
let binary = which(command) let binary = which(command)
.ok() .ok()
@ -17,7 +18,11 @@ fn exec_copy_with_args(
.args(args) .args(args)
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::null()) .stdout(Stdio::null())
.stderr(Stdio::piped()) .stderr(if pipe_stderr {
Stdio::piped()
} else {
Stdio::null()
})
.spawn() .spawn()
.map_err(|e| anyhow!("`{:?}`: {}", command, e))?; .map_err(|e| anyhow!("`{:?}`: {}", command, e))?;
@ -45,7 +50,7 @@ fn exec_copy_with_args(
} }
fn exec_copy(command: &str, text: &str) -> Result<()> { 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")))] #[cfg(all(target_family = "unix", not(target_os = "macos")))]
@ -58,10 +63,16 @@ pub fn copy_string(text: &str) -> Result<()> {
"xclip", "xclip",
&["-selection", "clipboard"], &["-selection", "clipboard"],
text, text,
false,
) )
.is_err() .is_err()
{ {
return exec_copy_with_args("xsel", &["--clipboard"], text); return exec_copy_with_args(
"xsel",
&["--clipboard"],
text,
true,
);
} }
Ok(()) Ok(())