-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: error thrown while writing function statement in '.editor' mode #9189
Comments
cc: @princejwesley |
Works fine in macOS. I'll try this in windows 10. |
Works fine in Update: Pipe is closed when write to input stream (#8241). Disable auto alignment feature in windows will fix this issue. |
@addaleax @Fishrock123 Thinking of protecting input stream from writing with |
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 |
@princejwesley I’m not sure if I’m 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 |
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 So, yeah, you’re right, we shouldn’t directly write to the output stream, but call the readline 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 What do you think? |
@addaleax Yea, its perfect 👍 |
Okay, I’ll PR with that then :) |
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: nodejs#9189
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>
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>
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
The text was updated successfully, but these errors were encountered: