Skip to content

Commit 58b60fc

Browse files
addaleaxMyles Borins
authored and
Myles Borins
committed
repl: don’t write to input stream in editor mode
Instead of writing to the REPL’s input stream for the alignment spaces in `.editor` mode, let `readline` handle the spaces properly (echoing them using `_ttyWrite` and adding them to the current line buffer). Fixes: #9189 PR-URL: #9207 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ed3de08 commit 58b60fc

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ function REPLServer(prompt,
476476
const matches = self._sawKeyPress ? cmd.match(/^\s+/) : null;
477477
if (matches) {
478478
const prefix = matches[0];
479-
self.inputStream.write(prefix);
479+
self.write(prefix);
480480
self.line = prefix;
481481
self.cursor = prefix.length;
482482
}

test/parallel/test-repl-.editor.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,15 @@ tests.forEach(run);
7575
// Auto code alignment for .editor mode
7676
function testCodeAligment({input, cursor = 0, line = ''}) {
7777
const stream = new common.ArrayStream();
78+
const outputStream = new common.ArrayStream();
79+
80+
stream.write = () => { throw new Error('Writing not allowed!'); };
7881

7982
const replServer = repl.start({
8083
prompt: '> ',
8184
terminal: true,
8285
input: stream,
83-
output: stream,
86+
output: outputStream,
8487
useColors: false
8588
});
8689

0 commit comments

Comments
 (0)