-
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: key interval delay for \r & \n #8109
Conversation
@@ -199,6 +199,27 @@ function isWarned(emitter) { | |||
assert.equal(callCount, expectedLines.length); | |||
rli.close(); | |||
|
|||
// Emit two line events where there is a delay | |||
// between \r and \n | |||
(() => { |
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 drop this style and just wrap this portion of the test in curly braces. That will provide the block scope you want.
@princejwesley Could you give an example as to how to induce the problem this fixes?
|
This is how I reproduced in macOS. Run the below snippet and hit const readline = require('readline');
const rli = new readline.Interface({
input: process.stdin,
output: process.stdout,
terminal: true
});
let count = 0;
rli.on('line', function(line) {
count++;
console.log(`line event triggered ${count}`);
}); Edit: |
It may be better to make the delay period configurable |
I think if we're going to add a delay, it should definitely be configurable (with some sensible default but allowing to opt out altogether -- perhaps with a 0 value). |
@mscdex Delay is introduced to differentiate whether its a system that emits In nutshell, this PR tries to figure out whether Current experience, ~ 🙈 node
> // I hit enter - that emits CR(\r)
> // now I hit `ctrl + j ` to emit LF(\n) - no newline |
@princejwesley I understand, but I think it would be useful to be able to explicitly tell |
@mscdex I'll update the PR with configurable option. Shall I use |
} | ||
return rl; | ||
}; | ||
|
||
|
||
function Interface(input, output, completer, terminal) { | ||
function Interface(input, output, completer, terminal, | ||
crLfDelay = kCRLFDelayInMillis) { |
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.
IMHO this should line up with the input
parameter.
@princejwesley I don't really have a preference on the name. Although personally I think if it starts with 'CRLF', that prefix would look better lowercased ( |
b85b036
to
587646a
Compare
@@ -358,6 +358,9 @@ added: v0.1.98 | |||
only if `terminal` is set to `true` by the user or by an internal `output` | |||
check, otherwise the history caching mechanism is not initialized at all. | |||
* `prompt` - the prompt string to use. Default: `'> '` | |||
* `crlfDelay` {number} If the delay between `\r` and `\n` exceeds | |||
`crlfDelay`, both `\r` and `\n` will be treated as separate end-of-line |
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: s/exceeds crlfDelay
/exceeds crlfDelay
milliseconds
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.
also... should there be a maximum delay? And how does one turn off the delay entirely? In other APIs, we've used setting the value explicitly to 0
or null
or Infinity
to turn it off.
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.
I am not sure about the maximum delay but minimum delay should not be zero. the reason is subsequent events(\r
followed by \n
) may have latency greater than or equal to 1ms. It will obviously break windows system.
What do you suggest ? 10ms as minimum delay?
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.
That should work.
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.
I am afraid to put 10ms (seems low because of context switches and other factors). Now I set [100, 2000]
as range. It will go few more rounds to come up with better range 😄
Another attempt, CI: https://ci.nodejs.org/job/node-test-pull-request/3766/ |
rli = new readline.Interface({ input: fi, output: fi, crlfDelay: 1 << 30}); | ||
assert.strictEqual(rli.crlfDelay, 2000); | ||
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.
To 3 separate scopes?
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.
@yorkie done
Emit two line events when there is a delay between CR('\r') and LF('\n')
8d1d416
to
3b1b84e
Compare
callCount++; | ||
}); | ||
fi.emit('data', '\r'); | ||
setTimeout(() => { |
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.
Wrap this function with common.mustCall
?
LGTM :) |
@jasnell @Fishrock123 @mscdex PTAL |
LGTM |
1 similar comment
LGTM |
Trying again for green build: https://ci.nodejs.org/job/node-test-pull-request/3865/ |
build bot failure on the last CI run... trying one final time for green: https://ci.nodejs.org/job/node-test-pull-request/3897/ |
@jasnell failed again 😞 |
@nodejs/build @jbergstroem ... can someone take a look to see what's happening with the arm build bot on this? |
ping @nodejs/build |
@jasnell I see full of red & unstable CI jobs. I'll trigger build after few days to get green build |
We've fixed the arm issues; disk-related. Please try again! |
CI: https://ci.nodejs.org/job/node-test-pull-request/3943/ Last CI run: https://ci.nodejs.org/job/node-test-pull-request/3959/ (unstable) |
@jbergstroem last two build attempts - unstable. can you take a look? |
@princejwesley 3959,3960 looked good though! Flaky is fine -- it means a test is known to fail. |
Emit two line events when there is a delay between CR('\r') and LF('\n'). Introduced a new option `crlfDelay`. If the delay between \r and \n exceeds `crlfDelay` milliseconds, both \r and \n will be treated as separate end-of-line input. Default to 100 milliseconds. `crlfDelay` will be coerced to [100, 2000] range. PR-URL: #8109 Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Landed in a634554 |
Emit two line events when there is a delay between CR('\r') and LF('\n'). Introduced a new option `crlfDelay`. If the delay between \r and \n exceeds `crlfDelay` milliseconds, both \r and \n will be treated as separate end-of-line input. Default to 100 milliseconds. `crlfDelay` will be coerced to [100, 2000] range. PR-URL: #8109 Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
readline
Description of change
Emit two line events when there is a delay between
CR('\r') and LF('\n')