From 58b60fc79de641c741a65abfb7d035488ace95a5 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 20 Oct 2016 16:57:40 +0200 Subject: [PATCH] =?UTF-8?q?repl:=20don=E2=80=99t=20write=20to=20input=20st?= =?UTF-8?q?ream=20in=20editor=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/issues/9189 PR-URL: https://github.com/nodejs/node/pull/9207 Reviewed-By: Prince John Wesley Reviewed-By: James M Snell --- lib/repl.js | 2 +- test/parallel/test-repl-.editor.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index a42d958d330099..c4ecced77837fc 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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; } diff --git a/test/parallel/test-repl-.editor.js b/test/parallel/test-repl-.editor.js index 4077840c596376..678d6d5c6d94f8 100644 --- a/test/parallel/test-repl-.editor.js +++ b/test/parallel/test-repl-.editor.js @@ -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 });