Skip to content

Conversation

@pckrishnadas88
Copy link
Contributor

Description:
This PR adds the ability to customise the REPL subprompt for multiline input. Previously, the REPL always used the fixed | prompt for multiline statements. With this change, the subprompt can be customised. Once feature finalised doc can be updated.

Feature: Customisable subprompt for multiline input.
Fixes : #59401

// custom-repl-subprompt.js
'use strict';
const repl = require('repl').start({ prompt: '> ' });

// Default behavior
// > const foo = {
// | bar: 42,
// | baz: 100
// | }
// > foo
// { bar: 42, baz: 100 }

// Set a custom multiline prompt
repl.setMultilinePrompt('... ');

// Example with custom prompt
// > const obj = {
// ... x: 1,
// ... y: 2
// ... }
// > obj
// { x: 1, y: 2 }

// Set an emoji as multiline prompt (UTF-8)
repl.setMultilinePrompt('😎 ');

// Example with emoji prompt
// > const emojiObj = {
// 😎 mood: 'happy',
// 😎 energy: 'high'
// 😎 }
// > emojiObj
// { mood: 'happy', energy: 'high' }

@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 Aug 21, 2025
@codecov
Copy link

codecov bot commented Aug 21, 2025

Codecov Report

❌ Patch coverage is 84.84848% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.93%. Comparing base (4612c79) to head (02f1d5e).

Files with missing lines Patch % Lines
lib/internal/readline/interface.js 69.23% 4 Missing ⚠️
lib/repl.js 95.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #59566      +/-   ##
==========================================
- Coverage   88.25%   87.93%   -0.33%     
==========================================
  Files         703      703              
  Lines      207412   207433      +21     
  Branches    39893    39707     -186     
==========================================
- Hits       183052   182404     -648     
- Misses      16313    16987     +674     
+ Partials     8047     8042       -5     
Files with missing lines Coverage Δ
lib/repl.js 86.95% <95.00%> (-7.32%) ⬇️
lib/internal/readline/interface.js 93.30% <69.23%> (-4.03%) ⬇️

... and 45 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.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening the PR. I think we should not add anything to readline, but we could add the option.

I also wonder if we just want to set that option to '| ' when we start the internal REPL and not do that for any other REPL instances. That way we would have the default behavior that we want and unbreak external REPLs, while still allowing them to opt-in to the other behavior, when appropriate.

* Returns the current multiline prompt.
* @returns {string}
*/
getMultilinePrompt() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is adding these methods to the readline interface, while we currently only use this in the REPL. I don't think we should regularly expose this API.

Since we already have the symbol anyway, I think we can just use those and directly set the symbol and remove this getter and setter.

ignoreUndefined: false,
useGlobal: true,
breakEvalOnSigint: true,
multilinePrompt: opts?.multilinePrompt ?? '| ',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this option is currently not used at all? I do think it would in fact be nicer if we used the repl options for defining the value. So we should probably do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi I'm currently down with fever please give me a day or two. Usually where we discuss and finalize the requirements? I will make the changes soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get well soon! 🫖
Discussing things in the PR is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pckrishnadas88 I hope you feel better again! Would you mind having another look? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will try to update it as soon as possible. Will ping you while coding in case I have questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgeAR I’ve updated the PR. My branch was behind main by over 200 commits due to a 2–3 week gap, and I got a bit lost on this issue. Could you please review the code and confirm if this aligns with your recommendations? Some tests are still failing, likely because I’m not entirely sure the rebase was completed correctly after encountering conflicts.

Add option to customize the REPL subprompt for multiline input.
Add a  option to the REPL to allow custom prompts
for multiline input, replacing the default
@pckrishnadas88 pckrishnadas88 force-pushed the feature/custom-repl-subprompt branch from 3bbdf10 to 494e89a Compare September 19, 2025 15:55
@pckrishnadas88 pckrishnadas88 force-pushed the feature/custom-repl-subprompt branch from 83c7637 to de9083b Compare November 30, 2025 20:20
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.

3 participants