Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

Problem

The REPL had two critical usability issues:

  1. History navigation broken: Up/down arrow keys did not recall previous commands
  2. Double Ctrl+C timing issue: Users had to press Ctrl+C twice extremely quickly (within 300ms of the prompt appearing) to exit, making it nearly impossible to exit reliably

Root Cause

History Issue

The REPL spawned a new thread for each readline operation, and each thread created a new Editor instance. While the code attempted to maintain history by loading strings into each new editor, rustyline's built-in history navigation requires a persistent Editor instance with its own internal history state, not just a list of strings being copied around.

Double Ctrl+C Issue

The exit logic tracked last_was_interrupted as a boolean and checked if the readline had been active for less than 300ms. This meant users had to press Ctrl+C twice within 300ms of the prompt appearing, not within 300ms of each other - a timing that was nearly impossible to achieve reliably.

Solution

History Fix

  • Wrap a single Editor instance in Arc<Mutex> and share it across threads
  • This preserves rustyline's internal history state, enabling proper up/down arrow navigation
  • History is now properly maintained across all readline operations

Double Ctrl+C Fix

  • Track last_interrupt_time: Option<Instant> instead of a boolean flag
  • Check if two Ctrl+C presses occur within 1 second of each other
  • This gives users a reasonable, reliable window to exit the REPL

Changes

  • File changed: cli/main.rs only
  • Net change: -27 lines (simpler, more maintainable code)
  • Preserved functionality: Event loop continues to tick during readline for async operations

Testing

✅ All 76 existing tests pass
✅ No clippy warnings
✅ Code properly formatted
✅ Manual testing confirms both issues are resolved

The threading approach remains necessary because readline() is a blocking call and we need the event loop to continue processing async operations. This fix preserves that architecture while fixing the usability issues.

Original prompt

The REPL is broken. Clicking control twice has to happen super duper fast to exit. History is no longer working


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix REPL exit functionality and history tracking Fix REPL history navigation and double Ctrl+C exit timing Oct 22, 2025
Copilot AI requested a review from MylesBorins October 22, 2025 15:59
Copilot finished work on behalf of MylesBorins October 22, 2025 15:59
@MylesBorins MylesBorins marked this pull request as ready for review October 22, 2025 17:10
@MylesBorins MylesBorins merged commit e104b17 into main Oct 22, 2025
6 checks passed
@MylesBorins MylesBorins deleted the copilot/fix-repl-exit-issue branch October 22, 2025 17:10
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.

2 participants