nodejs/node

readline: prompt opt-out behavior

Open

#12.606 geöffnet am 23. Apr. 2017

Auf GitHub ansehen
 (10 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (35.535 Forks)batch import
confirmed-bughelp wantedreadline

Repository-Metriken

Stars
 (117.218 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 18T 17h) (219 gemergte PRs in 30 T)

Beschreibung

  • Version: v8.0.0-rc.0
  • Platform: Windows 4 x64
  • Subsystem: readline

I am not sure if this is a bug or a feature.

Consider this simple echo interface:

'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:

1

However, if a user press DELETE, BACKSPACE or UP button, default prompt immediately and somehow unexpectedly appears shifting the whole line:

2

This can be prevented by setting the prompt option into the empty line. However, I am not sure if this opt-out rule is an intended behavior.

Contributor Guide