diff options
| author | Jonas Maier <> | 2026-04-20 00:02:30 +0200 |
|---|---|---|
| committer | Jonas Maier <> | 2026-04-20 00:02:35 +0200 |
| commit | 8fa52302ae6d0cb15daff9384f43744d4201d8ee (patch) | |
| tree | 5c786d87b70d8f9a6244db77271997ddeb730b61 /src/main.rs | |
| parent | 8fe815e4c1e70e6774ebfa30ff8c50e86f72a2c1 (diff) | |
| download | pish-8fa52302ae6d0cb15daff9384f43744d4201d8ee.tar.gz | |
ctrl+delete
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 5e1d847..9286653 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,6 +88,8 @@ pub struct Session { path_cache: PathCache, ctrlc: CtrlC, + debug_keystrokes: bool, + /// n before end of history.len() /// 0 == not checking history history_visit: usize, @@ -252,6 +254,23 @@ impl Session { cursor::move_cursor(Direction::Right, self.line.all_right()); io::stdout().flush().unwrap(); } + + fn del_right_word(&mut self) { + let mut del = 0; + while let Some(x) = self.line.get_right() + && x == b' ' + { + self.line.del_right(); + del += 1; + } + while let Some(x) = self.line.get_right() + && x != b' ' + { + self.line.del_right(); + del += 1; + } + self.line.display_post(&vec![b' '; del]); + } } fn read1() -> u8 { @@ -285,6 +304,7 @@ fn event_loop() { aliases: run::Aliases::new(), path_cache: Default::default(), ctrlc: Default::default(), + debug_keystrokes: false, }; print!("{}", se.prompt()); @@ -303,6 +323,9 @@ fn event_loop() { }; let mut se = session.lock().unwrap(); + if se.debug_keystrokes { + println!("{}", buf.escape_ascii()); + } match buf[0] { // Ctrl+A @@ -351,8 +374,8 @@ fn event_loop() { Err((crate::parse::ParseError::Eof, _)) => { se.line.add(b'\n'); print!("\r\n> "); - continue - }, + continue; + } Err(e) => { println!("{e:?}\n{}", se.prompt()); continue; @@ -413,6 +436,10 @@ fn event_loop() { seq.push(read1()); } + if se.debug_keystrokes { + println!("escape: {}", seq.escape_ascii()); + } + match seq[1] { b'A' => { // up @@ -484,6 +511,13 @@ fn event_loop() { _ => todo!("escape characters {}", seq[1..].escape_ascii()), } + } else { + if se.debug_keystrokes { + println!("escape: {}", seq.escape_ascii()); + } + if seq[0] == b'd' { + se.del_right_word(); + } } } |
