From 656d4e0d9399a66ebf1e35da41710d5ac2ad8ef8 Mon Sep 17 00:00:00 2001 From: altsem Date: Wed, 19 Feb 2025 19:19:50 +0100 Subject: [PATCH] fix: rebase menu opening after closing Neovim It seems Neovim would write terminal codes to stderr. These were captured by Gitu and then printed back into the terminal as part of the result, triggering a sequence of key-press events to be read by Gitu, opening up the rebase menu. Yikes. relates to: https://github.com/altsem/gitu/issues/318 --- Cargo.lock | 19 +++++++++++++++++++ Cargo.toml | 1 + src/state.rs | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index f1b5731622..b2f197e54c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -687,6 +687,7 @@ dependencies = [ "serde", "similar", "simple-logging", + "strip-ansi-escapes", "temp-dir", "toml", "tree-sitter", @@ -1669,6 +1670,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strip-ansi-escapes" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a8f8038e7e7969abb3f1b7c2a811225e9296da208539e0f79c5251d6cac0025" +dependencies = [ + "vte", +] + [[package]] name = "strsim" version = "0.11.1" @@ -2115,6 +2125,15 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vte" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "231fdcd7ef3037e8330d8e17e61011a2c244126acc0a982f4040ac3f9f0bc077" +dependencies = [ + "memchr", +] + [[package]] name = "walkdir" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index 4d8ac82547..aac276117e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,3 +63,4 @@ tree-sitter-ocaml = "=0.20.4" tree-sitter-html = "=0.20.0" tree-sitter-elixir = "=0.1.1" regex = "1.11.1" +strip-ansi-escapes = "0.2.1" diff --git a/src/state.rs b/src/state.rs index 8c3b7919a4..447a527e03 100644 --- a/src/state.rs +++ b/src/state.rs @@ -322,7 +322,7 @@ impl State { let child = cmd.spawn()?; let out = child.wait_with_output()?; - let out_utf8 = String::from_utf8(out.stderr.clone()) + let out_utf8 = String::from_utf8(strip_ansi_escapes::strip(out.stderr.clone())) .expect("Error turning command output to String") .into();