Skip to content

Commit 83167ee

Browse files
Fishrock123rvagg
authored andcommitted
Revert "readline: allow tabs in input"
This reverts commit 4b3d493. PR-URL: #1961 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
1 parent 133e99b commit 83167ee

File tree

2 files changed

+13
-67
lines changed

2 files changed

+13
-67
lines changed

lib/readline.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ function Interface(input, output, completer, terminal) {
4949
}
5050
historySize = historySize || kHistorySize;
5151

52-
if (completer && typeof completer !== 'function') {
52+
completer = completer || function() { return []; };
53+
54+
if (typeof completer !== 'function') {
5355
throw new TypeError('Argument \'completer\' must be a function');
5456
}
5557

@@ -72,11 +74,9 @@ function Interface(input, output, completer, terminal) {
7274
this.historySize = historySize;
7375

7476
// Check arity, 2 - for async, 1 for sync
75-
if (typeof completer === 'function') {
76-
this.completer = completer.length === 2 ? completer : function(v, cb) {
77-
cb(null, completer(v));
78-
};
79-
}
77+
this.completer = completer.length === 2 ? completer : function(v, callback) {
78+
callback(null, completer(v));
79+
};
8080

8181
this.setPrompt('> ');
8282

@@ -346,6 +346,9 @@ Interface.prototype._normalWrite = function(b) {
346346
};
347347

348348
Interface.prototype._insertString = function(c) {
349+
//BUG: Problem when adding tabs with following content.
350+
// Perhaps the bug is in _refreshLine(). Not sure.
351+
// A hack would be to insert spaces instead of literal '\t'.
349352
if (this.cursor < this.line.length) {
350353
var beg = this.line.slice(0, this.cursor);
351354
var end = this.line.slice(this.cursor, this.line.length);
@@ -838,6 +841,10 @@ Interface.prototype._ttyWrite = function(s, key) {
838841
this._deleteRight();
839842
break;
840843

844+
case 'tab': // tab completion
845+
this._tabComplete();
846+
break;
847+
841848
case 'left':
842849
this._moveCursor(-1);
843850
break;
@@ -862,14 +869,6 @@ Interface.prototype._ttyWrite = function(s, key) {
862869
this._historyNext();
863870
break;
864871

865-
case 'tab':
866-
// If tab completion enabled, do that...
867-
if (typeof this.completer === 'function') {
868-
this._tabComplete();
869-
break;
870-
}
871-
// falls through
872-
873872
default:
874873
if (s instanceof Buffer)
875874
s = s.toString('utf-8');

test/parallel/test-readline-interface.js

-53
Original file line numberDiff line numberDiff line change
@@ -175,59 +175,6 @@ function isWarned(emitter) {
175175
assert.equal(callCount, expectedLines.length);
176176
rli.close();
177177

178-
// \t when there is no completer function should behave like an ordinary
179-
// character
180-
fi = new FakeInput();
181-
rli = new readline.Interface({ input: fi, output: fi, terminal: true });
182-
called = false;
183-
rli.on('line', function(line) {
184-
assert.equal(line, '\t');
185-
assert.strictEqual(called, false);
186-
called = true;
187-
});
188-
fi.emit('data', '\t');
189-
fi.emit('data', '\n');
190-
assert.ok(called);
191-
rli.close();
192-
193-
// \t does not become part of the input when there is a completer function
194-
fi = new FakeInput();
195-
var completer = function(line) {
196-
return [[], line];
197-
};
198-
rli = new readline.Interface({
199-
input: fi,
200-
output: fi,
201-
terminal: true,
202-
completer: completer
203-
});
204-
called = false;
205-
rli.on('line', function(line) {
206-
assert.equal(line, 'foo');
207-
assert.strictEqual(called, false);
208-
called = true;
209-
});
210-
fi.emit('data', '\tfo\to\t');
211-
fi.emit('data', '\n');
212-
assert.ok(called);
213-
rli.close();
214-
215-
// constructor throws if completer is not a function or undefined
216-
fi = new FakeInput();
217-
assert.throws(function() {
218-
readline.createInterface({
219-
input: fi,
220-
completer: 'string is not valid'
221-
});
222-
}, function(err) {
223-
if (err instanceof TypeError) {
224-
if (/Argument \'completer\' must be a function/.test(err)) {
225-
return true;
226-
}
227-
}
228-
return false;
229-
});
230-
231178
// sending a multi-byte utf8 char over multiple writes
232179
var buf = Buffer('☮', 'utf8');
233180
fi = new FakeInput();

0 commit comments

Comments
 (0)