@@ -48,9 +48,7 @@ function Interface(input, output, completer, terminal) {
4848 }
4949 historySize = historySize || kHistorySize ;
5050
51- completer = completer || function ( ) { return [ ] ; } ;
52-
53- if ( typeof completer !== 'function' ) {
51+ if ( completer && typeof completer !== 'function' ) {
5452 throw new TypeError ( 'Argument \'completer\' must be a function' ) ;
5553 }
5654
@@ -73,9 +71,11 @@ function Interface(input, output, completer, terminal) {
7371 this . historySize = historySize ;
7472
7573 // Check arity, 2 - for async, 1 for sync
76- this . completer = completer . length === 2 ? completer : function ( v , callback ) {
77- callback ( null , completer ( v ) ) ;
78- } ;
74+ if ( typeof completer === 'function' ) {
75+ this . completer = completer . length === 2 ? completer : function ( v , cb ) {
76+ cb ( null , completer ( v ) ) ;
77+ } ;
78+ }
7979
8080 this . setPrompt ( '> ' ) ;
8181
@@ -345,9 +345,6 @@ Interface.prototype._normalWrite = function(b) {
345345} ;
346346
347347Interface . prototype . _insertString = function ( c ) {
348- //BUG: Problem when adding tabs with following content.
349- // Perhaps the bug is in _refreshLine(). Not sure.
350- // A hack would be to insert spaces instead of literal '\t'.
351348 if ( this . cursor < this . line . length ) {
352349 var beg = this . line . slice ( 0 , this . cursor ) ;
353350 var end = this . line . slice ( this . cursor , this . line . length ) ;
@@ -840,10 +837,6 @@ Interface.prototype._ttyWrite = function(s, key) {
840837 this . _deleteRight ( ) ;
841838 break ;
842839
843- case 'tab' : // tab completion
844- this . _tabComplete ( ) ;
845- break ;
846-
847840 case 'left' :
848841 this . _moveCursor ( - 1 ) ;
849842 break ;
@@ -868,6 +861,14 @@ Interface.prototype._ttyWrite = function(s, key) {
868861 this . _historyNext ( ) ;
869862 break ;
870863
864+ case 'tab' :
865+ // If tab completion enabled, do that...
866+ if ( typeof this . completer === 'function' ) {
867+ this . _tabComplete ( ) ;
868+ break ;
869+ }
870+ // falls through
871+
871872 default :
872873 if ( s instanceof Buffer )
873874 s = s . toString ( 'utf-8' ) ;
0 commit comments