Skip to content

Commit

Permalink
Added --no-backtrack options for no backtrack between words
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrlmarn authored and max-niederman committed Sep 30, 2023
1 parent 5b33304 commit dbbd7e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -248,7 +252,7 @@ fn main() -> crossterm::Result<()> {
match state {
State::Test(ref mut test) => {
if let Event::Key(key) = event {
test.handle_key(key);
test.handle_key(key, opt.no_backtrack);
if test.complete {
state = State::Results(Results::from(&*test));
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Test {
}
}

pub fn handle_key(&mut self, key: KeyEvent) {
pub fn handle_key(&mut self, key: KeyEvent, no_backtrack: bool) {
if key.kind != KeyEventKind::Press {
return;
}
Expand All @@ -77,7 +77,7 @@ impl Test {
}
}
KeyCode::Backspace => {
if word.progress.is_empty() {
if word.progress.is_empty() && !no_backtrack {
self.last_word();
} else {
word.events.push(TestEvent {
Expand Down

0 comments on commit dbbd7e2

Please sign in to comment.