Skip to content

Commit

Permalink
feat: handle alt+backspace for deleting current word
Browse files Browse the repository at this point in the history
  • Loading branch information
radlinskii committed Jul 27, 2023
1 parent af960a8 commit 6d60563
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,44 @@ impl<'a> Runner<'a> {
);
stdout.flush().unwrap();
}
Key::Alt(c) => {
// on alt + backspace delete current word
if c == '\x7F' {
let mut chars_to_delete = 0;
let mut found_non_space_char = false;
for c in self.actual_input.chars().rev() {
if c == ' ' && found_non_space_char {
break;
} else {
found_non_space_char = true;
}
chars_to_delete += 1;
}

for _ in 0..chars_to_delete {
print!("{}", termion::cursor::Left(1));
self.actual_input.pop();
print!("{}", termion::clear::AfterCursor);
}

print!(
"{}",
&self.expected_input.to_str()[self.actual_input.len()..]
);

print!(
"{}",
termion::cursor::Left(
self.expected_input.to_str()[self.actual_input.len()..]
.len()
.try_into()
.unwrap()
)
);

stdout.flush().unwrap();
}
}
Key::Ctrl('c') => {
break; // Exit the loop when the user presses Ctrl+C
}
Expand Down

0 comments on commit 6d60563

Please sign in to comment.