@@ -47,9 +47,7 @@ function Interface(input, output, completer, terminal) {
47
47
}
48
48
historySize = historySize || kHistorySize ;
49
49
50
- completer = completer || function ( ) { return [ ] ; } ;
51
-
52
- if ( typeof completer !== 'function' ) {
50
+ if ( completer && typeof completer !== 'function' ) {
53
51
throw new TypeError ( 'Argument \'completer\' must be a function' ) ;
54
52
}
55
53
@@ -72,9 +70,11 @@ function Interface(input, output, completer, terminal) {
72
70
this . historySize = historySize ;
73
71
74
72
// Check arity, 2 - for async, 1 for sync
75
- this . completer = completer . length === 2 ? completer : function ( v , callback ) {
76
- callback ( null , completer ( v ) ) ;
77
- } ;
73
+ if ( typeof completer === 'function' ) {
74
+ this . completer = completer . length === 2 ? completer : function ( v , cb ) {
75
+ cb ( null , completer ( v ) ) ;
76
+ } ;
77
+ }
78
78
79
79
this . setPrompt ( '> ' ) ;
80
80
@@ -344,9 +344,6 @@ Interface.prototype._normalWrite = function(b) {
344
344
} ;
345
345
346
346
Interface . prototype . _insertString = function ( c ) {
347
- //BUG: Problem when adding tabs with following content.
348
- // Perhaps the bug is in _refreshLine(). Not sure.
349
- // A hack would be to insert spaces instead of literal '\t'.
350
347
if ( this . cursor < this . line . length ) {
351
348
var beg = this . line . slice ( 0 , this . cursor ) ;
352
349
var end = this . line . slice ( this . cursor , this . line . length ) ;
@@ -839,10 +836,6 @@ Interface.prototype._ttyWrite = function(s, key) {
839
836
this . _deleteRight ( ) ;
840
837
break ;
841
838
842
- case 'tab' : // tab completion
843
- this . _tabComplete ( ) ;
844
- break ;
845
-
846
839
case 'left' :
847
840
this . _moveCursor ( - 1 ) ;
848
841
break ;
@@ -867,6 +860,14 @@ Interface.prototype._ttyWrite = function(s, key) {
867
860
this . _historyNext ( ) ;
868
861
break ;
869
862
863
+ case 'tab' :
864
+ // If tab completion enabled, do that...
865
+ if ( typeof this . completer === 'function' ) {
866
+ this . _tabComplete ( ) ;
867
+ break ;
868
+ }
869
+ // falls through
870
+
870
871
default :
871
872
if ( s instanceof Buffer )
872
873
s = s . toString ( 'utf-8' ) ;
0 commit comments