diff options
| author | sigoden <sigoden@gmail.com> | 2023-10-26 21:12:02 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-26 21:12:02 +0800 |
| commit | ca0f6343f22257fbcf4cf22ce622e75bb60a93bd (patch) | |
| tree | 104808bf750561990f8e6ff9690641d8fbe601a0 /src/repl/init.rs | |
| parent | b3f8f27018b1bbb3c1eb59ef05acc2d2a420b45e (diff) | |
| download | aichat-ca0f6343f22257fbcf4cf22ce622e75bb60a93bd.tar.gz | |
feat: add .edit command for multi-line editing (#151)
Diffstat (limited to 'src/repl/init.rs')
| -rw-r--r-- | src/repl/init.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/repl/init.rs b/src/repl/init.rs index 1204fa7..9cef4e5 100644 --- a/src/repl/init.rs +++ b/src/repl/init.rs @@ -32,15 +32,12 @@ impl Repl { let edit_mode: Box<dyn EditMode> = if config.read().vi_keybindings { let mut normal_keybindings = default_vi_normal_keybindings(); let mut insert_keybindings = default_vi_insert_keybindings(); - Self::add_menu_keybindings(&mut normal_keybindings); - Self::add_menu_keybindings(&mut insert_keybindings); - Self::add_clear_keybindings(&mut normal_keybindings); - Self::add_clear_keybindings(&mut insert_keybindings); + Self::extra_keybindings(&mut normal_keybindings); + Self::extra_keybindings(&mut insert_keybindings); Box::new(Vi::new(insert_keybindings, normal_keybindings)) } else { let mut keybindings = default_emacs_keybindings(); - Self::add_menu_keybindings(&mut keybindings); - Self::add_clear_keybindings(&mut keybindings); + Self::extra_keybindings(&mut keybindings); Box::new(Emacs::new(keybindings)) }; let mut editor = Reedline::create() @@ -67,7 +64,7 @@ impl Repl { completer } - fn add_menu_keybindings(keybindings: &mut Keybindings) { + fn extra_keybindings(keybindings: &mut Keybindings) { keybindings.add_binding( KeyModifiers::NONE, KeyCode::Tab, @@ -76,14 +73,16 @@ impl Repl { ReedlineEvent::MenuNext, ]), ); - } - - fn add_clear_keybindings(keybindings: &mut Keybindings) { keybindings.add_binding( KeyModifiers::CONTROL, KeyCode::Char('l'), ReedlineEvent::ExecuteHostCommand(".clear screen".into()), ); + keybindings.add_binding( + KeyModifiers::CONTROL, + KeyCode::Char('s'), + ReedlineEvent::Submit, + ); } fn create_menu() -> ReedlineMenu { |
