@@ -126,9 +126,11 @@ function Interface(input, output, completer, terminal) {
126
126
127
127
// Check arity, 2 - for async, 1 for sync
128
128
if ( typeof completer === 'function' ) {
129
- this . completer = completer . length === 2 ? completer : function ( v , cb ) {
130
- cb ( null , completer ( v ) ) ;
131
- } ;
129
+ this . completer = completer . length === 2 ?
130
+ completer :
131
+ function completerWrapper ( v , cb ) {
132
+ cb ( null , completer ( v ) ) ;
133
+ } ;
132
134
}
133
135
134
136
this . setPrompt ( prompt ) ;
@@ -171,15 +173,23 @@ function Interface(input, output, completer, terminal) {
171
173
}
172
174
173
175
if ( ! this . terminal ) {
174
- input . on ( 'data' , ondata ) ;
175
- input . on ( 'end' , onend ) ;
176
- self . once ( 'close' , function ( ) {
176
+ function onSelfCloseWithoutTerminal ( ) {
177
177
input . removeListener ( 'data' , ondata ) ;
178
178
input . removeListener ( 'end' , onend ) ;
179
- } ) ;
180
- this . _decoder = new StringDecoder ( 'utf8' ) ;
179
+ }
181
180
181
+ input . on ( 'data' , ondata ) ;
182
+ input . on ( 'end' , onend ) ;
183
+ self . once ( 'close' , onSelfCloseWithoutTerminal ) ;
184
+ this . _decoder = new StringDecoder ( 'utf8' ) ;
182
185
} else {
186
+ function onSelfCloseWithTerminal ( ) {
187
+ input . removeListener ( 'keypress' , onkeypress ) ;
188
+ input . removeListener ( 'end' , ontermend ) ;
189
+ if ( output !== null && output !== undefined ) {
190
+ output . removeListener ( 'resize' , onresize ) ;
191
+ }
192
+ }
183
193
184
194
emitKeypressEvents ( input , this ) ;
185
195
@@ -202,13 +212,7 @@ function Interface(input, output, completer, terminal) {
202
212
if ( output !== null && output !== undefined )
203
213
output . on ( 'resize' , onresize ) ;
204
214
205
- self . once ( 'close' , function ( ) {
206
- input . removeListener ( 'keypress' , onkeypress ) ;
207
- input . removeListener ( 'end' , ontermend ) ;
208
- if ( output !== null && output !== undefined ) {
209
- output . removeListener ( 'resize' , onresize ) ;
210
- }
211
- } ) ;
215
+ self . once ( 'close' , onSelfCloseWithTerminal ) ;
212
216
}
213
217
214
218
input . resume ( ) ;
@@ -450,7 +454,7 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
450
454
var self = this ;
451
455
452
456
self . pause ( ) ;
453
- self . completer ( self . line . slice ( 0 , self . cursor ) , function ( err , rv ) {
457
+ self . completer ( self . line . slice ( 0 , self . cursor ) , function onComplete ( err , rv ) {
454
458
self . resume ( ) ;
455
459
456
460
if ( err ) {
@@ -464,7 +468,7 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
464
468
// Apply/show completions.
465
469
if ( lastKeypressWasTab ) {
466
470
self . _writeToOutput ( '\r\n' ) ;
467
- var width = completions . reduce ( function ( a , b ) {
471
+ var width = completions . reduce ( function completionReducer ( a , b ) {
468
472
return a . length > b . length ? a : b ;
469
473
} ) . length + 2 ; // 2 space padding
470
474
var maxColumns = Math . floor ( self . columns / width ) ;
@@ -485,7 +489,9 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
485
489
}
486
490
487
491
// If there is a common prefix to all matches, then apply that portion.
488
- var f = completions . filter ( function ( e ) { if ( e ) return e ; } ) ;
492
+ var f = completions . filter ( function completionFilter ( e ) {
493
+ if ( e ) return e ;
494
+ } ) ;
489
495
var prefix = commonPrefix ( f ) ;
490
496
if ( prefix . length > completeOn . length ) {
491
497
self . _insertString ( prefix . slice ( completeOn . length ) ) ;
0 commit comments