Skip to content

Commit

Permalink
allow quitting via ctrl+c
Browse files Browse the repository at this point in the history
coloradocolby committed May 2, 2022
1 parent 20980db commit 172b809
Showing 3 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "thokr"
description = "a sleek typing tui written in rust"
version = "0.2.0"
version = "0.3.0"
readme = "README.md"
repository = "https://github.com/coloradocolby/thokr.git"
homepage = "https://github.com/coloradocolby/thokr"
55 changes: 32 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ mod util;
use crate::{lang::Language, thok::Thok};
use clap::{ArgEnum, ErrorKind, IntoApp, Parser};
use crossterm::{
event::{self, Event, KeyCode, KeyEvent},
event::{self, Event, KeyCode, KeyEvent, KeyModifiers},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
tty::IsTty,
@@ -183,31 +183,40 @@ fn start_tui<B: Backend>(
exit_type = ExitType::New;
break;
}
KeyCode::Char(c) => match app.thok.has_finished() {
false => {
app.thok.write(c);
if app.thok.has_finished() {
app.thok.calc_results();
}
KeyCode::Char(c) => {
if key.modifiers.contains(KeyModifiers::CONTROL)
&& key.code == KeyCode::Char('c')
// ctrl+c to quit
{
break;
}
true => match key.code {
KeyCode::Char('t') => {
if Browser::is_available() {
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))
.unwrap_or_default();

match app.thok.has_finished() {
false => {
app.thok.write(c);
if app.thok.has_finished() {
app.thok.calc_results();
}
}
KeyCode::Char('r') => {
exit_type = ExitType::Restart;
break;
}
KeyCode::Char('n') => {
exit_type = ExitType::New;
break;
}
_ => {}
},
},
true => match key.code {
KeyCode::Char('t') => {
if Browser::is_available() {
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))
.unwrap_or_default();
}
}
KeyCode::Char('r') => {
exit_type = ExitType::Restart;
break;
}
KeyCode::Char('n') => {
exit_type = ExitType::New;
break;
}
_ => {}
},
}
}
_ => {}
}
terminal.draw(|f| ui(app, f))?;

0 comments on commit 172b809

Please sign in to comment.