@@ -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,12 @@ 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  ? 
75+       completer  : function ( v ,  callback )  { 
76+         callback ( null ,  completer ( v ) ) ; 
77+       } ; 
78+   } 
7879
7980  this . setPrompt ( '> ' ) ; 
8081
@@ -344,9 +345,6 @@ Interface.prototype._normalWrite = function(b) {
344345} ; 
345346
346347Interface . 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'. 
350348  if  ( this . cursor  <  this . line . length )  { 
351349    var  beg  =  this . line . slice ( 0 ,  this . cursor ) ; 
352350    var  end  =  this . line . slice ( this . cursor ,  this . line . length ) ; 
@@ -839,10 +837,6 @@ Interface.prototype._ttyWrite = function(s, key) {
839837        this . _deleteRight ( ) ; 
840838        break ; 
841839
842-       case  'tab' : // tab completion 
843-         this . _tabComplete ( ) ; 
844-         break ; 
845- 
846840      case  'left' :
847841        this . _moveCursor ( - 1 ) ; 
848842        break ; 
@@ -867,6 +861,14 @@ Interface.prototype._ttyWrite = function(s, key) {
867861        this . _historyNext ( ) ; 
868862        break ; 
869863
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+ 
870872      default :
871873        if  ( s  instanceof  Buffer ) 
872874          s  =  s . toString ( 'utf-8' ) ; 
0 commit comments