-
Notifications
You must be signed in to change notification settings - Fork 30k
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
readline: keypress event trigger for escape character #7382
Conversation
@@ -149,3 +154,8 @@ addTest('\x1b[31ma\x1b[39ma', [ | |||
{ name: 'undefined', sequence: '\x1b[39m', code: '[39m' }, | |||
{ name: 'a', sequence: 'a' }, | |||
]); | |||
|
|||
// escape character | |||
addTest('\x1b', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a test for multiple escape characters one after another?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
ad7bf8f
to
9509910
Compare
function onData(b) { | ||
if (stream.listenerCount('keypress') > 0) { | ||
var r = stream[KEYPRESS_DECODER].write(b); | ||
if (r) { | ||
if (timeoutRef) { | ||
timeoutRef = clearTimeout(timeoutRef); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not return anything. See https://github.com/nodejs/node/blob/ede98a77677afcc5e75a126043a11a720f7ae28b/lib/timers.js -- you can use just use clearTimeout(timeoutRef)
without the if
or re-assigning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fishrock123 Yes, I just assigned the undefined
return value to timeout object. I'll remove that
435a870
to
bcb95b7
Compare
Looking good on the timeout value part from my side. By the way: changes over time are much easier to review if you don't force push after every change. |
// that can be called to run tests in sequence | ||
const addKeyIntervalTest = (sequences, expectedKeys, interval = 550, | ||
assertDelay = 550) => { | ||
return (next) => () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just add a comment stating which functions these are mocking?
Local testing shows this doing ok. LGTM with green CI but would like others to review also. |
Gave it a try. While it seems to work on single escape presses, 2 quick presses seem to get swallowed, 3 quick presses gives me:
|
@silverwind Do we need to reduce timeout value below 500ms? |
I don't think the timeout value is the issue, it's what happens when another escape arrives during the timeout. |
@nodejs/collaborators Is it good to merge? |
I'm fine with this as is but would like @silverwind to be comfortable with it also. |
Not really happy that it prints that garbage |
@silverwind I'll fix it |
e2476c7
to
9327a39
Compare
@silverwind Please try now |
Looking good. Only nit I have a are ESC+ESC and ESC+ESC+ESC entered during the timeout which are given as these keypress events:
Is ESC+ESC a valid escape sequence? If not, maybe we should emit individual events per keypress. Above issue isn't really something that should prevent this from landing. LGTM. |
@silverwind As per the existing implementation, CI: https://ci.nodejs.org/job/node-test-pull-request/3659/ For the invalid escape sequence, we may need a new PR to emit individual events per keypress as its a breaking change. |
CI is green. |
Fixes: #7379 PR-URL: #7382 Reviewed-By: jasnell - James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
Landed in |
I'd say leave it as is. I can't find any reference that ESC+ESC is not a escape sequence of its own. |
Fixes: #7379 PR-URL: #7382 Reviewed-By: jasnell - James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
Fixes: #7379 PR-URL: #7382 Reviewed-By: jasnell - James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
Fixes: #7379 PR-URL: #7382 Reviewed-By: jasnell - James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
Fixes: #7379 PR-URL: #7382 Reviewed-By: jasnell - James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
Checklist
make -j4 test
(UNIX) orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
readline
Description of change
Fixes: #7379