Skip to content

Commit

Permalink
readline: rename deDupeHistory option
Browse files Browse the repository at this point in the history
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: #11950
Ref: #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>
  • Loading branch information
DannyNemer authored and MylesBorins committed May 16, 2017
1 parent d3dafd6 commit 5bbe2f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions doc/api/readline.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ added: v0.1.98
`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.
* `deDupeHistory` {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`.
* `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`.

The `readline.createInterface()` method creates a new `readline.Interface`
instance.
Expand Down
8 changes: 4 additions & 4 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Interface(input, output, completer, terminal) {

EventEmitter.call(this);
var historySize;
var deDupeHistory = false;
var removeHistoryDuplicates = false;
let crlfDelay;
let prompt = '> ';

Expand All @@ -49,7 +49,7 @@ function Interface(input, output, completer, terminal) {
completer = input.completer;
terminal = input.terminal;
historySize = input.historySize;
deDupeHistory = input.deDupeHistory;
removeHistoryDuplicates = input.removeHistoryDuplicates;
if (input.prompt !== undefined) {
prompt = input.prompt;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ function Interface(input, output, completer, terminal) {
this.output = output;
this.input = input;
this.historySize = historySize;
this.deDupeHistory = !!deDupeHistory;
this.removeHistoryDuplicates = !!removeHistoryDuplicates;
this.crlfDelay = Math.max(kMincrlfDelay,
Math.min(kMaxcrlfDelay, crlfDelay >>> 0));

Expand Down Expand Up @@ -252,7 +252,7 @@ Interface.prototype._addHistory = function() {
if (this.line.trim().length === 0) return 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
const dupIndex = this.history.indexOf(this.line);
if (dupIndex !== -1) this.history.splice(dupIndex, 1);
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ function isWarned(emitter) {
return false;
});

// duplicate lines are removed from history when `options.deDupeHistory`
// is `true`
// duplicate lines are removed from history when
// `options.removeHistoryDuplicates` is `true`
fi = new FakeInput();
rli = new readline.Interface({
input: fi,
output: fi,
terminal: true,
deDupeHistory: true
removeHistoryDuplicates: true
});
expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
callCount = 0;
Expand All @@ -333,14 +333,14 @@ function isWarned(emitter) {
assert.strictEqual(callCount, 0);
rli.close();

// duplicate lines are not removed from history when `options.deDupeHistory`
// is `false`
// duplicate lines are not removed from history when
// `options.removeHistoryDuplicates` is `false`
fi = new FakeInput();
rli = new readline.Interface({
input: fi,
output: fi,
terminal: true,
deDupeHistory: false
removeHistoryDuplicates: false
});
expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
callCount = 0;
Expand Down

0 comments on commit 5bbe2f6

Please sign in to comment.