Skip to content

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

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

readline: avoid painting default prompt before prompt()#62525
Tseian wants to merge 1 commit into
nodejs: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 3 times, most recently 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.52%. Comparing base (25f80fb) to head (2b79a42).

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.65%   89.52%   -0.14%     
==========================================
  Files         712      712              
  Lines      220822   220699     -123     
  Branches    42373    42274      -99     
==========================================
- Hits       197985   197572     -413     
- Misses      14661    14929     +268     
- Partials     8176     8198      +22     
Files with missing lines Coverage Δ
lib/internal/readline/interface.js 91.47% <92.30%> (-5.88%) ⬇️

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

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 700207b to 2b79a42 Compare May 4, 2026 00:37
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