Skip to content

Commit 72cf7c5

Browse files
author
Chiranjeevi U
committed
fix(input): handle Ctrl+C via SIGINT signal instead of keypress
1 parent d71b7a9 commit 72cf7c5

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ chrono = "0.4"
3131
clap-verbosity-flag = "3.0.3"
3232
clap = { version = "4.5.41", features = ["derive"] }
3333
crossterm = "0.29.0"
34+
ctrlc = "3.4"
3435
derive_more = { version = "2.0.1", features = ["debug"] }
3536
eyre = "0.6.12"
3637
itertools = "0.14.0"

src/main.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ where
9696
let cumulative_time = Arc::new(RwLock::new(Duration::new(0, 0)));
9797
let table_cycle_offset = Arc::new(AtomicUsize::new(0));
9898

99+
// handle SIGINT properly instead of as a keypress
100+
// see https://github.com/imsnif/bandwhich/issues/487
101+
{
102+
let running = running.clone();
103+
ctrlc::set_handler(move || {
104+
running.store(false, Ordering::Release);
105+
})
106+
.expect("failed to set SIGINT handler");
107+
}
108+
99109
let mut active_threads = vec![];
100110

101111
let terminal_events = os_input.terminal_events;
@@ -192,12 +202,6 @@ where
192202
);
193203
}
194204
Event::Key(KeyEvent {
195-
modifiers: KeyModifiers::CONTROL,
196-
code: KeyCode::Char('c'),
197-
kind: KeyEventKind::Press,
198-
..
199-
})
200-
| Event::Key(KeyEvent {
201205
modifiers: KeyModifiers::NONE,
202206
code: KeyCode::Char('q'),
203207
kind: KeyEventKind::Press,

src/tests/cases/test_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use crate::{
2525
pub fn sleep_and_quit_events(sleep_num: usize) -> Box<TerminalEvents> {
2626
let events = iter::repeat_n(None, sleep_num)
2727
.chain([Some(Event::Key(KeyEvent::new(
28-
KeyCode::Char('c'),
29-
KeyModifiers::CONTROL,
28+
KeyCode::Char('q'),
29+
KeyModifiers::NONE,
3030
)))])
3131
.collect();
3232
Box::new(TerminalEvents::new(events))
@@ -37,8 +37,8 @@ pub fn sleep_resize_and_quit_events(sleep_num: usize) -> Box<TerminalEvents> {
3737
.chain([
3838
Some(Event::Resize(100, 100)),
3939
Some(Event::Key(KeyEvent::new(
40-
KeyCode::Char('c'),
41-
KeyModifiers::CONTROL,
40+
KeyCode::Char('q'),
41+
KeyModifiers::NONE,
4242
))),
4343
])
4444
.collect();

0 commit comments

Comments
 (0)