feat: edit current prompt on $VISUAL/$EDITOR (#314)

pull/317/head
sigoden 3 months ago committed by GitHub
parent 179a5f5749
commit 373b34ef5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -170,6 +170,7 @@ The Chat REPL supports:
.exit Exit the REPL
Type ::: to begin multi-line editing, type ::: to end it.
Press Ctrl+O to open an editor to modify the current prompt.
Press Ctrl+C to abort readline, Ctrl+D to exit the REPL
```

@ -20,6 +20,7 @@ use reedline::{
ColumnarMenu, EditMode, Emacs, KeyCode, KeyModifiers, Keybindings, Reedline, ReedlineEvent,
ReedlineMenu, ValidationResult, Validator, Vi,
};
use std::{env, process};
const MENU_NAME: &str = "completion_menu";
@ -292,7 +293,7 @@ Type ".help" for more information.
let highlighter = ReplHighlighter::new(config);
let menu = Self::create_menu();
let edit_mode = Self::create_edit_mode(config);
let editor = Reedline::create()
let mut editor = Reedline::create()
.with_completer(Box::new(completer))
.with_highlighter(Box::new(highlighter))
.with_menu(menu)
@ -303,6 +304,13 @@ Type ".help" for more information.
.with_validator(Box::new(ReplValidator))
.with_ansi_colors(true);
if let Ok(cmd) = env::var("VISUAL").or_else(|_| env::var("EDITOR")) {
let temp_file =
env::temp_dir().join(format!("aichat-{}.txt", chrono::Utc::now().timestamp()));
let command = process::Command::new(cmd);
editor = editor.with_buffer_editor(command, temp_file);
}
Ok(editor)
}
@ -400,6 +408,7 @@ fn dump_repl_help() {
r###"{head}
Type ::: to begin multi-line editing, type ::: to end it.
Press Ctrl+O to open an editor to modify the current prompt.
Press Ctrl+C to abort aichat, Ctrl+D to exit the REPL"###,
);
}

Loading…
Cancel
Save