From f15cd8c0a8f20f2fa6bb5bd465d23508b072ac63 Mon Sep 17 00:00:00 2001 From: shem Date: Sat, 15 Apr 2023 08:23:06 +0200 Subject: [PATCH 1/5] Fix crash on opening from suspend state (#6725) --- helix-term/src/application.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 4d28c8bed0c7..99acb745379f 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -471,7 +471,16 @@ impl Application { } } signal::SIGCONT => { - self.claim_term().await.unwrap(); + // Copy/Paste from same issue from neovim: + // https://github.com/neovim/neovim/issues/12322 + let mut retry_count = 10; + while retry_count > 0 { + match self.claim_term().await { + Ok(_) => break, + Err(_) => retry_count -= 1, + } + } + // redraw the terminal let area = self.terminal.size().expect("couldn't get terminal size"); self.compositor.resize(area); From d6d7ef60806d005f56018eb1b49a111dff8d8daa Mon Sep 17 00:00:00 2001 From: shem Date: Sat, 15 Apr 2023 22:00:10 +0200 Subject: [PATCH 2/5] Fix code style --- helix-term/src/application.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 99acb745379f..8cb4b862b05e 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -473,11 +473,9 @@ impl Application { signal::SIGCONT => { // Copy/Paste from same issue from neovim: // https://github.com/neovim/neovim/issues/12322 - let mut retry_count = 10; - while retry_count > 0 { - match self.claim_term().await { - Ok(_) => break, - Err(_) => retry_count -= 1, + for _ in 1..10 { + if self.claim_term().await.is_ok() { + break; } } From b1eb9878880e9c1d5b916443c12059afcaa4cc98 Mon Sep 17 00:00:00 2001 From: shem Date: Sat, 15 Apr 2023 23:06:01 +0200 Subject: [PATCH 3/5] revert using of the imperative code style. Add panic if couldn't set terminal raw mode --- helix-term/src/application.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 8cb4b862b05e..16bbdd81f3f6 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -440,6 +440,8 @@ impl Application { #[cfg(not(windows))] pub async fn handle_signals(&mut self, signal: i32) { + use core::panic; + match signal { signal::SIGTSTP => { self.restore_term().unwrap(); @@ -473,10 +475,16 @@ impl Application { signal::SIGCONT => { // Copy/Paste from same issue from neovim: // https://github.com/neovim/neovim/issues/12322 - for _ in 1..10 { + // https://github.com/neovim/neovim/pull/13084 + let mut retry_count = 10; + while retry_count > 0 { if self.claim_term().await.is_ok() { break; } + retry_count -= 1; + } + if retry_count == 0 { + panic!("couldn't set terminal raw mode"); } // redraw the terminal From 68abe5141af92a1cf091f04e866a7081bff26834 Mon Sep 17 00:00:00 2001 From: shem Date: Sun, 16 Apr 2023 21:35:56 +0200 Subject: [PATCH 4/5] remove redundant import of core::panic macros --- helix-term/src/application.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 16bbdd81f3f6..fdd55150b4ed 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -440,8 +440,6 @@ impl Application { #[cfg(not(windows))] pub async fn handle_signals(&mut self, signal: i32) { - use core::panic; - match signal { signal::SIGTSTP => { self.restore_term().unwrap(); From aac3662c23c70a674e2d020161d06222a6d35c41 Mon Sep 17 00:00:00 2001 From: shem Date: Sun, 16 Apr 2023 21:46:55 +0200 Subject: [PATCH 5/5] small refactoring --- helix-term/src/application.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index fdd55150b4ed..cda498e2fbbe 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -474,15 +474,12 @@ impl Application { // Copy/Paste from same issue from neovim: // https://github.com/neovim/neovim/issues/12322 // https://github.com/neovim/neovim/pull/13084 - let mut retry_count = 10; - while retry_count > 0 { - if self.claim_term().await.is_ok() { - break; + for retries in 1..=10 { + match self.claim_term().await { + Ok(()) => break, + Err(err) if retries == 10 => panic!("Failed to claim terminal: {}", err), + Err(_) => continue, } - retry_count -= 1; - } - if retry_count == 0 { - panic!("couldn't set terminal raw mode"); } // redraw the terminal