Skip to content

Add readline-based REPL input with persistent history and arrow-key navigation#61

Merged
assapir merged 2 commits into
mainfrom
copilot/add-repl-input-history
Mar 18, 2026
Merged

Add readline-based REPL input with persistent history and arrow-key navigation#61
assapir merged 2 commits into
mainfrom
copilot/add-repl-input-history

Conversation

Copilot AI commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

The REPL was using raw stdin line reads, so arrow keys emitted escape sequences and command history was unavailable. This change replaces prompt input handling with rustyline to provide standard line editing, up/down history navigation, and persisted history across sessions.

  • REPL input handling

    • Replaced tokio line-based stdin loop in src/main.rs with rustyline::DefaultEditor.
    • Prompt now supports readline-style editing semantics (cursor movement, backspace/delete, etc.).
  • History persistence

    • Added default_history_path() in src/consts.rs to centralize history location at ~/.golem/history.txt.
    • REPL now loads history on startup and saves on exit.
    • Uses auto_add_history(true) so non-empty submitted lines are tracked without manual insertion.
  • Interrupt / EOF behavior

    • Mapped ReadlineError::Interrupted to prompt interrupt handling (Ctrl+C) without exiting the REPL.
    • Mapped ReadlineError::Eof to clean REPL termination (Ctrl+D), preserving expected terminal behavior.
  • Dependencies and docs

    • Added rustyline = "17.0.2" to Cargo.toml.
    • Updated README REPL section to document arrow-key history and persistence path.
let mut repl: DefaultEditor =
    DefaultEditor::with_config(ReadlineConfig::builder().auto_add_history(true).build())?;

let history_path = default_history_path();
let _ = repl.load_history(&history_path);

loop {
    match repl.readline("\ngolem> ") {
        Ok(line) => { /* existing command/task dispatch */ }
        Err(ReadlineError::Interrupted) => continue, // Ctrl+C
        Err(ReadlineError::Eof) => break,            // Ctrl+D
        Err(e) => { eprintln!("input error: {e}"); break; }
    }
}

let _ = repl.save_history(&history_path);
Original prompt

This section details on the original issue you should resolve

<issue_title>feat: add REPL input history with up/down arrow keys</issue_title>
<issue_description>Currently the REPL reads raw lines from stdin — no history, no arrow key navigation. Pressing up-arrow just prints escape codes.

Add readline-style input history so up/down arrows cycle through previous inputs. This would use a crate like rustyline to replace the raw tokio::io::stdin().lines() reader in main.rs.

Expected behavior:

  • Up arrow: previous input
  • Down arrow: next input
  • History persists across sessions (save to ~/.golem/history.txt or in the SQLite DB)
  • Ctrl+C still interrupts, Ctrl+D still exits
  • Line editing (left/right, backspace, delete) works naturally</issue_description>

<agent_instructions>implament this. make sure you actually tested it</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: assapir <4030466+assapir@users.noreply.github.com>
Copilot AI changed the title [WIP] Add REPL input history with up down arrow navigation Add persistent readline REPL history with arrow-key navigation Mar 17, 2026
Copilot AI requested a review from assapir March 17, 2026 06:57
@assapir assapir marked this pull request as ready for review March 17, 2026 08:39
Copilot AI changed the title Add persistent readline REPL history with arrow-key navigation Add readline-based REPL input with persistent history and arrow-key navigation Mar 17, 2026
@assapir assapir merged commit 9fdcac9 into main Mar 18, 2026
5 checks passed
@assapir assapir deleted the copilot/add-repl-input-history branch March 18, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add REPL input history with up/down arrow keys

2 participants