File tree 9 files changed +12
-31
lines changed
9 files changed +12
-31
lines changed Original file line number Diff line number Diff line change @@ -119,9 +119,7 @@ fn run_app<B: Backend>(
119
119
loop {
120
120
terminal. draw ( |f| ui ( f, & app) ) ?;
121
121
122
- let timeout = tick_rate
123
- . checked_sub ( last_tick. elapsed ( ) )
124
- . unwrap_or_else ( || Duration :: from_secs ( 0 ) ) ;
122
+ let timeout = tick_rate. saturating_sub ( last_tick. elapsed ( ) ) ;
125
123
if crossterm:: event:: poll ( timeout) ? {
126
124
if let Event :: Key ( key) = event:: read ( ) ? {
127
125
if let KeyCode :: Char ( 'q' ) = key. code {
Original file line number Diff line number Diff line change @@ -125,9 +125,7 @@ fn run_app<B: Backend>(
125
125
loop {
126
126
terminal. draw ( |f| ui ( f, & app) ) ?;
127
127
128
- let timeout = tick_rate
129
- . checked_sub ( last_tick. elapsed ( ) )
130
- . unwrap_or_else ( || Duration :: from_secs ( 0 ) ) ;
128
+ let timeout = tick_rate. saturating_sub ( last_tick. elapsed ( ) ) ;
131
129
if crossterm:: event:: poll ( timeout) ? {
132
130
if let Event :: Key ( key) = event:: read ( ) ? {
133
131
if let KeyCode :: Char ( 'q' ) = key. code {
Original file line number Diff line number Diff line change @@ -50,9 +50,7 @@ fn run_app<B: Backend>(
50
50
loop {
51
51
terminal. draw ( |f| ui:: draw ( f, & mut app) ) ?;
52
52
53
- let timeout = tick_rate
54
- . checked_sub ( last_tick. elapsed ( ) )
55
- . unwrap_or_else ( || Duration :: from_secs ( 0 ) ) ;
53
+ let timeout = tick_rate. saturating_sub ( last_tick. elapsed ( ) ) ;
56
54
if crossterm:: event:: poll ( timeout) ? {
57
55
if let Event :: Key ( key) = event:: read ( ) ? {
58
56
if key. kind == KeyEventKind :: Press {
Original file line number Diff line number Diff line change 1
1
use std:: {
2
2
error:: Error ,
3
- io,
4
3
time:: { Duration , Instant } ,
5
4
} ;
6
5
@@ -32,19 +31,17 @@ fn run_app(
32
31
terminal : & mut Terminal < TermwizBackend > ,
33
32
mut app : App ,
34
33
tick_rate : Duration ,
35
- ) -> io :: Result < ( ) > {
34
+ ) -> Result < ( ) , Box < dyn Error > > {
36
35
let mut last_tick = Instant :: now ( ) ;
37
36
loop {
38
37
terminal. draw ( |f| ui:: draw ( f, & mut app) ) ?;
39
38
40
- let timeout = tick_rate
41
- . checked_sub ( last_tick. elapsed ( ) )
42
- . unwrap_or_else ( || Duration :: from_secs ( 0 ) ) ;
43
- if let Ok ( Some ( input) ) = terminal
39
+ let timeout = tick_rate. saturating_sub ( last_tick. elapsed ( ) ) ;
40
+ if let Some ( input) = terminal
44
41
. backend_mut ( )
45
42
. buffered_terminal_mut ( )
46
43
. terminal ( )
47
- . poll_input ( Some ( timeout) )
44
+ . poll_input ( Some ( timeout) ) ?
48
45
{
49
46
match input {
50
47
InputEvent :: Key ( key_code) => match key_code. key {
Original file line number Diff line number Diff line change @@ -98,9 +98,7 @@ fn input_handling(tx: mpsc::Sender<Event>) {
98
98
let mut last_tick = Instant :: now ( ) ;
99
99
loop {
100
100
// poll for tick rate duration, if no events, sent tick event.
101
- let timeout = tick_rate
102
- . checked_sub ( last_tick. elapsed ( ) )
103
- . unwrap_or_else ( || Duration :: from_secs ( 0 ) ) ;
101
+ let timeout = tick_rate. saturating_sub ( last_tick. elapsed ( ) ) ;
104
102
if crossterm:: event:: poll ( timeout) . unwrap ( ) {
105
103
match crossterm:: event:: read ( ) . unwrap ( ) {
106
104
crossterm:: event:: Event :: Key ( key) => tx. send ( Event :: Input ( key) ) . unwrap ( ) ,
Original file line number Diff line number Diff line change @@ -175,9 +175,7 @@ fn run_app<B: Backend>(
175
175
loop {
176
176
terminal. draw ( |f| ui ( f, & mut app) ) ?;
177
177
178
- let timeout = tick_rate
179
- . checked_sub ( last_tick. elapsed ( ) )
180
- . unwrap_or_else ( || Duration :: from_secs ( 0 ) ) ;
178
+ let timeout = tick_rate. saturating_sub ( last_tick. elapsed ( ) ) ;
181
179
if crossterm:: event:: poll ( timeout) ? {
182
180
if let Event :: Key ( key) = event:: read ( ) ? {
183
181
if key. kind == KeyEventKind :: Press {
Original file line number Diff line number Diff line change @@ -64,9 +64,7 @@ fn run_app<B: Backend>(
64
64
loop {
65
65
terminal. draw ( |f| ui ( f, & app) ) ?;
66
66
67
- let timeout = tick_rate
68
- . checked_sub ( last_tick. elapsed ( ) )
69
- . unwrap_or_else ( || Duration :: from_secs ( 0 ) ) ;
67
+ let timeout = tick_rate. saturating_sub ( last_tick. elapsed ( ) ) ;
70
68
if crossterm:: event:: poll ( timeout) ? {
71
69
if let Event :: Key ( key) = event:: read ( ) ? {
72
70
if let KeyCode :: Char ( 'q' ) = key. code {
Original file line number Diff line number Diff line change @@ -57,9 +57,7 @@ fn run_app<B: Backend>(
57
57
loop {
58
58
terminal. draw ( |f| ui ( f, & mut app) ) ?;
59
59
60
- let timeout = tick_rate
61
- . checked_sub ( last_tick. elapsed ( ) )
62
- . unwrap_or_else ( || Duration :: from_secs ( 0 ) ) ;
60
+ let timeout = tick_rate. saturating_sub ( last_tick. elapsed ( ) ) ;
63
61
if crossterm:: event:: poll ( timeout) ? {
64
62
if let Event :: Key ( key) = event:: read ( ) ? {
65
63
match key. code {
Original file line number Diff line number Diff line change @@ -109,9 +109,7 @@ fn run_app<B: Backend>(
109
109
loop {
110
110
terminal. draw ( |f| ui ( f, & app) ) ?;
111
111
112
- let timeout = tick_rate
113
- . checked_sub ( last_tick. elapsed ( ) )
114
- . unwrap_or_else ( || Duration :: from_secs ( 0 ) ) ;
112
+ let timeout = tick_rate. saturating_sub ( last_tick. elapsed ( ) ) ;
115
113
if crossterm:: event:: poll ( timeout) ? {
116
114
if let Event :: Key ( key) = event:: read ( ) ? {
117
115
if let KeyCode :: Char ( 'q' ) = key. code {
You can’t perform that action at this time.
0 commit comments