@@ -3,7 +3,6 @@ use anyhow::Result;
3
3
use crossbeam_channel:: { unbounded, Receiver , Sender } ;
4
4
use crossterm:: event:: { self , Event } ;
5
5
use std:: {
6
- process,
7
6
sync:: {
8
7
atomic:: { AtomicBool , Ordering } ,
9
8
Arc ,
@@ -33,6 +32,7 @@ pub struct Input {
33
32
desired_state : Arc < NotifyableMutex < bool > > ,
34
33
current_state : Arc < AtomicBool > ,
35
34
receiver : Receiver < InputEvent > ,
35
+ aborted : Arc < AtomicBool > ,
36
36
}
37
37
38
38
impl Input {
@@ -42,23 +42,26 @@ impl Input {
42
42
43
43
let desired_state = Arc :: new ( NotifyableMutex :: new ( true ) ) ;
44
44
let current_state = Arc :: new ( AtomicBool :: new ( true ) ) ;
45
+ let aborted = Arc :: new ( AtomicBool :: new ( false ) ) ;
45
46
46
47
let arc_desired = Arc :: clone ( & desired_state) ;
47
48
let arc_current = Arc :: clone ( & current_state) ;
49
+ let arc_aborted = Arc :: clone ( & aborted) ;
48
50
49
51
thread:: spawn ( move || {
50
52
if let Err ( e) =
51
53
Self :: input_loop ( & arc_desired, & arc_current, & tx)
52
54
{
53
55
log:: error!( "input thread error: {}" , e) ;
54
- process :: abort ( ) ;
56
+ arc_aborted . store ( true , Ordering :: SeqCst ) ;
55
57
}
56
58
} ) ;
57
59
58
60
Self {
59
61
receiver : rx,
60
62
desired_state,
61
63
current_state,
64
+ aborted,
62
65
}
63
66
}
64
67
@@ -82,6 +85,10 @@ impl Input {
82
85
!= self . current_state . load ( Ordering :: Relaxed )
83
86
}
84
87
88
+ pub fn is_aborted ( & self ) -> bool {
89
+ self . aborted . load ( Ordering :: SeqCst )
90
+ }
91
+
85
92
fn poll ( dur : Duration ) -> anyhow:: Result < Option < Event > > {
86
93
if event:: poll ( dur) ? {
87
94
Ok ( Some ( event:: read ( ) ?) )
0 commit comments