When using the REPL's .editor mode, the following error occurs when hitting the 'ENTER' key after a return statement. Tested in both CMD and Git Bash
C:\Users\joe>node -v
v6.9.0
C:\Users\joe>node
> var a = 1
undefined
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function thing (x) {
return x
readline.js:982
throw err;
^
Error: write EPIPE
at exports._errnoException (util.js:1026:11)
at ReadStream.Socket._writeGeneric (net.js:710:26)
at ReadStream.Socket._write (net.js:729:8)
at doWrite (_stream_writable.js:333:12)
at writeOrBuffer (_stream_writable.js:319:5)
at ReadStream.Writable.write (_stream_writable.js:246:11)
at ReadStream.Socket.write (net.js:656:40)
at REPLServer.<anonymous> (repl.js:479:26)
at emitOne (events.js:101:20)
at REPLServer.emit (events.js:188:7)
cc: @princejwesley
Works fine in macOS. I'll try this in windows 10.
Works fine in v6.5.0(irrelevant). Writing white spaces to input stream throws this error in v6.9.0.
_Update_: Pipe is closed when write to input stream (https://github.com/nodejs/node/pull/8241). Disable auto alignment feature in windows will fix this issue.
@addaleax @Fishrock123 Thinking of protecting input stream from writing with inputStream.isTTY && (inputStream.writable || process.platform !== 'win32') predicate. Any suggestion?
Hm, why does the REPL try to write to the input stream here in the first place? Is there any reason not to use the output stream for that?
@addaleax User can use backspace to remove/adjust the alignment.
@princejwesley I鈥檓 not sure if I鈥檓 unaware of something Windows-specific here, but generally, that should work fine when writing to the output stream?
@addaleax can we undo the characters written to output stream? In the case of input stream, current line data is still in buffer and user can use backspace to erase white spaces added for alignment
My understanding is, output stream is read only in ttys perspective.
current line data is still in buffer
Whose buffer? In the context of the REPL, the TTY is generally in raw mode, so buffering is not really an issue here, and the current line is only stored by our readline.Interface instance.
So, yeah, you鈥檙e right, we shouldn鈥檛 directly write to the output stream, but call the readline write(). Something like this seems like a correct patch to me:
diff --git a/lib/repl.js b/lib/repl.js
index 620addc5ef53..283adfeb78be 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;
}
@@ -601,6 +601,7 @@ function REPLServer(prompt,
// Wrap readline tty to enable editor mode
const ttyWrite = self._ttyWrite.bind(self);
self._ttyWrite = (d, key) => {
+ key = key || {};
if (!self.editorMode || !self.terminal) {
ttyWrite(d, key);
return;
That last piece should probably be added anyway, too, to match the check in readline.js.
What do you think?
@addaleax Yea, its perfect 馃憤
Okay, I鈥檒l PR with that then :)
Most helpful comment
Okay, I鈥檒l PR with that then :)