Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -302,6 +312,7 @@ fn main() -> io::Result<()> {
practice_words,
!opt.no_backtrack,
opt.sudden_death,
!opt.no_backspace,
));
}
Event::Key(KeyEvent {
Expand Down
13 changes: 10 additions & 3 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, backtracking_enabled: bool, sudden_death_enabled: bool) -> Self {
pub fn new(
words: Vec<String>,
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,
}
}

Expand Down Expand Up @@ -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[..])),
Expand Down
Loading