@@ -94,8 +94,8 @@ function Interface(input, output, completer, terminal) {
9494 this . escapeCodeTimeout = ESCAPE_CODE_TIMEOUT ;
9595
9696 EventEmitter . call ( this ) ;
97- var historySize ;
98- var removeHistoryDuplicates = false ;
97+ let historySize ;
98+ let removeHistoryDuplicates = false ;
9999 let crlfDelay ;
100100 let prompt = '> ' ;
101101
@@ -258,10 +258,9 @@ Object.defineProperty(Interface.prototype, 'columns', {
258258 configurable : true ,
259259 enumerable : true ,
260260 get : function ( ) {
261- var columns = Infinity ;
262261 if ( this . output && this . output . columns )
263- columns = this . output . columns ;
264- return columns ;
262+ return this . output . columns ;
263+ return Infinity ;
265264 }
266265} ) ;
267266
@@ -308,7 +307,7 @@ Interface.prototype.question = function(query, cb) {
308307
309308Interface . prototype . _onLine = function ( line ) {
310309 if ( this . _questionCallback ) {
311- var cb = this . _questionCallback ;
310+ const cb = this . _questionCallback ;
312311 this . _questionCallback = null ;
313312 this . setPrompt ( this . _oldPrompt ) ;
314313 cb ( line ) ;
@@ -435,7 +434,7 @@ Interface.prototype._normalWrite = function(b) {
435434 if ( b === undefined ) {
436435 return ;
437436 }
438- var string = this . _decoder . write ( b ) ;
437+ let string = this . _decoder . write ( b ) ;
439438 if ( this . _sawReturnAt &&
440439 Date . now ( ) - this . _sawReturnAt <= this . crlfDelay ) {
441440 string = string . replace ( / ^ \n / , '' ) ;
@@ -453,11 +452,11 @@ Interface.prototype._normalWrite = function(b) {
453452 this . _sawReturnAt = string . endsWith ( '\r' ) ? Date . now ( ) : 0 ;
454453
455454 // Got one or more newlines; process into "line" events
456- var lines = string . split ( lineEnding ) ;
455+ const lines = string . split ( lineEnding ) ;
457456 // Either '' or (conceivably) the unfinished portion of the next line
458457 string = lines . pop ( ) ;
459458 this . _line_buffer = string ;
460- for ( var n = 0 ; n < lines . length ; n ++ )
459+ for ( let n = 0 ; n < lines . length ; n ++ )
461460 this . _onLine ( lines [ n ] ) ;
462461 } else if ( string ) {
463462 // No newlines this time, save what we have for next time
@@ -467,8 +466,8 @@ Interface.prototype._normalWrite = function(b) {
467466
468467Interface . prototype . _insertString = function ( c ) {
469468 if ( this . cursor < this . line . length ) {
470- var beg = this . line . slice ( 0 , this . cursor ) ;
471- var end = this . line . slice ( this . cursor , this . line . length ) ;
469+ const beg = this . line . slice ( 0 , this . cursor ) ;
470+ const end = this . line . slice ( this . cursor , this . line . length ) ;
472471 this . line = beg + c + end ;
473472 this . cursor += c . length ;
474473 this . _refreshLine ( ) ;
@@ -505,16 +504,16 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
505504 // Apply/show completions.
506505 if ( lastKeypressWasTab ) {
507506 self . _writeToOutput ( '\r\n' ) ;
508- var width = completions . reduce ( function completionReducer ( a , b ) {
507+ const width = completions . reduce ( function completionReducer ( a , b ) {
509508 return a . length > b . length ? a : b ;
510509 } ) . length + 2 ; // 2 space padding
511- var maxColumns = Math . floor ( self . columns / width ) ;
510+ let maxColumns = Math . floor ( self . columns / width ) ;
512511 if ( ! maxColumns || maxColumns === Infinity ) {
513512 maxColumns = 1 ;
514513 }
515- var group = [ ] ;
516- for ( var i = 0 ; i < completions . length ; i ++ ) {
517- var c = completions [ i ] ;
514+ let group = [ ] ;
515+ for ( let i = 0 ; i < completions . length ; i ++ ) {
516+ const c = completions [ i ] ;
518517 if ( c === '' ) {
519518 handleGroup ( self , group , width , maxColumns ) ;
520519 group = [ ] ;
@@ -526,8 +525,8 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) {
526525 }
527526
528527 // If there is a common prefix to all matches, then apply that portion.
529- var f = completions . filter ( ( e ) => e ) ;
530- var prefix = commonPrefix ( f ) ;
528+ const f = completions . filter ( ( e ) => e ) ;
529+ const prefix = commonPrefix ( f ) ;
531530 if ( prefix . length > completeOn . length ) {
532531 self . _insertString ( prefix . slice ( completeOn . length ) ) ;
533532 }
@@ -543,16 +542,16 @@ function handleGroup(self, group, width, maxColumns) {
543542 return ;
544543 }
545544 const minRows = Math . ceil ( group . length / maxColumns ) ;
546- for ( var row = 0 ; row < minRows ; row ++ ) {
547- for ( var col = 0 ; col < maxColumns ; col ++ ) {
548- var idx = row * maxColumns + col ;
545+ for ( let row = 0 ; row < minRows ; row ++ ) {
546+ for ( let col = 0 ; col < maxColumns ; col ++ ) {
547+ const idx = row * maxColumns + col ;
549548 if ( idx >= group . length ) {
550549 break ;
551550 }
552- var item = group [ idx ] ;
551+ const item = group [ idx ] ;
553552 self . _writeToOutput ( item ) ;
554553 if ( col < maxColumns - 1 ) {
555- for ( var s = 0 ; s < width - item . length ; s ++ ) {
554+ for ( let s = 0 ; s < width - item . length ; s ++ ) {
556555 self . _writeToOutput ( ' ' ) ;
557556 }
558557 }
@@ -570,7 +569,7 @@ function commonPrefix(strings) {
570569 const sorted = strings . slice ( ) . sort ( ) ;
571570 const min = sorted [ 0 ] ;
572571 const max = sorted [ sorted . length - 1 ] ;
573- for ( var i = 0 , len = min . length ; i < len ; i ++ ) {
572+ for ( let i = 0 , len = min . length ; i < len ; i ++ ) {
574573 if ( min [ i ] !== max [ i ] ) {
575574 return min . slice ( 0 , i ) ;
576575 }
@@ -583,18 +582,18 @@ Interface.prototype._wordLeft = function() {
583582 if ( this . cursor > 0 ) {
584583 // Reverse the string and match a word near beginning
585584 // to avoid quadratic time complexity
586- var leading = this . line . slice ( 0 , this . cursor ) ;
587- var reversed = leading . split ( '' ) . reverse ( ) . join ( '' ) ;
588- var match = reversed . match ( / ^ \s * (?: [ ^ \w \s ] + | \w + ) ? / ) ;
585+ const leading = this . line . slice ( 0 , this . cursor ) ;
586+ const reversed = leading . split ( '' ) . reverse ( ) . join ( '' ) ;
587+ const match = reversed . match ( / ^ \s * (?: [ ^ \w \s ] + | \w + ) ? / ) ;
589588 this . _moveCursor ( - match [ 0 ] . length ) ;
590589 }
591590} ;
592591
593592
594593Interface . prototype . _wordRight = function ( ) {
595594 if ( this . cursor < this . line . length ) {
596- var trailing = this . line . slice ( this . cursor ) ;
597- var match = trailing . match ( / ^ (?: \s + | [ ^ \w \s ] + | \w + ) \s * / ) ;
595+ const trailing = this . line . slice ( this . cursor ) ;
596+ const match = trailing . match ( / ^ (?: \s + | [ ^ \w \s ] + | \w + ) \s * / ) ;
598597 this . _moveCursor ( match [ 0 ] . length ) ;
599598 }
600599} ;
@@ -643,9 +642,9 @@ Interface.prototype._deleteWordLeft = function() {
643642 if ( this . cursor > 0 ) {
644643 // Reverse the string and match a word near beginning
645644 // to avoid quadratic time complexity
646- var leading = this . line . slice ( 0 , this . cursor ) ;
647- var reversed = leading . split ( '' ) . reverse ( ) . join ( '' ) ;
648- var match = reversed . match ( / ^ \s * (?: [ ^ \w \s ] + | \w + ) ? / ) ;
645+ let leading = this . line . slice ( 0 , this . cursor ) ;
646+ const reversed = leading . split ( '' ) . reverse ( ) . join ( '' ) ;
647+ const match = reversed . match ( / ^ \s * (?: [ ^ \w \s ] + | \w + ) ? / ) ;
649648 leading = leading . slice ( 0 , leading . length - match [ 0 ] . length ) ;
650649 this . line = leading + this . line . slice ( this . cursor , this . line . length ) ;
651650 this . cursor = leading . length ;
@@ -656,8 +655,8 @@ Interface.prototype._deleteWordLeft = function() {
656655
657656Interface . prototype . _deleteWordRight = function ( ) {
658657 if ( this . cursor < this . line . length ) {
659- var trailing = this . line . slice ( this . cursor ) ;
660- var match = trailing . match ( / ^ (?: \s + | \W + | \w + ) \s * / ) ;
658+ const trailing = this . line . slice ( this . cursor ) ;
659+ const match = trailing . match ( / ^ (?: \s + | \W + | \w + ) \s * / ) ;
661660 this . line = this . line . slice ( 0 , this . cursor ) +
662661 trailing . slice ( match [ 0 ] . length ) ;
663662 this . _refreshLine ( ) ;
@@ -723,13 +722,12 @@ Interface.prototype._historyPrev = function() {
723722
724723// Returns the last character's display position of the given string
725724Interface . prototype . _getDisplayPos = function ( str ) {
726- var offset = 0 ;
725+ let offset = 0 ;
727726 const col = this . columns ;
728- var row = 0 ;
729- var code ;
727+ let row = 0 ;
730728 str = stripVTControlCharacters ( str ) ;
731- for ( var i = 0 , len = str . length ; i < len ; i ++ ) {
732- code = str . codePointAt ( i ) ;
729+ for ( let i = 0 , len = str . length ; i < len ; i ++ ) {
730+ const code = str . codePointAt ( i ) ;
733731 if ( code >= kUTF16SurrogateThreshold ) { // Surrogates.
734732 i ++ ;
735733 }
@@ -761,8 +759,8 @@ Interface.prototype._getCursorPos = function() {
761759 const strBeforeCursor = this . _prompt + this . line . substring ( 0 , this . cursor ) ;
762760 const dispPos = this . _getDisplayPos (
763761 stripVTControlCharacters ( strBeforeCursor ) ) ;
764- var cols = dispPos . cols ;
765- var rows = dispPos . rows ;
762+ let cols = dispPos . cols ;
763+ let rows = dispPos . rows ;
766764 // If the cursor is on a full-width character which steps over the line,
767765 // move the cursor to the beginning of the next line.
768766 if ( cols + 1 === columns &&
@@ -790,8 +788,8 @@ Interface.prototype._moveCursor = function(dx) {
790788
791789 // Check if cursors are in the same line
792790 if ( oldPos . rows === newPos . rows ) {
793- var diffCursor = this . cursor - oldcursor ;
794- var diffWidth ;
791+ const diffCursor = this . cursor - oldcursor ;
792+ let diffWidth ;
795793 if ( diffCursor < 0 ) {
796794 diffWidth = - getStringWidth (
797795 this . line . substring ( this . cursor , oldcursor )
@@ -1072,8 +1070,8 @@ Interface.prototype._ttyWrite = function(s, key) {
10721070
10731071 default :
10741072 if ( typeof s === 'string' && s ) {
1075- var lines = s . split ( / \r \n | \n | \r / ) ;
1076- for ( var i = 0 , len = lines . length ; i < len ; i ++ ) {
1073+ const lines = s . split ( / \r \n | \n | \r / ) ;
1074+ for ( let i = 0 , len = lines . length ; i < len ; i ++ ) {
10771075 if ( i > 0 ) {
10781076 this . _line ( ) ;
10791077 }
@@ -1136,15 +1134,15 @@ function emitKeypressEvents(stream, iface) {
11361134
11371135 function onData ( b ) {
11381136 if ( stream . listenerCount ( 'keypress' ) > 0 ) {
1139- var r = stream [ KEYPRESS_DECODER ] . write ( b ) ;
1137+ const r = stream [ KEYPRESS_DECODER ] . write ( b ) ;
11401138 if ( r ) {
11411139 clearTimeout ( timeoutId ) ;
11421140
11431141 if ( iface ) {
11441142 iface . _sawKeyPress = r . length === 1 ;
11451143 }
11461144
1147- for ( var i = 0 ; i < r . length ; i ++ ) {
1145+ for ( let i = 0 ; i < r . length ; i ++ ) {
11481146 if ( r [ i ] === '\t' && typeof r [ i + 1 ] === 'string' && iface ) {
11491147 iface . isCompletionEnabled = false ;
11501148 }
0 commit comments