@@ -49,7 +49,9 @@ function Interface(input, output, completer, terminal) {
49
49
}
50
50
historySize = historySize || kHistorySize ;
51
51
52
- if ( completer && typeof completer !== 'function' ) {
52
+ completer = completer || function ( ) { return [ ] ; } ;
53
+
54
+ if ( typeof completer !== 'function' ) {
53
55
throw new TypeError ( 'Argument \'completer\' must be a function' ) ;
54
56
}
55
57
@@ -72,11 +74,9 @@ function Interface(input, output, completer, terminal) {
72
74
this . historySize = historySize ;
73
75
74
76
// 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
+ } ;
80
80
81
81
this . setPrompt ( '> ' ) ;
82
82
@@ -346,6 +346,9 @@ Interface.prototype._normalWrite = function(b) {
346
346
} ;
347
347
348
348
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'.
349
352
if ( this . cursor < this . line . length ) {
350
353
var beg = this . line . slice ( 0 , this . cursor ) ;
351
354
var end = this . line . slice ( this . cursor , this . line . length ) ;
@@ -838,6 +841,10 @@ Interface.prototype._ttyWrite = function(s, key) {
838
841
this . _deleteRight ( ) ;
839
842
break ;
840
843
844
+ case 'tab' : // tab completion
845
+ this . _tabComplete ( ) ;
846
+ break ;
847
+
841
848
case 'left' :
842
849
this . _moveCursor ( - 1 ) ;
843
850
break ;
@@ -862,14 +869,6 @@ Interface.prototype._ttyWrite = function(s, key) {
862
869
this . _historyNext ( ) ;
863
870
break ;
864
871
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
-
873
872
default :
874
873
if ( s instanceof Buffer )
875
874
s = s . toString ( 'utf-8' ) ;
0 commit comments