feat(cli): add multiline input support with Alt+Enter

- Enable custom-bindings feature in rustyline
- Bind Alt+Enter to insert newlines in interactive and accumulative modes
- Update calculate_visual_lines() to handle embedded newlines correctly
- Add tests for multiline visual line calculation

Note: Shift+Enter is not distinguishable in standard terminals, so Alt+Enter
is used as the multiline input trigger.
This commit is contained in:
Dhanji R. Prasanna
2026-02-06 14:09:12 +11:00
parent abfac197ab
commit 31bdcb651b
4 changed files with 50 additions and 13 deletions

View File

@@ -3,7 +3,7 @@
use anyhow::Result;
use crossterm::style::{Color, ResetColor, SetForegroundColor};
use rustyline::error::ReadlineError;
use rustyline::{Config, Editor};
use rustyline::{Cmd, Config, Editor, EventHandler, KeyCode, KeyEvent, Modifiers};
use crate::completion::G3Helper;
use std::path::Path;
use tracing::{debug, error};
@@ -226,6 +226,10 @@ pub async fn run_interactive<W: UiWriter>(
let mut rl = Editor::with_config(config)?;
rl.set_helper(Some(G3Helper::new()));
// Bind Alt+Enter to insert a newline (for multi-line input)
// Note: Shift+Enter is not distinguishable in standard terminals
rl.bind_sequence(KeyEvent(KeyCode::Enter, Modifiers::ALT), EventHandler::Simple(Cmd::Newline));
// Try to load history from a file in the user's home directory
let history_file = dirs::home_dir().map(|mut path| {
path.push(".g3_history");