| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,6 +107,11 @@ const { StringDecoder } = require('string_decoder'); | |||
| 107 | 107 | // Lazy load Readable for startup performance. | |
| 108 | 108 | let Readable; | |
| 109 | 109 | ||
| 110 | + /** | ||
| 111 | + * @typedef {import('./stream.js').Readable} Readable | ||
| 112 | + * @typedef {import('./stream.js').Writable} Writable | ||
| 113 | + */ | ||
| 114 | + | ||
| 110 | 115 | const kHistorySize = 30; | |
| 111 | 116 | const kMincrlfDelay = 100; | |
| 112 | 117 | // \r\n, \n, or \r followed by something other than \n | |
@@ -118,6 +123,27 @@ const kQuestionCancel = Symbol('kQuestionCancel'); | |||
| 118 | 123 | // GNU readline library - keyseq-timeout is 500ms (default) | |
| 119 | 124 | const ESCAPE_CODE_TIMEOUT = 500; | |
| 120 | 125 | ||
| 126 | + /** | ||
| 127 | + * Creates a new `readline.Interface` instance. | ||
| 128 | + * @param {Readable | { | ||
| 129 | + * input: Readable; | ||
| 130 | + * output: Writable; | ||
| 131 | + * completer?: Function; | ||
| 132 | + * terminal?: boolean; | ||
| 133 | + * history?: string[]; | ||
| 134 | + * historySize?: number; | ||
| 135 | + * removeHistoryDuplicates?: boolean; | ||
| 136 | + * prompt?: string; | ||
| 137 | + * crlfDelay?: number; | ||
| 138 | + * escapeCodeTimeout?: number; | ||
| 139 | + * tabSize?: number; | ||
| 140 | + * signal?: AbortSignal; | ||
| 141 | + * }} input | ||
| 142 | + * @param {Writable} [output] | ||
| 143 | + * @param {Function} [completer] | ||
| 144 | + * @param {boolean} [terminal] | ||
| 145 | + * @returns {Interface} | ||
| 146 | + */ | ||
| 121 | 147 | function createInterface(input, output, completer, terminal) { | |
| 122 | 148 | return new Interface(input, output, completer, terminal); | |
| 123 | 149 | } | |
@@ -348,11 +374,19 @@ ObjectDefineProperty(Interface.prototype, 'columns', { | |||
| 348 | 374 | } | |
| 349 | 375 | }); | |
| 350 | 376 | ||
| 377 | + /** | ||
| 378 | + * Sets the prompt written to the output. | ||
| 379 | + * @param {string} prompt | ||
| 380 | + * @returns {void} | ||
| 381 | + */ | ||
| 351 | 382 | Interface.prototype.setPrompt = function(prompt) { | |
| 352 | 383 | this._prompt = prompt; | |
| 353 | 384 | }; | |
| 354 | 385 | ||
| 355 | - | ||
| 386 | + /** | ||
| 387 | + * Returns the current prompt used by `rl.prompt()`. | ||
| 388 | + * @returns {string} | ||
| 389 | + */ | ||
| 356 | 390 | Interface.prototype.getPrompt = function() { | |
| 357 | 391 | return this._prompt; | |
| 358 | 392 | }; | |
@@ -368,7 +402,11 @@ Interface.prototype._setRawMode = function(mode) { | |||
| 368 | 402 | return wasInRawMode; | |
| 369 | 403 | }; | |
| 370 | 404 | ||
| 371 | - | ||
| 405 | + /** | ||
| 406 | + * Writes the configured `prompt` to a new line in `output`. | ||
| 407 | + * @param {boolean} [preserveCursor] | ||
| 408 | + * @returns {void} | ||
| 409 | + */ | ||
| 372 | 410 | Interface.prototype.prompt = function(preserveCursor) { | |
| 373 | 411 | if (this.paused) this.resume(); | |
| 374 | 412 | if (this.terminal && process.env.TERM !== 'dumb') { | |
@@ -379,7 +417,13 @@ Interface.prototype.prompt = function(preserveCursor) { | |||
| 379 | 417 | } | |
| 380 | 418 | }; | |
| 381 | 419 | ||
| 382 | - | ||
| 420 | + /** | ||
| 421 | + * Displays `query` by writing it to the `output`. | ||
| 422 | + * @param {string} query | ||
| 423 | + * @param {{ signal?: AbortSignal; }} [options] | ||
| 424 | + * @param {Function} cb | ||
| 425 | + * @returns {void} | ||
| 426 | + */ | ||
| 383 | 427 | Interface.prototype.question = function(query, options, cb) { | |
| 384 | 428 | cb = typeof options === 'function' ? options : cb; | |
| 385 | 429 | options = typeof options === 'object' && options !== null ? options : {}; | |
@@ -528,7 +572,10 @@ Interface.prototype._refreshLine = function() { | |||
| 528 | 572 | this.prevRows = cursorPos.rows; | |
| 529 | 573 | }; | |
| 530 | 574 | ||
| 531 | - | ||
| 575 | + /** | ||
| 576 | + * Closes the `readline.Interface` instance. | ||
| 577 | + * @returns {void} | ||
| 578 | + */ | ||
| 532 | 579 | Interface.prototype.close = function() { | |
| 533 | 580 | if (this.closed) return; | |
| 534 | 581 | this.pause(); | |
@@ -539,7 +586,10 @@ Interface.prototype.close = function() { | |||
| 539 | 586 | this.emit('close'); | |
| 540 | 587 | }; | |
| 541 | 588 | ||
| 542 | - | ||
| 589 | + /** | ||
| 590 | + * Pauses the `input` stream. | ||
| 591 | + * @returns {void | Interface} | ||
| 592 | + */ | ||
| 543 | 593 | Interface.prototype.pause = function() { | |
| 544 | 594 | if (this.paused) return; | |
| 545 | 595 | this.input.pause(); | |
@@ -548,7 +598,10 @@ Interface.prototype.pause = function() { | |||
| 548 | 598 | return this; | |
| 549 | 599 | }; | |
| 550 | 600 | ||
| 551 | - | ||
| 601 | + /** | ||
| 602 | + * Resumes the `input` stream if paused. | ||
| 603 | + * @returns {void | Interface} | ||
| 604 | + */ | ||
| 552 | 605 | Interface.prototype.resume = function() { | |
| 553 | 606 | if (!this.paused) return; | |
| 554 | 607 | this.input.resume(); | |
@@ -557,7 +610,18 @@ Interface.prototype.resume = function() { | |||
| 557 | 610 | return this; | |
| 558 | 611 | }; | |
| 559 | 612 | ||
| 560 | - | ||
| 613 | + /** | ||
| 614 | + * Writes either `data` or a `key` sequence identified by | ||
| 615 | + * `key` to the `output`. | ||
| 616 | + * @param {string} d | ||
| 617 | + * @param {{ | ||
| 618 | + * ctrl?: boolean; | ||
| 619 | + * meta?: boolean; | ||
| 620 | + * shift?: boolean; | ||
| 621 | + * name?: string; | ||
| 622 | + * }} [key] | ||
| 623 | + * @returns {void} | ||
| 624 | + */ | ||
| 561 | 625 | Interface.prototype.write = function(d, key) { | |
| 562 | 626 | if (this.paused) this.resume(); | |
| 563 | 627 | if (this.terminal) { | |
@@ -868,7 +932,14 @@ Interface.prototype._getDisplayPos = function(str) { | |||
| 868 | 932 | return { cols, rows }; | |
| 869 | 933 | }; | |
| 870 | 934 | ||
| 871 | - // Returns current cursor's position and line | ||
| 935 | + /** | ||
| 936 | + * Returns the real position of the cursor in relation | ||
| 937 | + * to the input prompt + string. | ||
| 938 | + * @returns {{ | ||
| 939 | + * rows: number; | ||
| 940 | + * cols: number; | ||
| 941 | + * }} | ||
| 942 | + */ | ||
| 872 | 943 | Interface.prototype.getCursorPos = function() { | |
| 873 | 944 | const strBeforeCursor = this._prompt + | |
| 874 | 945 | StringPrototypeSlice(this.line, 0, this.cursor); | |
@@ -1197,6 +1268,11 @@ Interface.prototype._ttyWrite = function(s, key) { | |||
| 1197 | 1268 | } | |
| 1198 | 1269 | }; | |
| 1199 | 1270 | ||
| 1271 | + /** | ||
| 1272 | + * Creates an `AsyncIterator` object that iterates through | ||
| 1273 | + * each line in the input stream as a string. | ||
| 1274 | + * @returns {Symbol.AsyncIterator} | ||
| 1275 | + */ | ||
| 1200 | 1276 | Interface.prototype[SymbolAsyncIterator] = function() { | |
| 1201 | 1277 | if (this[kLineObjectStream] === undefined) { | |
| 1202 | 1278 | if (Readable === undefined) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments