Skip to content

Commit 818db3a

Browse files
committed
feat(readline): readline displays default prompt
1 parent 60f19bc commit 818db3a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

lib/internal/readline/interface.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const kMaxLengthOfKillRing = 32;
9999

100100
const kMultilinePrompt = Symbol('| ');
101101

102+
const kDefaultPrompt = '> ';
103+
102104
const kAddHistory = Symbol('_addHistory');
103105
const kBeforeEdit = Symbol('_beforeEdit');
104106
const kDecoder = Symbol('_decoder');
@@ -170,7 +172,7 @@ function InterfaceConstructor(input, output, completer, terminal) {
170172
FunctionPrototypeCall(EventEmitter, this);
171173

172174
let crlfDelay;
173-
let prompt = '> ';
175+
let prompt = kDefaultPrompt;
174176
let signal;
175177

176178
if (input?.input) {
@@ -353,6 +355,13 @@ function InterfaceConstructor(input, output, completer, terminal) {
353355
this[kSetLine]('');
354356

355357
input.resume();
358+
359+
// If the default prompt prompt is used and the terminal is active, the prompt is automatically displayed.
360+
if (prompt === kDefaultPrompt && this.terminal && output !== null && output !== undefined) {
361+
process.nextTick(() => {
362+
this.prompt();
363+
});
364+
}
356365
}
357366

358367
ObjectSetPrototypeOf(InterfaceConstructor.prototype, EventEmitter.prototype);
@@ -463,6 +472,9 @@ class Interface extends InterfaceConstructor {
463472
cb(line);
464473
} else {
465474
this.emit('line', line);
475+
if (this[kPrompt] === kDefaultPrompt && this.terminal && this.output !== null && this.output !== undefined) {
476+
this.prompt();
477+
}
466478
}
467479
}
468480

0 commit comments

Comments
 (0)