@@ -49,9 +49,7 @@ function Interface(input, output, completer, terminal) {
4949 }
5050 historySize = historySize || kHistorySize ;
5151
52- completer = completer || function ( ) { return [ ] ; } ;
53-
54- if ( typeof completer !== 'function' ) {
52+ if ( completer && typeof completer !== 'function' ) {
5553 throw new TypeError ( 'Argument \'completer\' must be a function' ) ;
5654 }
5755
@@ -74,9 +72,11 @@ function Interface(input, output, completer, terminal) {
7472 this . historySize = historySize ;
7573
7674 // Check arity, 2 - for async, 1 for sync
77- this . completer = completer . length === 2 ? completer : function ( v , callback ) {
78- callback ( null , completer ( v ) ) ;
79- } ;
75+ if ( typeof completer === 'function' ) {
76+ this . completer = completer . length === 2 ? completer : function ( v , cb ) {
77+ cb ( null , completer ( v ) ) ;
78+ } ;
79+ }
8080
8181 this . setPrompt ( '> ' ) ;
8282
@@ -346,9 +346,6 @@ Interface.prototype._normalWrite = function(b) {
346346} ;
347347
348348Interface . 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'.
352349 if ( this . cursor < this . line . length ) {
353350 var beg = this . line . slice ( 0 , this . cursor ) ;
354351 var end = this . line . slice ( this . cursor , this . line . length ) ;
@@ -841,10 +838,6 @@ Interface.prototype._ttyWrite = function(s, key) {
841838 this . _deleteRight ( ) ;
842839 break ;
843840
844- case 'tab' : // tab completion
845- this . _tabComplete ( ) ;
846- break ;
847-
848841 case 'left' :
849842 this . _moveCursor ( - 1 ) ;
850843 break ;
@@ -869,6 +862,14 @@ Interface.prototype._ttyWrite = function(s, key) {
869862 this . _historyNext ( ) ;
870863 break ;
871864
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+
872873 default :
873874 if ( s instanceof Buffer )
874875 s = s . toString ( 'utf-8' ) ;
0 commit comments