| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f25b00a commit 31a63ab
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,8 +94,8 @@ function Interface(input, output, completer, terminal) { | |||
| 94 | 94 | this.escapeCodeTimeout = ESCAPE_CODE_TIMEOUT; | |
| 95 | 95 | ||
| 96 | 96 | EventEmitter.call(this); | |
| 97 | - var historySize; | ||
| 98 | - var removeHistoryDuplicates = false; | ||
| 97 | + let historySize; | ||
| 98 | + let removeHistoryDuplicates = false; | ||
| 99 | 99 | let crlfDelay; | |
| 100 | 100 | let prompt = '> '; | |
| 101 | 101 | ||
@@ -258,10 +258,9 @@ Object.defineProperty(Interface.prototype, 'columns', { | |||
| 258 | 258 | configurable: true, | |
| 259 | 259 | enumerable: true, | |
| 260 | 260 | get: function() { | |
| 261 | - var columns = Infinity; | ||
| 262 | 261 | if (this.output && this.output.columns) | |
| 263 | - columns = this.output.columns; | ||
| 264 | - return columns; | ||
| 262 | + return this.output.columns; | ||
| 263 | + return Infinity; | ||
| 265 | 264 | } | |
| 266 | 265 | }); | |
| 267 | 266 | ||
@@ -308,7 +307,7 @@ Interface.prototype.question = function(query, cb) { | |||
| 308 | 307 | ||
| 309 | 308 | Interface.prototype._onLine = function(line) { | |
| 310 | 309 | if (this._questionCallback) { | |
| 311 | - var cb = this._questionCallback; | ||
| 310 | + const cb = this._questionCallback; | ||
| 312 | 311 | this._questionCallback = null; | |
| 313 | 312 | this.setPrompt(this._oldPrompt); | |
| 314 | 313 | cb(line); | |
@@ -435,7 +434,7 @@ Interface.prototype._normalWrite = function(b) { | |||
| 435 | 434 | if (b === undefined) { | |
| 436 | 435 | return; | |
| 437 | 436 | } | |
| 438 | - var string = this._decoder.write(b); | ||
| 437 | + let string = this._decoder.write(b); | ||
| 439 | 438 | if (this._sawReturnAt && | |
| 440 | 439 | Date.now() - this._sawReturnAt <= this.crlfDelay) { | |
| 441 | 440 | string = string.replace(/^\n/, ''); | |
@@ -453,11 +452,11 @@ Interface.prototype._normalWrite = function(b) { | |||
| 453 | 452 | this._sawReturnAt = string.endsWith('\r') ? Date.now() : 0; | |
| 454 | 453 | ||
| 455 | 454 | // Got one or more newlines; process into "line" events | |
| 456 | - var lines = string.split(lineEnding); | ||
| 455 | + const lines = string.split(lineEnding); | ||
| 457 | 456 | // Either '' or (conceivably) the unfinished portion of the next line | |
| 458 | 457 | string = lines.pop(); | |
| 459 | 458 | this._line_buffer = string; | |
| 460 | - for (var n = 0; n < lines.length; n++) | ||
| 459 | + for (let n = 0; n < lines.length; n++) | ||
| 461 | 460 | this._onLine(lines[n]); | |
| 462 | 461 | } else if (string) { | |
| 463 | 462 | // No newlines this time, save what we have for next time | |
@@ -467,8 +466,8 @@ Interface.prototype._normalWrite = function(b) { | |||
| 467 | 466 | ||
| 468 | 467 | Interface.prototype._insertString = function(c) { | |
| 469 | 468 | 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); | ||
| 472 | 471 | this.line = beg + c + end; | |
| 473 | 472 | this.cursor += c.length; | |
| 474 | 473 | this._refreshLine(); | |
@@ -505,16 +504,16 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) { | |||
| 505 | 504 | // Apply/show completions. | |
| 506 | 505 | if (lastKeypressWasTab) { | |
| 507 | 506 | self._writeToOutput('\r\n'); | |
| 508 | - var width = completions.reduce(function completionReducer(a, b) { | ||
| 507 | + const width = completions.reduce(function completionReducer(a, b) { | ||
| 509 | 508 | return a.length > b.length ? a : b; | |
| 510 | 509 | }).length + 2; // 2 space padding | |
| 511 | - var maxColumns = Math.floor(self.columns / width); | ||
| 510 | + let maxColumns = Math.floor(self.columns / width); | ||
| 512 | 511 | if (!maxColumns || maxColumns === Infinity) { | |
| 513 | 512 | maxColumns = 1; | |
| 514 | 513 | } | |
| 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]; | ||
| 518 | 517 | if (c === '') { | |
| 519 | 518 | handleGroup(self, group, width, maxColumns); | |
| 520 | 519 | group = []; | |
@@ -526,8 +525,8 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) { | |||
| 526 | 525 | } | |
| 527 | 526 | ||
| 528 | 527 | // 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); | ||
| 531 | 530 | if (prefix.length > completeOn.length) { | |
| 532 | 531 | self._insertString(prefix.slice(completeOn.length)); | |
| 533 | 532 | } | |
@@ -543,16 +542,16 @@ function handleGroup(self, group, width, maxColumns) { | |||
| 543 | 542 | return; | |
| 544 | 543 | } | |
| 545 | 544 | 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; | ||
| 549 | 548 | if (idx >= group.length) { | |
| 550 | 549 | break; | |
| 551 | 550 | } | |
| 552 | - var item = group[idx]; | ||
| 551 | + const item = group[idx]; | ||
| 553 | 552 | self._writeToOutput(item); | |
| 554 | 553 | if (col < maxColumns - 1) { | |
| 555 | - for (var s = 0; s < width - item.length; s++) { | ||
| 554 | + for (let s = 0; s < width - item.length; s++) { | ||
| 556 | 555 | self._writeToOutput(' '); | |
| 557 | 556 | } | |
| 558 | 557 | } | |
@@ -570,7 +569,7 @@ function commonPrefix(strings) { | |||
| 570 | 569 | const sorted = strings.slice().sort(); | |
| 571 | 570 | const min = sorted[0]; | |
| 572 | 571 | 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++) { | ||
| 574 | 573 | if (min[i] !== max[i]) { | |
| 575 | 574 | return min.slice(0, i); | |
| 576 | 575 | } | |
@@ -583,18 +582,18 @@ Interface.prototype._wordLeft = function() { | |||
| 583 | 582 | if (this.cursor > 0) { | |
| 584 | 583 | // Reverse the string and match a word near beginning | |
| 585 | 584 | // 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+)?/); | ||
| 589 | 588 | this._moveCursor(-match[0].length); | |
| 590 | 589 | } | |
| 591 | 590 | }; | |
| 592 | 591 | ||
| 593 | 592 | ||
| 594 | 593 | Interface.prototype._wordRight = function() { | |
| 595 | 594 | 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*/); | ||
| 598 | 597 | this._moveCursor(match[0].length); | |
| 599 | 598 | } | |
| 600 | 599 | }; | |
@@ -643,9 +642,9 @@ Interface.prototype._deleteWordLeft = function() { | |||
| 643 | 642 | if (this.cursor > 0) { | |
| 644 | 643 | // Reverse the string and match a word near beginning | |
| 645 | 644 | // 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+)?/); | ||
| 649 | 648 | leading = leading.slice(0, leading.length - match[0].length); | |
| 650 | 649 | this.line = leading + this.line.slice(this.cursor, this.line.length); | |
| 651 | 650 | this.cursor = leading.length; | |
@@ -656,8 +655,8 @@ Interface.prototype._deleteWordLeft = function() { | |||
| 656 | 655 | ||
| 657 | 656 | Interface.prototype._deleteWordRight = function() { | |
| 658 | 657 | 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*/); | ||
| 661 | 660 | this.line = this.line.slice(0, this.cursor) + | |
| 662 | 661 | trailing.slice(match[0].length); | |
| 663 | 662 | this._refreshLine(); | |
@@ -723,13 +722,12 @@ Interface.prototype._historyPrev = function() { | |||
| 723 | 722 | ||
| 724 | 723 | // Returns the last character's display position of the given string | |
| 725 | 724 | Interface.prototype._getDisplayPos = function(str) { | |
| 726 | - var offset = 0; | ||
| 725 | + let offset = 0; | ||
| 727 | 726 | const col = this.columns; | |
| 728 | - var row = 0; | ||
| 729 | - var code; | ||
| 727 | + let row = 0; | ||
| 730 | 728 | 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); | ||
| 733 | 731 | if (code >= kUTF16SurrogateThreshold) { // Surrogates. | |
| 734 | 732 | i++; | |
| 735 | 733 | } | |
@@ -761,8 +759,8 @@ Interface.prototype._getCursorPos = function() { | |||
| 761 | 759 | const strBeforeCursor = this._prompt + this.line.substring(0, this.cursor); | |
| 762 | 760 | const dispPos = this._getDisplayPos( | |
| 763 | 761 | stripVTControlCharacters(strBeforeCursor)); | |
| 764 | - var cols = dispPos.cols; | ||
| 765 | - var rows = dispPos.rows; | ||
| 762 | + let cols = dispPos.cols; | ||
| 763 | + let rows = dispPos.rows; | ||
| 766 | 764 | // If the cursor is on a full-width character which steps over the line, | |
| 767 | 765 | // move the cursor to the beginning of the next line. | |
| 768 | 766 | if (cols + 1 === columns && | |
@@ -790,8 +788,8 @@ Interface.prototype._moveCursor = function(dx) { | |||
| 790 | 788 | ||
| 791 | 789 | // Check if cursors are in the same line | |
| 792 | 790 | if (oldPos.rows === newPos.rows) { | |
| 793 | - var diffCursor = this.cursor - oldcursor; | ||
| 794 | - var diffWidth; | ||
| 791 | + const diffCursor = this.cursor - oldcursor; | ||
| 792 | + let diffWidth; | ||
| 795 | 793 | if (diffCursor < 0) { | |
| 796 | 794 | diffWidth = -getStringWidth( | |
| 797 | 795 | this.line.substring(this.cursor, oldcursor) | |
@@ -1072,8 +1070,8 @@ Interface.prototype._ttyWrite = function(s, key) { | |||
| 1072 | 1070 | ||
| 1073 | 1071 | default: | |
| 1074 | 1072 | 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++) { | ||
| 1077 | 1075 | if (i > 0) { | |
| 1078 | 1076 | this._line(); | |
| 1079 | 1077 | } | |
@@ -1136,15 +1134,15 @@ function emitKeypressEvents(stream, iface) { | |||
| 1136 | 1134 | ||
| 1137 | 1135 | function onData(b) { | |
| 1138 | 1136 | if (stream.listenerCount('keypress') > 0) { | |
| 1139 | - var r = stream[KEYPRESS_DECODER].write(b); | ||
| 1137 | + const r = stream[KEYPRESS_DECODER].write(b); | ||
| 1140 | 1138 | if (r) { | |
| 1141 | 1139 | clearTimeout(timeoutId); | |
| 1142 | 1140 | ||
| 1143 | 1141 | if (iface) { | |
| 1144 | 1142 | iface._sawKeyPress = r.length === 1; | |
| 1145 | 1143 | } | |
| 1146 | 1144 | ||
| 1147 | - for (var i = 0; i < r.length; i++) { | ||
| 1145 | + for (let i = 0; i < r.length; i++) { | ||
| 1148 | 1146 | if (r[i] === '\t' && typeof r[i + 1] === 'string' && iface) { | |
| 1149 | 1147 | iface.isCompletionEnabled = false; | |
| 1150 | 1148 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments