diff --git a/README.md b/README.md index d7b9397..28c5cbb 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ USAGE: ttyper [FLAGS] [OPTIONS] [contents] FLAGS: + --no-backtrack Enable no backtrack between words -d, --debug -h, --help Prints help information --list-languages List installed languages diff --git a/src/main.rs b/src/main.rs index 738eeab..8e68b02 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,6 +55,10 @@ struct Opt { /// List installed languages #[structopt(long)] list_languages: bool, + + /// Enable no backtrack between words + #[structopt(long)] + no_backtrack: bool, } impl Opt { @@ -215,9 +219,12 @@ fn main() -> crossterm::Result<()> { )?; terminal.clear()?; - let mut state = State::Test(Test::new(opt.gen_contents().expect( - "Couldn't get test contents. Make sure the specified language actually exists.", - ))); + let mut state = State::Test(Test::new( + opt.gen_contents().expect( + "Couldn't get test contents. Make sure the specified language actually exists.", + ), + !opt.no_backtrack, + )); state.render_into(&mut terminal, &config)?; loop { @@ -261,9 +268,12 @@ fn main() -> crossterm::Result<()> { modifiers: KeyModifiers::NONE, .. }) => { - state = State::Test(Test::new(opt.gen_contents().expect( + state = State::Test(Test::new( + opt.gen_contents().expect( "Couldn't get test contents. Make sure the specified language actually exists.", - ))); + ), + !opt.no_backtrack + )); } Event::Key(KeyEvent { code: KeyCode::Char('p'), @@ -280,7 +290,7 @@ fn main() -> crossterm::Result<()> { .flat_map(|w| vec![w.clone(); 5]) .collect(); practice_words.shuffle(&mut thread_rng()); - state = State::Test(Test::new(practice_words)); + state = State::Test(Test::new(practice_words, !opt.no_backtrack)); } Event::Key(KeyEvent { code: KeyCode::Char('q'), diff --git a/src/test/mod.rs b/src/test/mod.rs index f198786..dc33e2f 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -41,14 +41,16 @@ pub struct Test { pub words: Vec, pub current_word: usize, pub complete: bool, + pub backtracking_enabled: bool, } impl Test { - pub fn new(words: Vec) -> Self { + pub fn new(words: Vec, backtracking_enabled: bool) -> Self { Self { words: words.into_iter().map(TestWord::from).collect(), current_word: 0, complete: false, + backtracking_enabled, } } @@ -77,7 +79,7 @@ impl Test { } } KeyCode::Backspace => { - if word.progress.is_empty() { + if word.progress.is_empty() && self.backtracking_enabled { self.last_word(); } else { word.events.push(TestEvent {