@@ -47,9 +47,7 @@ function Interface(input, output, completer, terminal) {
4747  } 
4848  historySize  =  historySize  ||  kHistorySize ; 
4949
50-   completer  =  completer  ||  function ( )  {  return  [ ] ;  } ; 
51- 
52-   if  ( typeof  completer  !==  'function' )  { 
50+   if  ( completer  &&  typeof  completer  !==  'function' )  { 
5351    throw  new  TypeError ( 'Argument \'completer\' must be a function' ) ; 
5452  } 
5553
@@ -72,9 +70,11 @@ function Interface(input, output, completer, terminal) {
7270  this . historySize  =  historySize ; 
7371
7472  // 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+   } 
7878
7979  this . setPrompt ( '> ' ) ; 
8080
@@ -344,9 +344,6 @@ Interface.prototype._normalWrite = function(b) {
344344} ; 
345345
346346Interface . 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'. 
350347  if  ( this . cursor  <  this . line . length )  { 
351348    var  beg  =  this . line . slice ( 0 ,  this . cursor ) ; 
352349    var  end  =  this . line . slice ( this . cursor ,  this . line . length ) ; 
@@ -839,10 +836,6 @@ Interface.prototype._ttyWrite = function(s, key) {
839836        this . _deleteRight ( ) ; 
840837        break ; 
841838
842-       case  'tab' : // tab completion 
843-         this . _tabComplete ( ) ; 
844-         break ; 
845- 
846839      case  'left' :
847840        this . _moveCursor ( - 1 ) ; 
848841        break ; 
@@ -867,6 +860,14 @@ Interface.prototype._ttyWrite = function(s, key) {
867860        this . _historyNext ( ) ; 
868861        break ; 
869862
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+ 
870871      default :
871872        if  ( s  instanceof  Buffer ) 
872873          s  =  s . toString ( 'utf-8' ) ; 
0 commit comments