Skip to content

Commit

Permalink
repl: don’t write to input stream in editor mode
Browse files Browse the repository at this point in the history
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 <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and evanlucas committed Nov 3, 2016
1 parent 1c59cef commit 0b9d80a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ function REPLServer(prompt,
const matches = self._sawKeyPress ? cmd.match(/^\s+/) : null;
if (matches) {
const prefix = matches[0];
self.inputStream.write(prefix);
self.write(prefix);
self.line = prefix;
self.cursor = prefix.length;
}
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-repl-.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ tests.forEach(run);
// Auto code alignment for .editor mode
function testCodeAligment({input, cursor = 0, line = ''}) {
const stream = new common.ArrayStream();
const outputStream = new common.ArrayStream();

stream.write = () => { throw new Error('Writing not allowed!'); };

const replServer = repl.start({
prompt: '> ',
terminal: true,
input: stream,
output: stream,
output: outputStream,
useColors: false
});

Expand Down

0 comments on commit 0b9d80a

Please sign in to comment.