@@ -6,7 +6,7 @@ mod util;
6
6
use crate :: { lang:: Language , thok:: Thok } ;
7
7
use clap:: { ArgEnum , ErrorKind , IntoApp , Parser } ;
8
8
use crossterm:: {
9
- event:: { self , Event , KeyCode , KeyEvent } ,
9
+ event:: { self , Event , KeyCode , KeyEvent , KeyModifiers } ,
10
10
execute,
11
11
terminal:: { disable_raw_mode, enable_raw_mode, EnterAlternateScreen , LeaveAlternateScreen } ,
12
12
tty:: IsTty ,
@@ -183,31 +183,40 @@ fn start_tui<B: Backend>(
183
183
exit_type = ExitType :: New ;
184
184
break ;
185
185
}
186
- KeyCode :: Char ( c) => match app . thok . has_finished ( ) {
187
- false => {
188
- app . thok . write ( c ) ;
189
- if app . thok . has_finished ( ) {
190
- app . thok . calc_results ( ) ;
191
- }
186
+ KeyCode :: Char ( c) => {
187
+ if key . modifiers . contains ( KeyModifiers :: CONTROL )
188
+ && key . code == KeyCode :: Char ( 'c' )
189
+ // ctrl+c to quit
190
+ {
191
+ break ;
192
192
}
193
- true => match key. code {
194
- KeyCode :: Char ( 't' ) => {
195
- if Browser :: is_available ( ) {
196
- webbrowser:: open ( & format ! ( "https://twitter.com/intent/tweet?text={}%20wpm%20%2F%20{}%25%20acc%20%2F%20{:.2}%20sd%0A%0Ahttps%3A%2F%2Fgithub.com%2Fcoloradocolby%2Fthokr" , app. thok. wpm, app. thok. accuracy, app. thok. std_dev) )
197
- . unwrap_or_default ( ) ;
193
+
194
+ match app. thok . has_finished ( ) {
195
+ false => {
196
+ app. thok . write ( c) ;
197
+ if app. thok . has_finished ( ) {
198
+ app. thok . calc_results ( ) ;
198
199
}
199
200
}
200
- KeyCode :: Char ( 'r' ) => {
201
- exit_type = ExitType :: Restart ;
202
- break ;
203
- }
204
- KeyCode :: Char ( 'n' ) => {
205
- exit_type = ExitType :: New ;
206
- break ;
207
- }
208
- _ => { }
209
- } ,
210
- } ,
201
+ true => match key. code {
202
+ KeyCode :: Char ( 't' ) => {
203
+ if Browser :: is_available ( ) {
204
+ webbrowser:: open ( & format ! ( "https://twitter.com/intent/tweet?text={}%20wpm%20%2F%20{}%25%20acc%20%2F%20{:.2}%20sd%0A%0Ahttps%3A%2F%2Fgithub.com%2Fcoloradocolby%2Fthokr" , app. thok. wpm, app. thok. accuracy, app. thok. std_dev) )
205
+ . unwrap_or_default ( ) ;
206
+ }
207
+ }
208
+ KeyCode :: Char ( 'r' ) => {
209
+ exit_type = ExitType :: Restart ;
210
+ break ;
211
+ }
212
+ KeyCode :: Char ( 'n' ) => {
213
+ exit_type = ExitType :: New ;
214
+ break ;
215
+ }
216
+ _ => { }
217
+ } ,
218
+ }
219
+ }
211
220
_ => { }
212
221
}
213
222
terminal. draw ( |f| ui ( app, f) ) ?;
0 commit comments