@@ -3,7 +3,6 @@ use anyhow::Result;
33use crossbeam_channel::{unbounded, Receiver, Sender};
44use crossterm::event::{self, Event};
55use std::{
6- process,
76 sync::{
87 atomic::{AtomicBool, Ordering},
98 Arc,
@@ -33,6 +32,7 @@ pub struct Input {
3332 desired_state: Arc<NotifyableMutex<bool>>,
3433 current_state: Arc<AtomicBool>,
3534 receiver: Receiver<InputEvent>,
35+ aborted: Arc<AtomicBool>,
3636}
3737
3838impl Input {
@@ -42,23 +42,26 @@ impl Input {
4242
4343 let desired_state = Arc::new(NotifyableMutex::new(true));
4444 let current_state = Arc::new(AtomicBool::new(true));
45+ let aborted = Arc::new(AtomicBool::new(false));
4546
4647 let arc_desired = Arc::clone(&desired_state);
4748 let arc_current = Arc::clone(¤t_state);
49+ let arc_aborted = Arc::clone(&aborted);
4850
4951 thread::spawn(move || {
5052 if let Err(e) =
5153 Self::input_loop(&arc_desired, &arc_current, &tx)
5254 {
5355 log::error!("input thread error: {}", e);
54- process::abort( );
56+ arc_aborted.store(true, Ordering::SeqCst );
5557 }
5658 });
5759
5860 Self {
5961 receiver: rx,
6062 desired_state,
6163 current_state,
64+ aborted,
6265 }
6366 }
6467
@@ -82,6 +85,10 @@ impl Input {
8285 != self.current_state.load(Ordering::Relaxed)
8386 }
8487
88+ pub fn is_aborted(&self) -> bool {
89+ self.aborted.load(Ordering::SeqCst)
90+ }
91+
8592 fn poll(dur: Duration) -> anyhow::Result<Option<Event>> {
8693 if event::poll(dur)? {
8794 Ok(Some(event::read()?))
0 commit comments