readline: rename deDupeHistory
option
Renames `options.deDupeHistory` → `options.removeHistoryDuplicates` for `readline.createInterface(options)`. The option name `removeHistoryDuplicates` is preferable to the semantically identical name `deDupeHistory` because "dedupe" (short for "deduplication") is obscure and neologistic while `removeHistoryDuplicates` is clear, though verbose. Updates tests and documentation for this option accordingly. PR-URL: https://github.com/nodejs/node/pull/11950 Ref: https://github.com/nodejs/node/pull/2982 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
e26b6c6baa
commit
c8eec76c5f
@ -370,9 +370,9 @@ changes:
|
|||||||
`crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate
|
`crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate
|
||||||
end-of-line input. Default to `100` milliseconds.
|
end-of-line input. Default to `100` milliseconds.
|
||||||
`crlfDelay` will be coerced to `[100, 2000]` range.
|
`crlfDelay` will be coerced to `[100, 2000]` range.
|
||||||
* `deDupeHistory` {boolean} If `true`, when a new input line added to the
|
* `removeHistoryDuplicates` {boolean} If `true`, when a new input line added
|
||||||
history list duplicates an older one, this removes the older line from the
|
to the history list duplicates an older one, this removes the older line
|
||||||
list. Defaults to `false`.
|
from the list. Defaults to `false`.
|
||||||
|
|
||||||
The `readline.createInterface()` method creates a new `readline.Interface`
|
The `readline.createInterface()` method creates a new `readline.Interface`
|
||||||
instance.
|
instance.
|
||||||
|
@ -60,7 +60,7 @@ function Interface(input, output, completer, terminal) {
|
|||||||
|
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
var historySize;
|
var historySize;
|
||||||
var deDupeHistory = false;
|
var removeHistoryDuplicates = false;
|
||||||
let crlfDelay;
|
let crlfDelay;
|
||||||
let prompt = '> ';
|
let prompt = '> ';
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ function Interface(input, output, completer, terminal) {
|
|||||||
completer = input.completer;
|
completer = input.completer;
|
||||||
terminal = input.terminal;
|
terminal = input.terminal;
|
||||||
historySize = input.historySize;
|
historySize = input.historySize;
|
||||||
deDupeHistory = input.deDupeHistory;
|
removeHistoryDuplicates = input.removeHistoryDuplicates;
|
||||||
if (input.prompt !== undefined) {
|
if (input.prompt !== undefined) {
|
||||||
prompt = input.prompt;
|
prompt = input.prompt;
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ function Interface(input, output, completer, terminal) {
|
|||||||
this.output = output;
|
this.output = output;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.historySize = historySize;
|
this.historySize = historySize;
|
||||||
this.deDupeHistory = !!deDupeHistory;
|
this.removeHistoryDuplicates = !!removeHistoryDuplicates;
|
||||||
this.crlfDelay = Math.max(kMincrlfDelay,
|
this.crlfDelay = Math.max(kMincrlfDelay,
|
||||||
Math.min(kMaxcrlfDelay, crlfDelay >>> 0));
|
Math.min(kMaxcrlfDelay, crlfDelay >>> 0));
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ Interface.prototype._addHistory = function() {
|
|||||||
if (this.line.trim().length === 0) return this.line;
|
if (this.line.trim().length === 0) return this.line;
|
||||||
|
|
||||||
if (this.history.length === 0 || this.history[0] !== this.line) {
|
if (this.history.length === 0 || this.history[0] !== this.line) {
|
||||||
if (this.deDupeHistory) {
|
if (this.removeHistoryDuplicates) {
|
||||||
// Remove older history line if identical to new one
|
// Remove older history line if identical to new one
|
||||||
const dupIndex = this.history.indexOf(this.line);
|
const dupIndex = this.history.indexOf(this.line);
|
||||||
if (dupIndex !== -1) this.history.splice(dupIndex, 1);
|
if (dupIndex !== -1) this.history.splice(dupIndex, 1);
|
||||||
|
@ -326,14 +326,14 @@ function isWarned(emitter) {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// duplicate lines are removed from history when `options.deDupeHistory`
|
// duplicate lines are removed from history when
|
||||||
// is `true`
|
// `options.removeHistoryDuplicates` is `true`
|
||||||
fi = new FakeInput();
|
fi = new FakeInput();
|
||||||
rli = new readline.Interface({
|
rli = new readline.Interface({
|
||||||
input: fi,
|
input: fi,
|
||||||
output: fi,
|
output: fi,
|
||||||
terminal: true,
|
terminal: true,
|
||||||
deDupeHistory: true
|
removeHistoryDuplicates: true
|
||||||
});
|
});
|
||||||
expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
|
expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
|
||||||
callCount = 0;
|
callCount = 0;
|
||||||
@ -356,14 +356,14 @@ function isWarned(emitter) {
|
|||||||
assert.strictEqual(callCount, 0);
|
assert.strictEqual(callCount, 0);
|
||||||
rli.close();
|
rli.close();
|
||||||
|
|
||||||
// duplicate lines are not removed from history when `options.deDupeHistory`
|
// duplicate lines are not removed from history when
|
||||||
// is `false`
|
// `options.removeHistoryDuplicates` is `false`
|
||||||
fi = new FakeInput();
|
fi = new FakeInput();
|
||||||
rli = new readline.Interface({
|
rli = new readline.Interface({
|
||||||
input: fi,
|
input: fi,
|
||||||
output: fi,
|
output: fi,
|
||||||
terminal: true,
|
terminal: true,
|
||||||
deDupeHistory: false
|
removeHistoryDuplicates: false
|
||||||
});
|
});
|
||||||
expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
|
expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
|
||||||
callCount = 0;
|
callCount = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user