Permalink
Browse files

readline: remove max limit of crlfDelay

Backport-PR-URL: #14899
PR-URL: #13497
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information...
Azard authored and MylesBorins committed Aug 17, 2017
1 parent 14cc1ab commit 86047729605ad71654e5262593c5200417944736
Showing with 69 additions and 10 deletions.
  1. +3 −1 doc/api/readline.md
  2. +2 −3 lib/readline.js
  3. +64 −6 test/parallel/test-readline-interface.js
View
@@ -362,7 +362,9 @@ added: v0.1.98
* `crlfDelay` {number} 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.
`crlfDelay` will be coerced to a number no less than `100`. It can be set to
`Infinity`, in which case `\r` followed by `\n` will always be considered a
single newline.
* `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. Defaults to `false`.
View
@@ -8,7 +8,6 @@
const kHistorySize = 30;
const kMincrlfDelay = 100;
const kMaxcrlfDelay = 2000;
const util = require('util');
const debug = util.debuglog('readline');
@@ -83,8 +82,8 @@ function Interface(input, output, completer, terminal) {
this.input = input;
this.historySize = historySize;
this.removeHistoryDuplicates = !!removeHistoryDuplicates;
this.crlfDelay = Math.max(kMincrlfDelay,
Math.min(kMaxcrlfDelay, crlfDelay >>> 0));
this.crlfDelay = crlfDelay ?
Math.max(kMincrlfDelay, crlfDelay) : kMincrlfDelay;
// Check arity, 2 - for async, 1 for sync
if (typeof completer === 'function') {
@@ -40,14 +40,25 @@ function isWarned(emitter) {
}
{
// Maximum crlfDelay is 2000ms
// set crlfDelay to float 100.5ms
const fi = new FakeInput();
const rli = new readline.Interface({
input: fi,
output: fi,
crlfDelay: 1 << 30
crlfDelay: 100.5
});
assert.strictEqual(rli.crlfDelay, 2000);
assert.strictEqual(rli.crlfDelay, 100.5);
rli.close();
}
{
const fi = new FakeInput();
const rli = new readline.Interface({
input: fi,
output: fi,
crlfDelay: 5000
});
assert.strictEqual(rli.crlfDelay, 5000);
rli.close();
}
@@ -225,7 +236,7 @@ function isWarned(emitter) {
rli.close();
// Emit two line events when the delay
// between \r and \n exceeds crlfDelay
// between \r and \n exceeds crlfDelay
{
const fi = new FakeInput();
const delay = 200;
@@ -247,8 +258,55 @@ function isWarned(emitter) {
}), delay * 2);
}
// Emit one line events when the delay between \r and \n is
// over the default crlfDelay but within the setting value
{
const fi = new FakeInput();
const delay = 200;
const crlfDelay = 500;
const rli = new readline.Interface({
input: fi,
output: fi,
terminal: terminal,
crlfDelay
});
let callCount = 0;
rli.on('line', function(line) {
callCount++;
});
fi.emit('data', '\r');
setTimeout(common.mustCall(() => {
fi.emit('data', '\n');
assert.strictEqual(callCount, 1);
rli.close();
}), delay);
}
// set crlfDelay to `Infinity` is allowed
{
const fi = new FakeInput();
const delay = 200;
const crlfDelay = Infinity;
const rli = new readline.Interface({
input: fi,
output: fi,
terminal: terminal,
crlfDelay
});
let callCount = 0;
rli.on('line', function(line) {
callCount++;
});
fi.emit('data', '\r');
setTimeout(common.mustCall(() => {
fi.emit('data', '\n');
assert.strictEqual(callCount, 1);
rli.close();
}), delay);
}
// \t when there is no completer function should behave like an ordinary
// character
// character
fi = new FakeInput();
rli = new readline.Interface({ input: fi, output: fi, terminal: true });
called = false;
@@ -494,7 +552,7 @@ function isWarned(emitter) {
assert.strictEqual(isWarned(process.stdout._events), false);
}
//can create a new readline Interface with a null output arugument
// can create a new readline Interface with a null output arugument
fi = new FakeInput();
rli = new readline.Interface({input: fi, output: null, terminal: terminal });

0 comments on commit 8604772

Please sign in to comment.