|
|
@ -48,7 +48,9 @@ function Interface(input, output, completer, terminal) { |
|
|
|
} |
|
|
|
historySize = historySize || kHistorySize; |
|
|
|
|
|
|
|
if (completer && typeof completer !== 'function') { |
|
|
|
completer = completer || function() { return []; }; |
|
|
|
|
|
|
|
if (typeof completer !== 'function') { |
|
|
|
throw new TypeError('Argument \'completer\' must be a function'); |
|
|
|
} |
|
|
|
|
|
|
@ -71,11 +73,9 @@ function Interface(input, output, completer, terminal) { |
|
|
|
this.historySize = historySize; |
|
|
|
|
|
|
|
// Check arity, 2 - for async, 1 for sync
|
|
|
|
if (typeof completer === 'function') { |
|
|
|
this.completer = completer.length === 2 ? completer : function(v, cb) { |
|
|
|
cb(null, completer(v)); |
|
|
|
}; |
|
|
|
} |
|
|
|
this.completer = completer.length === 2 ? completer : function(v, callback) { |
|
|
|
callback(null, completer(v)); |
|
|
|
}; |
|
|
|
|
|
|
|
this.setPrompt('> '); |
|
|
|
|
|
|
@ -345,6 +345,9 @@ Interface.prototype._normalWrite = function(b) { |
|
|
|
}; |
|
|
|
|
|
|
|
Interface.prototype._insertString = function(c) { |
|
|
|
//BUG: Problem when adding tabs with following content.
|
|
|
|
// Perhaps the bug is in _refreshLine(). Not sure.
|
|
|
|
// A hack would be to insert spaces instead of literal '\t'.
|
|
|
|
if (this.cursor < this.line.length) { |
|
|
|
var beg = this.line.slice(0, this.cursor); |
|
|
|
var end = this.line.slice(this.cursor, this.line.length); |
|
|
@ -837,6 +840,10 @@ Interface.prototype._ttyWrite = function(s, key) { |
|
|
|
this._deleteRight(); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'tab': // tab completion
|
|
|
|
this._tabComplete(); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'left': |
|
|
|
this._moveCursor(-1); |
|
|
|
break; |
|
|
@ -861,14 +868,6 @@ Interface.prototype._ttyWrite = function(s, key) { |
|
|
|
this._historyNext(); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'tab': |
|
|
|
// If tab completion enabled, do that...
|
|
|
|
if (typeof this.completer === 'function') { |
|
|
|
this._tabComplete(); |
|
|
|
break; |
|
|
|
} |
|
|
|
// falls through
|
|
|
|
|
|
|
|
default: |
|
|
|
if (s instanceof Buffer) |
|
|
|
s = s.toString('utf-8'); |
|
|
|