Allow customizing the new line keybinding in the CLI (#5956)
Signed-off-by: Trae Robrock <trobrock@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
use super::completion::GooseCompleter;
|
use super::completion::GooseCompleter;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use goose::config::Config;
|
||||||
use rustyline::Editor;
|
use rustyline::Editor;
|
||||||
use shlex;
|
use shlex;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -55,12 +56,24 @@ impl rustyline::ConditionalEventHandler for CtrlCHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_newline_key() -> char {
|
||||||
|
Config::global()
|
||||||
|
.get_param::<String>("GOOSE_CLI_NEWLINE_KEY")
|
||||||
|
.ok()
|
||||||
|
.and_then(|s| s.chars().next())
|
||||||
|
.map(|c| c.to_ascii_lowercase())
|
||||||
|
.unwrap_or('j')
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_input(
|
pub fn get_input(
|
||||||
editor: &mut Editor<GooseCompleter, rustyline::history::DefaultHistory>,
|
editor: &mut Editor<GooseCompleter, rustyline::history::DefaultHistory>,
|
||||||
) -> Result<InputResult> {
|
) -> Result<InputResult> {
|
||||||
// Ensure Ctrl-J binding is set for newlines
|
let newline_key = get_newline_key();
|
||||||
editor.bind_sequence(
|
editor.bind_sequence(
|
||||||
rustyline::KeyEvent(rustyline::KeyCode::Char('j'), rustyline::Modifiers::CTRL),
|
rustyline::KeyEvent(
|
||||||
|
rustyline::KeyCode::Char(newline_key),
|
||||||
|
rustyline::Modifiers::CTRL,
|
||||||
|
),
|
||||||
rustyline::EventHandler::Simple(rustyline::Cmd::Newline),
|
rustyline::EventHandler::Simple(rustyline::Cmd::Newline),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -297,6 +310,7 @@ fn get_input_prompt_string() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn print_help() {
|
fn print_help() {
|
||||||
|
let newline_key = get_newline_key().to_ascii_uppercase();
|
||||||
println!(
|
println!(
|
||||||
"Available commands:
|
"Available commands:
|
||||||
/exit or /quit - Exit the session
|
/exit or /quit - Exit the session
|
||||||
@@ -322,7 +336,7 @@ fn print_help() {
|
|||||||
|
|
||||||
Navigation:
|
Navigation:
|
||||||
Ctrl+C - Clear current line if text is entered, otherwise exit the session
|
Ctrl+C - Clear current line if text is entered, otherwise exit the session
|
||||||
Ctrl+J - Add a newline
|
Ctrl+{newline_key} - Add a newline (configurable via GOOSE_CLI_NEWLINE_KEY)
|
||||||
Up/Down arrows - Navigate through command history"
|
Up/Down arrows - Navigate through command history"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/// Returns a system prompt extension that explains CLI-specific functionality
|
/// Returns a system prompt extension that explains CLI-specific functionality
|
||||||
pub fn get_cli_prompt() -> String {
|
pub fn get_cli_prompt() -> String {
|
||||||
String::from(
|
let newline_key = super::input::get_newline_key().to_ascii_uppercase();
|
||||||
|
format!(
|
||||||
"You are being accessed through a command-line interface. The following slash commands are available
|
"You are being accessed through a command-line interface. The following slash commands are available
|
||||||
- you can let the user know about them if they need help:
|
- you can let the user know about them if they need help:
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ pub fn get_cli_prompt() -> String {
|
|||||||
|
|
||||||
Additional keyboard shortcuts:
|
Additional keyboard shortcuts:
|
||||||
- Ctrl+C - Interrupt the current interaction (resets to before the interrupted request)
|
- Ctrl+C - Interrupt the current interaction (resets to before the interrupted request)
|
||||||
- Ctrl+J - Add a newline
|
- Ctrl+{newline_key} - Add a newline
|
||||||
- Up/Down arrows - Navigate command history"
|
- Up/Down arrows - Navigate command history"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user