diff options
| author | Jonas Maier <> | 2026-05-03 11:29:42 +0200 |
|---|---|---|
| committer | Jonas Maier <> | 2026-05-03 11:29:42 +0200 |
| commit | 110b179e3651570f6ede3090e2e8f304dac7024d (patch) | |
| tree | f8af54954d0845132d5ee3affed167b06fbc853e /src/main.rs | |
| parent | d5953e52f0df8ca6727e71fa07f147467a7369c1 (diff) | |
| download | pish-110b179e3651570f6ede3090e2e8f304dac7024d.tar.gz | |
keybinds seem to work somewhat
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 73 |
1 files changed, 22 insertions, 51 deletions
diff --git a/src/main.rs b/src/main.rs index f2b7544..a21b313 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,8 @@ -#![feature(unix_socket_ancillary_data, peer_credentials_unix_socket)] +#![feature( + unix_socket_ancillary_data, + peer_credentials_unix_socket, + associated_type_defaults +)] #![allow(clippy::needless_range_loop)] use std::collections::HashMap; @@ -81,7 +85,7 @@ pub struct Session { line: LineBuf, history: Vec<HistoryEntry>, prev_path: BString, - builtins: HashMap<BString, &'static dyn run::Builtin>, + builtins: HashMap<BString, &'static dyn run::BuiltinClone>, vars: HashMap<BString, BString>, funs: HashMap<BString, Block>, aliases: run::Aliases, @@ -214,6 +218,16 @@ impl Session { self.line.display_post(b" "); } + fn del_left_or_previous(&mut self) { + if self.line.is_empty() && !self.line.is_dirty() && !self.history.is_empty() { + // take previous command for editing + let cmd = self.history[self.history.len() - 1].cmd.clone(); + self.type_bytes(&cmd); + } else { + self.del_left(); + } + } + fn move_to_begin(&mut self) { cursor::move_cursor(Direction::Left, self.line.all_left()); io::stdout().flush().unwrap(); @@ -316,6 +330,11 @@ impl Session { se.reprint_prompt(); } } + + fn screen_clear(&mut self) { + clear_screen(); + self.reprint_prompt(); + } } fn exec_rc_file(se: Arc<Mutex<Session>>) { @@ -375,7 +394,7 @@ fn event_loop() { aliases: run::Aliases::new(), path_cache: Default::default(), ctrlc: Default::default(), - debug_keystrokes: true, + debug_keystrokes: false, loud: false, ti_keybinds: HashMap::new(), ascii_keybinds: HashMap::new(), @@ -488,47 +507,6 @@ fn event_loop() { /* match key { - Kb::CtrlA => se.move_to_begin(), - Kb::CtrlE => se.move_to_end(), - Kb::Eof | Kb::CtrlD => break, - Kb::CtrlL => { - clear_screen(); - print!("{}", se.prompt()); - io::stdout().write_all(&se.line.into_bytes()).unwrap(); - cursor::move_cursor(Direction::Left, se.line.distance_from_right_end()); - io::stdout().lock().flush().unwrap(); - } - Kb::CtrlR => { - println!(" search is not yet implemented"); - se.reprint_prompt(); - } - Kb::Key(b'\r' | b'\n') => { - let line = se.line.into_bytes(); - - if !line.is_empty() { - let parsed = match parse::do_parse(&line) { - Ok(p) => p, - Err((crate::parse::ParseError::Eof, _)) => { - se.line.add(b'\n'); - print!("\r\n> "); - continue; - } - Err(e) => { - println!("{e:?}\n{}", se.prompt()); - continue; - } - }; - print!("\r\n"); - let entry = HistoryEntry::new(line.clone()); - history::persist(&entry); - se.history.push(entry); - se.history_visit = 0; - se.line.dump(); - drop(se); - run::run(session.clone(), parsed); - } - } - Kb::Key(b'\t') => {} Kb::Arrow(dir) => match dir { Direction::Up => se.history_up(), Direction::Down => se.history_down(), @@ -554,13 +532,6 @@ fn event_loop() { } }, Kb::DeleteLeft => { - if se.line.is_empty() && !se.line.is_dirty() && !se.history.is_empty() { - // take previous command for editing - let cmd = se.history[se.history.len() - 1].cmd.clone(); - se.type_bytes(&cmd); - } else { - se.del_left(); - } } Kb::DeleteRight => se.del_right(), Kb::CtrlDeleteRight => se.del_right_word(), |
