From 37184044609997604bfa1ab08be356d8b4e5e19d Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 15:07:45 +0100 Subject: Input editor: history, bracketed paste, in-line editing - crossterm raw mode only for the duration of a prompt, so SIGINT keeps working during a turn - persisted history with prompt commands excluded and newlines escaped - bracketed paste inserts one multi-line buffer instead of firing N turns - ctrl-a/e/u/k/w editing, ctrl-c abandons the line, ctrl-d exits - ctrl-j submits, so pipes and pty harnesses work - width fallback: a 0-column pty is 80 columns, not 1 --- src/main.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 4bc3550..29b4280 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,11 @@ -use std::io::{BufRead, IsTerminal, Write}; +use std::io::{BufRead, Write}; use std::path::PathBuf; use std::time::SystemTime; use serde_json::Value; use agent686::config::Config; +use agent686::line::Editor; use agent686::session::{self, Session}; use agent686::ui::Approver; use agent686::{agent, signal}; @@ -16,7 +17,12 @@ USAGE: agent686 [OPTIONS] [PROMPT...] With a prompt it runs one turn and exits. Without one it reads prompts from -stdin, one per line. Commands: /paste, /exit, /help. +stdin. In a terminal: up/down for history, ctrl-a/e/u/w/k to edit, ctrl-d to +exit, ctrl-c to abandon the line. Commands: /paste, /exit, /help. + +/cmd + /paste read a block of lines until a lone `.` + /exit quit OPTIONS: -m, --model model id (default: deepseek-v4.1-flash) @@ -109,7 +115,8 @@ fn main() { return; } - let interactive = std::io::stdin().is_terminal(); + let mut editor = Editor::new(); + let interactive = editor.is_interactive(); if interactive { eprintln!( "agent686 · {} · session {}{}", @@ -117,22 +124,21 @@ fn main() { cfg.session, if cfg.yolo { " · yolo" } else { "" } ); - eprintln!("one prompt per line · /paste · /exit"); + eprintln!("type a prompt · up/down history · ctrl-d exit · /help"); } let stdin = std::io::stdin(); let mut line = String::new(); loop { - if interactive { - print!("> "); - let _ = std::io::stdout().flush(); - } - line.clear(); - if stdin.lock().read_line(&mut line).unwrap_or(0) == 0 { - break; - } - let mut text = line.trim_end().to_string(); - if text.is_empty() { + let mut text = match editor.read("> ") { + Ok(Some(text)) => text, + Ok(None) => break, + Err(error) => { + eprintln!("agent686: input: {error}"); + break; + } + }; + if text.trim().is_empty() { continue; } -- cgit v1.2.3