@@ -107,6 +107,11 @@ const { StringDecoder } = require('string_decoder');
107107// Lazy load Readable for startup performance.
108108let Readable ;
109109
110+ /**
111+ * @typedef {import('./stream.js').Readable } Readable
112+ * @typedef {import('./stream.js').Writable } Writable
113+ */
114+
110115const kHistorySize = 30 ;
111116const kMincrlfDelay = 100 ;
112117// \r\n, \n, or \r followed by something other than \n
@@ -118,6 +123,27 @@ const kQuestionCancel = Symbol('kQuestionCancel');
118123// GNU readline library - keyseq-timeout is 500ms (default)
119124const ESCAPE_CODE_TIMEOUT = 500 ;
120125
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+ */
121147function createInterface ( input , output , completer , terminal ) {
122148 return new Interface ( input , output , completer , terminal ) ;
123149}
@@ -348,11 +374,19 @@ ObjectDefineProperty(Interface.prototype, 'columns', {
348374 }
349375} ) ;
350376
377+ /**
378+ * Sets the prompt written to the output.
379+ * @param {string } prompt
380+ * @returns {void }
381+ */
351382Interface . prototype . setPrompt = function ( prompt ) {
352383 this . _prompt = prompt ;
353384} ;
354385
355-
386+ /**
387+ * Returns the current prompt used by `rl.prompt()`.
388+ * @returns {string }
389+ */
356390Interface . prototype . getPrompt = function ( ) {
357391 return this . _prompt ;
358392} ;
@@ -368,7 +402,11 @@ Interface.prototype._setRawMode = function(mode) {
368402 return wasInRawMode ;
369403} ;
370404
371-
405+ /**
406+ * Writes the configured `prompt` to a new line in `output`.
407+ * @param {boolean } [preserveCursor]
408+ * @returns {void }
409+ */
372410Interface . prototype . prompt = function ( preserveCursor ) {
373411 if ( this . paused ) this . resume ( ) ;
374412 if ( this . terminal && process . env . TERM !== 'dumb' ) {
@@ -379,7 +417,13 @@ Interface.prototype.prompt = function(preserveCursor) {
379417 }
380418} ;
381419
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+ */
383427Interface . prototype . question = function ( query , options , cb ) {
384428 cb = typeof options === 'function' ? options : cb ;
385429 options = typeof options === 'object' && options !== null ? options : { } ;
@@ -528,7 +572,10 @@ Interface.prototype._refreshLine = function() {
528572 this . prevRows = cursorPos . rows ;
529573} ;
530574
531-
575+ /**
576+ * Closes the `readline.Interface` instance.
577+ * @returns {void }
578+ */
532579Interface . prototype . close = function ( ) {
533580 if ( this . closed ) return ;
534581 this . pause ( ) ;
@@ -539,7 +586,10 @@ Interface.prototype.close = function() {
539586 this . emit ( 'close' ) ;
540587} ;
541588
542-
589+ /**
590+ * Pauses the `input` stream.
591+ * @returns {void | Interface }
592+ */
543593Interface . prototype . pause = function ( ) {
544594 if ( this . paused ) return ;
545595 this . input . pause ( ) ;
@@ -548,7 +598,10 @@ Interface.prototype.pause = function() {
548598 return this ;
549599} ;
550600
551-
601+ /**
602+ * Resumes the `input` stream if paused.
603+ * @returns {void | Interface }
604+ */
552605Interface . prototype . resume = function ( ) {
553606 if ( ! this . paused ) return ;
554607 this . input . resume ( ) ;
@@ -557,7 +610,18 @@ Interface.prototype.resume = function() {
557610 return this ;
558611} ;
559612
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+ */
561625Interface . prototype . write = function ( d , key ) {
562626 if ( this . paused ) this . resume ( ) ;
563627 if ( this . terminal ) {
@@ -868,7 +932,14 @@ Interface.prototype._getDisplayPos = function(str) {
868932 return { cols, rows } ;
869933} ;
870934
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+ */
872943Interface . prototype . getCursorPos = function ( ) {
873944 const strBeforeCursor = this . _prompt +
874945 StringPrototypeSlice ( this . line , 0 , this . cursor ) ;
@@ -1197,6 +1268,11 @@ Interface.prototype._ttyWrite = function(s, key) {
11971268 }
11981269} ;
11991270
1271+ /**
1272+ * Creates an `AsyncIterator` object that iterates through
1273+ * each line in the input stream as a string.
1274+ * @returns {Symbol.AsyncIterator }
1275+ */
12001276Interface . prototype [ SymbolAsyncIterator ] = function ( ) {
12011277 if ( this [ kLineObjectStream ] === undefined ) {
12021278 if ( Readable === undefined ) {
0 commit comments