Skip to content

Commit 0c4b916

Browse files
committed
Add CLI arg to disable the backspace key
1 parent 00ca3ae commit 0c4b916

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ scoop install ttyper
5050
For usage instructions, you can run `ttyper --help`:
5151

5252
```
53-
ttyper 1.5.0
53+
ttyper 1.6.1
5454
Terminal-based typing test.
5555
5656
USAGE:
@@ -62,6 +62,7 @@ FLAGS:
6262
--list-languages List installed languages
6363
--no-backtrack Disable backtracking to completed words
6464
--sudden-death Enable sudden death mode to restart on first error
65+
--no-backspace Disable backspace
6566
-V, --version Prints version information
6667
6768
OPTIONS:

src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ struct Opt {
6464
/// Enable sudden death mode to restart on first error
6565
#[arg(long)]
6666
sudden_death: bool,
67+
68+
/// Disable backspace
69+
#[arg(long)]
70+
no_backspace: bool,
6771
}
6872

6973
impl Opt {
@@ -234,6 +238,7 @@ fn main() -> io::Result<()> {
234238
),
235239
!opt.no_backtrack,
236240
opt.sudden_death,
241+
!opt.no_backspace,
237242
));
238243

239244
state.render_into(&mut terminal, &config)?;
@@ -283,7 +288,8 @@ fn main() -> io::Result<()> {
283288
"Couldn't get test contents. Make sure the specified language actually exists.",
284289
),
285290
!opt.no_backtrack,
286-
opt.sudden_death
291+
opt.sudden_death,
292+
!opt.no_backspace,
287293
));
288294
}
289295
Event::Key(KeyEvent {
@@ -305,6 +311,7 @@ fn main() -> io::Result<()> {
305311
practice_words,
306312
!opt.no_backtrack,
307313
opt.sudden_death,
314+
!opt.no_backspace,
308315
));
309316
}
310317
Event::Key(KeyEvent {

src/test/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,23 @@ pub struct Test {
5353
pub complete: bool,
5454
pub backtracking_enabled: bool,
5555
pub sudden_death_enabled: bool,
56+
pub backspace_enabled: bool,
5657
}
5758

5859
impl Test {
59-
pub fn new(words: Vec<String>, backtracking_enabled: bool, sudden_death_enabled: bool) -> Self {
60+
pub fn new(
61+
words: Vec<String>,
62+
backtracking_enabled: bool,
63+
sudden_death_enabled: bool,
64+
backspace_enabled: bool,
65+
) -> Self {
6066
Self {
6167
words: words.into_iter().map(TestWord::from).collect(),
6268
current_word: 0,
6369
complete: false,
6470
backtracking_enabled,
6571
sudden_death_enabled,
72+
backspace_enabled,
6673
}
6774
}
6875

@@ -96,9 +103,9 @@ impl Test {
96103
}
97104
}
98105
KeyCode::Backspace => {
99-
if word.progress.is_empty() && self.backtracking_enabled {
106+
if word.progress.is_empty() && self.backtracking_enabled && self.backspace_enabled {
100107
self.last_word();
101-
} else {
108+
} else if self.backspace_enabled {
102109
word.events.push(TestEvent {
103110
time: Instant::now(),
104111
correct: Some(!word.text.starts_with(&word.progress[..])),

0 commit comments

Comments
 (0)