summaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorMichael Davis2023-06-05 13:27:57 +0000
committerGitHub2023-06-05 13:27:57 +0000
commit428d33ab504cea9b66404356c6fe12fbbdc4db7d (patch)
tree537b6d4ec1e4bae944dc0a0b52ea25cd872dc5b8 /helix-term/src
parentd5707a4696af0c63ec350791501440e7d0adc036 (diff)
Exit gracefully on termination signals (#7236)
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/application.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 0ea31413..7e968482 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -231,8 +231,14 @@ impl Application {
#[cfg(windows)]
let signals = futures_util::stream::empty();
#[cfg(not(windows))]
- let signals = Signals::new([signal::SIGTSTP, signal::SIGCONT, signal::SIGUSR1])
- .context("build signal handler")?;
+ let signals = Signals::new([
+ signal::SIGTSTP,
+ signal::SIGCONT,
+ signal::SIGUSR1,
+ signal::SIGTERM,
+ signal::SIGINT,
+ ])
+ .context("build signal handler")?;
let app = Self {
compositor,
@@ -318,7 +324,9 @@ impl Application {
biased;
Some(signal) = self.signals.next() => {
- self.handle_signals(signal).await;
+ if !self.handle_signals(signal).await {
+ return false;
+ };
}
Some(event) = input_stream.next() => {
self.handle_terminal_events(event).await;
@@ -442,10 +450,12 @@ impl Application {
#[cfg(windows)]
// no signal handling available on windows
- pub async fn handle_signals(&mut self, _signal: ()) {}
+ pub async fn handle_signals(&mut self, _signal: ()) -> bool {
+ true
+ }
#[cfg(not(windows))]
- pub async fn handle_signals(&mut self, signal: i32) {
+ pub async fn handle_signals(&mut self, signal: i32) -> bool {
match signal {
signal::SIGTSTP => {
self.restore_term().unwrap();
@@ -499,8 +509,14 @@ impl Application {
self.refresh_config();
self.render().await;
}
+ signal::SIGTERM | signal::SIGINT => {
+ self.restore_term().unwrap();
+ return false;
+ }
_ => unreachable!(),
}
+
+ true
}
pub async fn handle_idle_timeout(&mut self) {