diff --git a/README.md b/README.md index ffc5351..996410e 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ scoop install ttyper For usage instructions, you can run `ttyper --help`: ``` -ttyper 1.5.0 +ttyper 1.6.1 Terminal-based typing test. USAGE: @@ -62,6 +62,7 @@ FLAGS: --list-languages List installed languages --no-backtrack Disable backtracking to completed words --sudden-death Enable sudden death mode to restart on first error + --no-backspace Disable backspace -V, --version Prints version information OPTIONS: diff --git a/src/main.rs b/src/main.rs index e5d0110..258f480 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,6 +64,10 @@ struct Opt { /// Enable sudden death mode to restart on first error #[arg(long)] sudden_death: bool, + + /// Disable backspace + #[arg(long)] + no_backspace: bool, } impl Opt { @@ -231,7 +235,12 @@ fn main() -> io::Result<()> { )?; terminal.clear()?; - let mut state = State::Test(Test::new(contents, !opt.no_backtrack, opt.sudden_death)); + let mut state = State::Test(Test::new( + contents, + !opt.no_backtrack, + opt.sudden_death, + !opt.no_backspace, + )); state.render_into(&mut terminal, &config)?; loop { @@ -280,7 +289,8 @@ fn main() -> io::Result<()> { "Couldn't get test contents. Make sure the specified language actually exists.", ), !opt.no_backtrack, - opt.sudden_death + opt.sudden_death, + !opt.no_backspace, )); } Event::Key(KeyEvent { @@ -302,6 +312,7 @@ fn main() -> io::Result<()> { practice_words, !opt.no_backtrack, opt.sudden_death, + !opt.no_backspace, )); } Event::Key(KeyEvent { diff --git a/src/test/mod.rs b/src/test/mod.rs index 0780bb8..d6997cb 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -53,16 +53,23 @@ pub struct Test { pub complete: bool, pub backtracking_enabled: bool, pub sudden_death_enabled: bool, + pub backspace_enabled: bool, } impl Test { - pub fn new(words: Vec, backtracking_enabled: bool, sudden_death_enabled: bool) -> Self { + pub fn new( + words: Vec, + backtracking_enabled: bool, + sudden_death_enabled: bool, + backspace_enabled: bool, + ) -> Self { Self { words: words.into_iter().map(TestWord::from).collect(), current_word: 0, complete: false, backtracking_enabled, sudden_death_enabled, + backspace_enabled, } } @@ -96,9 +103,9 @@ impl Test { } } KeyCode::Backspace => { - if word.progress.is_empty() && self.backtracking_enabled { + if word.progress.is_empty() && self.backtracking_enabled && self.backspace_enabled { self.last_word(); - } else { + } else if self.backspace_enabled { word.events.push(TestEvent { time: Instant::now(), correct: Some(!word.text.starts_with(&word.progress[..])),