Skip to content

Commit 172b809

Browse files
committed
allow quitting via ctrl+c
1 parent 20980db commit 172b809

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "thokr"
33
description = "a sleek typing tui written in rust"
4-
version = "0.2.0"
4+
version = "0.3.0"
55
readme = "README.md"
66
repository = "https://github.com/coloradocolby/thokr.git"
77
homepage = "https://github.com/coloradocolby/thokr"

src/main.rs

+32-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod util;
66
use crate::{lang::Language, thok::Thok};
77
use clap::{ArgEnum, ErrorKind, IntoApp, Parser};
88
use crossterm::{
9-
event::{self, Event, KeyCode, KeyEvent},
9+
event::{self, Event, KeyCode, KeyEvent, KeyModifiers},
1010
execute,
1111
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
1212
tty::IsTty,
@@ -183,31 +183,40 @@ fn start_tui<B: Backend>(
183183
exit_type = ExitType::New;
184184
break;
185185
}
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;
192192
}
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();
198199
}
199200
}
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+
}
211220
_ => {}
212221
}
213222
terminal.draw(|f| ui(app, f))?;

0 commit comments

Comments
 (0)