-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
add escapeCodeTimeout as an option to createInterface #19780
Conversation
Hi, @raoofha and welcome! Thanks for the pull request! Some immediate thoughts:
/ping @thlorenz |
Would it make sense to do this on a per-instance basis, rather than for each Node.js process as a whole? |
lib/readline.js
Outdated
@@ -1133,5 +1130,6 @@ module.exports = { | |||
createInterface, | |||
cursorTo, | |||
emitKeypressEvents, | |||
moveCursor | |||
moveCursor, | |||
ESCAPE_CODE_TIMEOUT : 500 // GNU readline library - keyseq-timeout is 500ms (default) |
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.
If we're going to do this, passing escapeCodeTimeout
as an option to readline.createInterface()
would seem to be the better approach.
I add doc ( copyed from here ) and manually test it on my machine. I don't know how to write test for it, if you can tell me how maybe I can do it. thanks |
Sorry @raoofha, I should have included this link with my comment! https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md Hope it helps. (And if it doesn't, maybe you can give some feedback and we can try to improve it!) |
thanks @Trott for your comments. I added a simple test and waiting for your review. |
I rebased to get rid of the conflict, and also reworded the documentation. (Hope that's OK!) |
CI failures are unrelated. Re-running relevant jobs. Re-run FreeBSD: https://ci.nodejs.org/job/node-test-commit-freebsd/16720/ |
lib/readline.js
Outdated
Number.isNaN(escapeCodeTimeout) || | ||
escapeCodeTimeout < 0) { | ||
escapeCodeTimeout = ESCAPE_CODE_TIMEOUT; | ||
} |
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.
Suggestion: the check could be moved in the upper if.
lib/readline.js
Outdated
timeoutId = setTimeout( | ||
escapeCodeTimeoutFn, | ||
ESCAPE_CODE_TIMEOUT | ||
); |
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.
Suggestion: just write:
timeoutId = setTimeout(escapeCodeTimeoutFn, iface ? iface.escapeCodeTimeout : ESCAPE_CODE_TIMEOUT);
doc/api/readline.md
Outdated
character when reading an ambiguous key sequence (one that can both form a | ||
complete key sequence using the input read so far and can take additional | ||
input to complete a longer key sequence). The default value is used if | ||
`NaN`, a negative number, or a non-number is provided. **Default:** `500`. |
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.
It is unclear in what unit the time is measured here. It should say something like The duration readline will wait for a character when reading an ambiguous key sequence in milliseconds (...)
.
I personally would also only accept integers but that is just me.
}); | ||
assert.strictEqual(rli.escapeCodeTimeout, ESCAPE_CODE_TIMEOUT); | ||
rli.close(); | ||
} |
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.
These tests are doing all the same thing and are just duplicated. It would be best to write:
[
null,
{},
NaN,
'50'
].forEach((invalidInput) => {
const fi = new FakeInput();
const rli = new readline.Interface({
input: fi,
output: fi,
escapeCodeTimeout: invalidInput
});
assert.strictEqual(rli.escapeCodeTimeout, ESCAPE_CODE_TIMEOUT);
rli.close();
});
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.
Left a few comments. Mostly trying to make the diff less noisy.
doc/api/readline.md
Outdated
@@ -373,6 +373,12 @@ changes: | |||
* `removeHistoryDuplicates` {boolean} If `true`, when a new input line added | |||
to the history list duplicates an older one, this removes the older line | |||
from the list. **Default:** `false`. | |||
* `escapeCodeTimeout` {number} The duration `readline` will wait for a | |||
character when reading an ambiguous key sequence in milliseconds (one that |
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.
The parentheses should probably go next to "ambiguous key sequence"
lib/readline.js
Outdated
@@ -94,10 +95,16 @@ function Interface(input, output, completer, terminal) { | |||
if (input.prompt !== undefined) { | |||
prompt = input.prompt; | |||
} | |||
if (typeof input.escapeCodeTimeout === 'number' && |
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.
Perhaps Number.isFinite()
should be used here. It's also probably better to throw, rather than silently use a different value.
lib/readline.js
Outdated
crlfDelay = input.crlfDelay; | ||
input = input.input; | ||
} | ||
|
||
|
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.
Could you remove this new blank line.
lib/readline.js
Outdated
@@ -126,7 +133,7 @@ function Interface(input, output, completer, terminal) { | |||
this.removeHistoryDuplicates = !!removeHistoryDuplicates; | |||
this.crlfDelay = crlfDelay ? | |||
Math.max(kMincrlfDelay, crlfDelay) : kMincrlfDelay; | |||
|
|||
this.escapeCodeTimeout = escapeCodeTimeout; |
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.
escapeCodeTimeout
isn't used between here and line 101. I don't think you need to create an intermediate variable for it.
lib/readline.js
Outdated
@@ -992,7 +999,7 @@ function emitKeypressEvents(stream, iface) { | |||
stream[ESCAPE_DECODER] = emitKeys(stream); | |||
stream[ESCAPE_DECODER].next(); | |||
|
|||
const escapeCodeTimeout = () => stream[ESCAPE_DECODER].next(''); | |||
const escapeCodeTimeoutFn = () => stream[ESCAPE_DECODER].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.
And if you don't introduce a new intermediate variable, you don't need to rename this.
@raoofha if you have some time, would you be so kind and have a look at the comments? :-) |
@BridgeAR sorry, I will |
lib/readline.js
Outdated
crlfDelay = input.crlfDelay; | ||
input = input.input; | ||
} | ||
|
||
if (!Number.isFinite(this.escapeCodeTimeout)) { |
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 should be moved into the added upper if statement, since it is only necessary to test to possible provided option. If non was passed through, we already know that the value is finite.
@BridgeAR please take a look again |
hi @BridgeAR wondering when this is going to merge, or is there something that I have to do first? |
CI: https://ci.nodejs.org/job/node-test-pull-request/16372/ @BridgeAR I believe your comments have been addressed, PTAL |
Ping @BridgeAR |
Changes LGTM but I'm not familiar with realine, hence no green mark. ping @BridgeAR. |
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.
LGTM
Just as note: this did not have to wait on me. I did not block anything. |
escapeCodeTimeout option in createInterface default to ESCAPE_CODE_TIMEOUT = 500 when set to a NaN or negative number or a value other than a number set back to default value
as suggested by @BridgeAR
Had to rebase in order to get a proper CI: https://ci.nodejs.org/job/node-test-pull-request/17910/ |
Resume Build: https://ci.nodejs.org/job/node-test-pull-request/17960/ |
PR-URL: #19780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Landed in c829202 |
PR-URL: #19780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #19780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #19780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
500ms for application like readline-vim is very annoying. this PR allow the developer to control the timeout.
make -j4 test
(UNIX), orvcbuild test
(Windows) passes