Skip to content

repl: add possibility to edit multiline commands while adding them #58003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

puskin94
Copy link
Contributor

@puskin94 puskin94 commented Apr 24, 2025

Summary

This PR builds upon the multiline editing support added to the REPL history in #57400, enhancing it with the ability to edit multiline input as you're writing it, before it even reaches the history.

Key Features

  1. Inline Multiline Editing: You can now insert, delete, edit, and split lines while composing a REPL command. This brings a more fluid editing experience, similar to what you'd expect from a basic code editor. See the GIF below for a demo.

  2. TTY-only Support: This feature makes heavy use of cursor movement to efficiently draw and clear parts of the current input. As a result, it currently only works in TTY environments.

  3. Unchanged Execution Behavior: Pressing Enter behaves as usual:

    • If the current input is a complete and valid command, it executes.
    • If not, a new line is added, continuing multiline input.
  4. Limitations:

    • If you want to insert a new line in the middle of a complete multiline command, you’ll need to first make the command incomplete (e.g. by removing a closing } or `).
    • The logic for inserting new lines in complete commands is in place, but I ran into trouble capturing a reliable shortcut like Shift + Enter. I’ve left a TODO to revisit this and debug further.

multiline-while-adding

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module. repl Issues and PRs related to the REPL subsystem. labels Apr 24, 2025
@puskin94 puskin94 force-pushed the repl-multiline-refactor-and-while-typing branch from 7353efd to 9aca5ed Compare April 24, 2025 12:12
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 98.79518% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.27%. Comparing base (c11c7be) to head (1947902).
Report is 50 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/readline/interface.js 98.72% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58003      +/-   ##
==========================================
+ Coverage   90.24%   90.27%   +0.03%     
==========================================
  Files         630      630              
  Lines      185788   186279     +491     
  Branches    36429    36493      +64     
==========================================
+ Hits       167659   168169     +510     
+ Misses      11004    10982      -22     
- Partials     7125     7128       +3     
Files with missing lines Coverage Δ
lib/repl.js 94.98% <100.00%> (-0.05%) ⬇️
lib/internal/readline/interface.js 96.84% <98.72%> (+0.04%) ⬆️

... and 62 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@puskin94 puskin94 force-pushed the repl-multiline-refactor-and-while-typing branch 3 times, most recently from f48329c to 161cdcf Compare April 25, 2025 14:59
@puskin94 puskin94 force-pushed the repl-multiline-refactor-and-while-typing branch from 161cdcf to 1947902 Compare April 25, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants