Skip to content

Commit

Permalink
Added backspace options for enable/disable backspace between words
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrlmarn committed Sep 29, 2023
1 parent 9790d54 commit 9f58ee5
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:
--backspace Enable backspace 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 backspace between words
#[structopt(long)]
backspace: 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.backspace);
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, backspace: 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() && backspace {
self.last_word();
} else {
word.events.push(TestEvent {
Expand Down

0 comments on commit 9f58ee5

Please sign in to comment.