Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

raoofha
Copy link
Contributor

@raoofha raoofha commented Apr 3, 2018

500ms for application like readline-vim is very annoying. this PR allow the developer to control the timeout.

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the readline Issues and PRs related to the built-in readline module. label Apr 3, 2018
@Trott
Copy link
Member

Trott commented Apr 3, 2018

Hi, @raoofha and welcome! Thanks for the pull request!

Some immediate thoughts:

  • If we're going to export this, we'll need to add documentation for it. Totally OK if you're not comfortable writing the final text, but a draft of what you think should go in the docs would be very helpful.

  • Since this adds functionality, there should be a test for it. At a minimum, a test file should load readline and confirm that the property is exported, confirm that setting it to a few invalid values has the expected affect (which should be documented--ignore invalid value? throw? coerce to something valid? something else?), and (if possible) confirm that setting it to something very low and/or very high has the desired affect.

  • If we're exporting it, then it's no longer a constant and we probably want to change the name from ESCAPE_CODE_TIMEOUT to something more like escapeCodeTimeout.

/ping @thlorenz

@Trott Trott added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 3, 2018
@addaleax
Copy link
Member

addaleax commented Apr 3, 2018

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)
Copy link
Member

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.

@raoofha raoofha changed the title export ESCAPE_CODE_TIMEOUT add escapeCodeTimeout as an option to createInterface Apr 4, 2018
@raoofha
Copy link
Contributor Author

raoofha commented Apr 4, 2018

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

@Trott
Copy link
Member

Trott commented Apr 4, 2018

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!)

@raoofha
Copy link
Contributor Author

raoofha commented Apr 4, 2018

thanks @Trott for your comments. I added a simple test and waiting for your review.

@Trott
Copy link
Member

Trott commented Apr 4, 2018

I rebased to get rid of the conflict, and also reworded the documentation. (Hope that's OK!)

CI: https://ci.nodejs.org/job/node-test-pull-request/14049/

@Trott
Copy link
Member

Trott commented Apr 4, 2018

CI failures are unrelated. Re-running relevant jobs.

Re-run FreeBSD: https://ci.nodejs.org/job/node-test-commit-freebsd/16720/
Re-run Linux: https://ci.nodejs.org/job/node-test-commit-linux/17640/

lib/readline.js Outdated
Number.isNaN(escapeCodeTimeout) ||
escapeCodeTimeout < 0) {
escapeCodeTimeout = ESCAPE_CODE_TIMEOUT;
}
Copy link
Member

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
);
Copy link
Member

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);

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`.
Copy link
Member

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();
}
Copy link
Member

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();
});

Copy link
Contributor

@cjihrig cjihrig left a 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.

@@ -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
Copy link
Contributor

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' &&
Copy link
Contributor

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;
}


Copy link
Contributor

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;
Copy link
Contributor

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('');
Copy link
Contributor

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.

@BridgeAR
Copy link
Member

@raoofha if you have some time, would you be so kind and have a look at the comments? :-)

@raoofha
Copy link
Contributor Author

raoofha commented May 15, 2018

@BridgeAR sorry, I will

@raoofha
Copy link
Contributor Author

raoofha commented May 15, 2018

@cjihrig @BridgeAR thanks for your reviews please look at the last commit, and sorry for the delay

lib/readline.js Outdated
crlfDelay = input.crlfDelay;
input = input.input;
}

if (!Number.isFinite(this.escapeCodeTimeout)) {
Copy link
Member

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.

@raoofha
Copy link
Contributor Author

raoofha commented May 16, 2018

@BridgeAR please take a look again

@raoofha
Copy link
Contributor Author

raoofha commented Jul 12, 2018

hi @BridgeAR wondering when this is going to merge, or is there something that I have to do first?

@maclover7
Copy link
Contributor

CI: https://ci.nodejs.org/job/node-test-pull-request/16372/

@BridgeAR I believe your comments have been addressed, PTAL

@jasnell
Copy link
Member

jasnell commented Sep 10, 2018

Ping @BridgeAR

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Sep 10, 2018
@lundibundi
Copy link
Member

lundibundi commented Oct 15, 2018

CI: https://ci.nodejs.org/job/node-test-pull-request/17876/
Resume CI: https://ci.nodejs.org/job/node-test-pull-request/17891/

Changes LGTM but I'm not familiar with realine, hence no green mark.

ping @BridgeAR.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BridgeAR BridgeAR added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed stalled Issues and PRs that are stalled. labels Oct 16, 2018
@BridgeAR
Copy link
Member

Just as note: this did not have to wait on me. I did not block anything.

@refack
Copy link
Contributor

refack commented Oct 16, 2018

@refack
Copy link
Contributor

refack commented Oct 16, 2018

Had to rebase in order to get a proper CI: https://ci.nodejs.org/job/node-test-pull-request/17910/

@Trott
Copy link
Member

Trott commented Oct 18, 2018

jasnell pushed a commit that referenced this pull request Oct 25, 2018
PR-URL: #19780
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@jasnell
Copy link
Member

jasnell commented Oct 25, 2018

Landed in c829202

@jasnell jasnell closed this Oct 25, 2018
targos pushed a commit that referenced this pull request Oct 26, 2018
PR-URL: #19780
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
targos pushed a commit that referenced this pull request Nov 1, 2018
PR-URL: #19780
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
BethGriggs pushed a commit that referenced this pull request Apr 8, 2019
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>
@BethGriggs BethGriggs mentioned this pull request May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. readline Issues and PRs related to the built-in readline module. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants