Skip to content

Commit

Permalink
refactor: exit application on SIGINT / C-c (#274)
Browse files Browse the repository at this point in the history
Fixes #272
alexpasmantier authored Jan 13, 2025

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent d68ae21 commit 1934d3f
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .config/config.toml
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ theme = "TwoDark"
# ------------------------
[keybindings.Channel]
# Quit the application
quit = "esc"
quit = ["esc", "ctrl-c"]
# Scrolling through entries
select_next_entry = ["down", "ctrl-n", "ctrl-j"]
select_prev_entry = ["up", "ctrl-p", "ctrl-k"]
7 changes: 5 additions & 2 deletions crates/television/event.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ use crossterm::event::{
KeyEvent, KeyEventKind, KeyModifiers,
};
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc;
use tokio::{signal, sync::mpsc};
use tracing::{debug, warn};

#[derive(Debug, Clone, Copy)]
@@ -160,7 +160,6 @@ impl EventLoop {
//let mut reader = crossterm::event::EventStream::new();
tokio::spawn(async move {
loop {
//let event = reader.next();
let delay = tokio::time::sleep(tick_interval);
let event_available = poll_event(tick_interval);

@@ -171,6 +170,10 @@ impl EventLoop {
tx.send(Event::Tick).unwrap_or_else(|_| warn!("Unable to send Tick event"));
break;
},
_ = signal::ctrl_c() => {
debug!("Received SIGINT");
tx.send(Event::Input(Key::Ctrl('c'))).unwrap_or_else(|_| warn!("Unable to send Ctrl-C event"));
},
// if `delay` completes, pass to the next event "frame"
() = delay => {
tx.send(Event::Tick).unwrap_or_else(|_| warn!("Unable to send Tick event"));

0 comments on commit 1934d3f

Please sign in to comment.