Skip to content

readline: avoid painting default prompt before prompt()#62525

Open
Tseian wants to merge 1 commit intonodejs:mainfrom
Tseian:fix/readline-12606
Open

readline: avoid painting default prompt before prompt()#62525
Tseian wants to merge 1 commit intonodejs:mainfrom
Tseian:fix/readline-12606

Conversation

@Tseian
Copy link
Copy Markdown
Contributor

@Tseian Tseian commented Mar 31, 2026

Issue

#12606

Description

Track whether prompt() has been invoked and whether the configured prompt
is still the documented default. Until then, skip the default prefix when
redrawing the line or computing cursor position, fixing inconsistent
appearance after keys that refresh the line (see issue #12606).

Set the same flag when tab completion redraws the line so behavior matches
prior releases. Document that callers should call prompt() from a line
listener when they want a prompt on each new line (REPL already does).

Before

'use strict';

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

rl.on('line', (line) => {
  console.log(line);
});

It does not use rl.prompt() anywhere and with a common input there will be no default prompt.
However, if a user press DELETE, BACKSPACE or UP button. For example default prompt immediately and somehow unexpectedly appears shifting the whole line when I click UP button.

a
a
> a

After

Default prompt will not appear again.

a
a
a

@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. labels Mar 31, 2026
@Tseian Tseian force-pushed the fix/readline-12606 branch 2 times, most recently from c006977 to 263b532 Compare April 18, 2026 08:20
Track whether prompt() has been invoked and whether the configured prompt
is still the documented default. Until then, skip the default prefix when
redrawing the line or computing cursor position, fixing inconsistent
appearance after keys that refresh the line (see issue nodejs#12606).

Set the same flag when tab completion redraws the line so behavior matches
prior releases. Document that callers should call prompt() from a line
listener when they want a prompt on each new line (REPL already does).

Refs: nodejs#12606
Assisted-by: Cursor IDE
@Tseian Tseian force-pushed the fix/readline-12606 branch from 263b532 to 700207b Compare April 18, 2026 08:21
@Tseian Tseian changed the title WIP fs: readline readline: avoid painting default prompt before prompt() Apr 18, 2026
@Tseian Tseian marked this pull request as ready for review April 18, 2026 08:34
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 18, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.55%. Comparing base (7e3c244) to head (700207b).
⚠️ Report is 148 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/readline/interface.js 92.30% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62525      +/-   ##
==========================================
- Coverage   89.70%   89.55%   -0.15%     
==========================================
  Files         694      706      +12     
  Lines      214216   218147    +3931     
  Branches    41108    41685     +577     
==========================================
+ Hits       192160   195362    +3202     
- Misses      14109    14683     +574     
- Partials     7947     8102     +155     
Files with missing lines Coverage Δ
lib/internal/readline/interface.js 91.47% <92.30%> (-5.88%) ⬇️

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

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants