diff --git a/crates/goose-cli/src/session/input.rs b/crates/goose-cli/src/session/input.rs index 34d385291f26..900f95dbe310 100644 --- a/crates/goose-cli/src/session/input.rs +++ b/crates/goose-cli/src/session/input.rs @@ -1,5 +1,6 @@ use super::completion::GooseCompleter; use anyhow::Result; +use goose::config::Config; use rustyline::Editor; use shlex; use std::collections::HashMap; @@ -54,12 +55,24 @@ impl rustyline::ConditionalEventHandler for CtrlCHandler { } } +pub fn get_newline_key() -> char { + Config::global() + .get_param::("GOOSE_CLI_NEWLINE_KEY") + .ok() + .and_then(|s| s.chars().next()) + .map(|c| c.to_ascii_lowercase()) + .unwrap_or('j') +} + pub fn get_input( editor: &mut Editor, ) -> Result { - // Ensure Ctrl-J binding is set for newlines + let newline_key = get_newline_key(); 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), ); @@ -295,6 +308,7 @@ fn get_input_prompt_string() -> String { } fn print_help() { + let newline_key = get_newline_key().to_ascii_uppercase(); println!( "Available commands: /exit or /quit - Exit the session @@ -319,7 +333,7 @@ fn print_help() { Navigation: 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" ); } diff --git a/crates/goose-cli/src/session/prompt.rs b/crates/goose-cli/src/session/prompt.rs index 9c0db7bc1a33..695b28aadf81 100644 --- a/crates/goose-cli/src/session/prompt.rs +++ b/crates/goose-cli/src/session/prompt.rs @@ -1,6 +1,7 @@ /// Returns a system prompt extension that explains CLI-specific functionality 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 can let the user know about them if they need help: @@ -10,7 +11,7 @@ pub fn get_cli_prompt() -> String { Additional keyboard shortcuts: - 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" ) }