Uh oh!
There was an error while loading. Please reload this page.
readline: turn emitKeys into a streaming parser - #1601
Conversation
mscdex
commented
May 3, 2015
What about having a timer that starts when you see |
rlidwka
commented
May 3, 2015
I think readline behavior should be consistent with other shells. I just tested |
mscdex
commented
May 3, 2015
Sorry, I was referring to ncurses-based programs and such, not so much shells or other REPLs. |
There was a problem hiding this comment.
Maybe use a while (ch === '\x1b'), so it will catch as many escapes as one could possibly feed into it?
Fishrock123
commented
May 4, 2015
Clever use of a generator here. I like it. Would prefer if someone who better understands the parsing requirements could also take a look though. |
Fishrock123
commented
May 4, 2015
silverwind
commented
May 6, 2015
There're a few unused consts after this commit, probaby best to remove these (unless there's future use for them): |
silverwind
commented
May 6, 2015
Tested it a bit. Escape sequences all work as expected, the code looks well documented, nice work! |
There was a problem hiding this comment.
Does all the existing Buffer functionality still work?
There was a problem hiding this comment.
No, it's not, and it didn't work before either.
I'd appreciate another look at this, but I think this Buffer handling was a dead code since this commit: 3c91a7a.
Function emitKeys never receives any buffers in the first place, because string_decoder.write() returns strings only.
Fishrock123
commented
May 7, 2015
LGTM, but maybe cc @piscisaureus? |
rlidwka
commented
May 7, 2015
Done. Some of rhe consts are used in |
There was a problem hiding this comment.
should we put these into consts then? Does it make a difference?
There was a problem hiding this comment.
Are you talking about regular expressions?
I think the only difference is readability, so if regexps are large enough, it'd make sense to move them out (or get rid of them since large regular expressions are a source of trouble usually).
But those are small, so they could be inlined.
V8 should create each regexp from regexp literal only once anyway.
In certain environments escape sequences could be splitted into multiple chunks. For example, when user presses left arrow, `\x1b[D` sequence could appear as two keypresses (`\x1b` + `[D`). Fixes: nodejs#1403
rlidwka
commented
May 9, 2015
Rebased on top of master branch and added generators to |
silverwind
commented
May 10, 2015
LGTM |
In certain environments escape sequences could be splitted into multiple chunks. For example, when user presses left arrow, `\x1b[D` sequence could appear as two keypresses (`\x1b` + `[D`). PR-URL: #1601Fixes: #1403 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
silverwind
commented
May 10, 2015
Thanks! Landed in aed6bce |
In certain environments escape sequences could be splitted into multiple chunks. For example, when user presses left arrow, `\x1b[D` sequence could appear as two keypresses (`\x1b` + `[D`). PR-URL: nodejs#1601Fixes: nodejs#1403 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
see #1403
I changed
emitKeysto a generator that receives data character by character and emitskeypressevent whenever an escape sequence is complete.So now behavior is similar to
bashandpythonshells I tested so far. For example, you can sequentally pressESC + [ + D, and it will be handled the same as "left arrow", because the data that's coming to node.js is the same in both cases:\x1b[D.Possible side effect:
escapekey itself will never be emitted. If we get\x1b, parser will treat it as a start of an escape sequence no matter what. Our REPL never rely on that, but maybe other readline users are (xkcd spacebar heating yep).