@@ -48,7 +48,9 @@ function Interface(input, output, completer, terminal) {
4848 }
4949 historySize = historySize || kHistorySize ;
5050
51- if ( completer && typeof completer !== 'function' ) {
51+ completer = completer || function ( ) { return [ ] ; } ;
52+
53+ if ( typeof completer !== 'function' ) {
5254 throw new TypeError ( 'Argument \'completer\' must be a function' ) ;
5355 }
5456
@@ -71,11 +73,9 @@ function Interface(input, output, completer, terminal) {
7173 this . historySize = historySize ;
7274
7375 // Check arity, 2 - for async, 1 for sync
74- if ( typeof completer === 'function' ) {
75- this . completer = completer . length === 2 ? completer : function ( v , cb ) {
76- cb ( null , completer ( v ) ) ;
77- } ;
78- }
76+ this . completer = completer . length === 2 ? completer : function ( v , callback ) {
77+ callback ( null , completer ( v ) ) ;
78+ } ;
7979
8080 this . setPrompt ( '> ' ) ;
8181
@@ -345,6 +345,9 @@ 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'.
348351 if ( this . cursor < this . line . length ) {
349352 var beg = this . line . slice ( 0 , this . cursor ) ;
350353 var end = this . line . slice ( this . cursor , this . line . length ) ;
@@ -837,6 +840,10 @@ Interface.prototype._ttyWrite = function(s, key) {
837840 this . _deleteRight ( ) ;
838841 break ;
839842
843+ case 'tab' : // tab completion
844+ this . _tabComplete ( ) ;
845+ break ;
846+
840847 case 'left' :
841848 this . _moveCursor ( - 1 ) ;
842849 break ;
@@ -861,14 +868,6 @@ Interface.prototype._ttyWrite = function(s, key) {
861868 this . _historyNext ( ) ;
862869 break ;
863870
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-
872871 default :
873872 if ( s instanceof Buffer )
874873 s = s . toString ( 'utf-8' ) ;
0 commit comments