diff options
author | Rich Trott <rtrott@gmail.com> | 2015-05-20 21:17:10 -0700 |
---|---|---|
committer | Rod Vagg <rod@vagg.org> | 2015-08-04 11:56:17 -0700 |
commit | 4cffaa3f558bd1154759c5175ca773f809b68be6 (patch) | |
tree | cd0253d8277302a8da5001e1079cb38e987426e3 /lib/readline.js | |
parent | 971de5e4176444b18ba09229eb4c2f33b29b2d3d (diff) | |
download | android-node-v8-4cffaa3f558bd1154759c5175ca773f809b68be6.tar.gz android-node-v8-4cffaa3f558bd1154759c5175ca773f809b68be6.tar.bz2 android-node-v8-4cffaa3f558bd1154759c5175ca773f809b68be6.zip |
readline: allow tabs in input
If tab completion is not being used, allow user to enter tab
characters.
PR-URL: https://github.com/nodejs/io.js/pull/1761
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
Diffstat (limited to 'lib/readline.js')
-rw-r--r-- | lib/readline.js | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/readline.js b/lib/readline.js index 741f58b934..02fa9d08f6 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -49,9 +49,7 @@ function Interface(input, output, completer, terminal) { } historySize = historySize || kHistorySize; - completer = completer || function() { return []; }; - - if (typeof completer !== 'function') { + if (completer && typeof completer !== 'function') { throw new TypeError('Argument \'completer\' must be a function'); } @@ -74,9 +72,11 @@ function Interface(input, output, completer, terminal) { this.historySize = historySize; // Check arity, 2 - for async, 1 for sync - this.completer = completer.length === 2 ? completer : function(v, callback) { - callback(null, completer(v)); - }; + if (typeof completer === 'function') { + this.completer = completer.length === 2 ? completer : function(v, cb) { + cb(null, completer(v)); + }; + } this.setPrompt('> '); @@ -346,9 +346,6 @@ 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); @@ -841,10 +838,6 @@ Interface.prototype._ttyWrite = function(s, key) { this._deleteRight(); break; - case 'tab': // tab completion - this._tabComplete(); - break; - case 'left': this._moveCursor(-1); break; @@ -869,6 +862,14 @@ 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'); |