CoolFace
Apppublic

Pinsave/counterstrike

sourceHugging Faceupdated 3mo agoView on Hugging Face
1likes
promises.d.ts162 linesDownload Raw Back to readline
1/**2 * @since v17.0.03 */4declare module "readline/promises" {5    import { Abortable } from "node:events";6    import {7        CompleterResult,8        Direction,9        Interface as _Interface,10        ReadLineOptions as _ReadLineOptions,11    } from "node:readline";12    /**13     * Instances of the `readlinePromises.Interface` class are constructed using the `readlinePromises.createInterface()` method. Every instance is associated with a14     * single `input` `Readable` stream and a single `output` `Writable` stream.15     * The `output` stream is used to print prompts for user input that arrives on,16     * and is read from, the `input` stream.17     * @since v17.0.018     */19    class Interface extends _Interface {20        /**21         * The `rl.question()` method displays the `query` by writing it to the `output`,22         * waits for user input to be provided on `input`, then invokes the `callback` function passing the provided input as the first argument.23         *24         * When called, `rl.question()` will resume the `input` stream if it has been25         * paused.26         *27         * If the `Interface` was created with `output` set to `null` or `undefined` the `query` is not written.28         *29         * If the question is called after `rl.close()`, it returns a rejected promise.30         *31         * Example usage:32         *33         * ```js34         * const answer = await rl.question('What is your favorite food? ');35         * console.log(`Oh, so your favorite food is ${answer}`);36         * ```37         *38         * Using an `AbortSignal` to cancel a question.39         *40         * ```js41         * const signal = AbortSignal.timeout(10_000);42         *43         * signal.addEventListener('abort', () => {44         *   console.log('The food question timed out');45         * }, { once: true });46         *47         * const answer = await rl.question('What is your favorite food? ', { signal });48         * console.log(`Oh, so your favorite food is ${answer}`);49         * ```50         * @since v17.0.051         * @param query A statement or query to write to `output`, prepended to the prompt.52         * @return A promise that is fulfilled with the user's input in response to the `query`.53         */54        question(query: string): Promise<string>;55        question(query: string, options: Abortable): Promise<string>;56    }57    /**58     * @since v17.0.059     */60    class Readline {61        /**62         * @param stream A TTY stream.63         */64        constructor(65            stream: NodeJS.WritableStream,66            options?: {67                autoCommit?: boolean;68            },69        );70        /**71         * The `rl.clearLine()` method adds to the internal list of pending action an72         * action that clears current line of the associated `stream` in a specified73         * direction identified by `dir`.74         * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.75         * @since v17.0.076         * @return this77         */78        clearLine(dir: Direction): this;79        /**80         * The `rl.clearScreenDown()` method adds to the internal list of pending action an81         * action that clears the associated stream from the current position of the82         * cursor down.83         * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.84         * @since v17.0.085         * @return this86         */87        clearScreenDown(): this;88        /**89         * The `rl.commit()` method sends all the pending actions to the associated `stream` and clears the internal list of pending actions.90         * @since v17.0.091         */92        commit(): Promise<void>;93        /**94         * The `rl.cursorTo()` method adds to the internal list of pending action an action95         * that moves cursor to the specified position in the associated `stream`.96         * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.97         * @since v17.0.098         * @return this99         */100        cursorTo(x: number, y?: number): this;101        /**102         * The `rl.moveCursor()` method adds to the internal list of pending action an103         * action that moves the cursor _relative_ to its current position in the104         * associated `stream`.105         * Call `rl.commit()` to see the effect of this method, unless `autoCommit: true` was passed to the constructor.106         * @since v17.0.0107         * @return this108         */109        moveCursor(dx: number, dy: number): this;110        /**111         * The `rl.rollback` methods clears the internal list of pending actions without112         * sending it to the associated `stream`.113         * @since v17.0.0114         * @return this115         */116        rollback(): this;117    }118    type Completer = (line: string) => CompleterResult | Promise<CompleterResult>;119    interface ReadLineOptions extends Omit<_ReadLineOptions, "completer"> {120        /**121         * An optional function used for Tab autocompletion.122         */123        completer?: Completer | undefined;124    }125    /**126     * The `readlinePromises.createInterface()` method creates a new `readlinePromises.Interface` instance.127     *128     * ```js129     * import readlinePromises from 'node:readline/promises';130     * const rl = readlinePromises.createInterface({131     *   input: process.stdin,132     *   output: process.stdout,133     * });134     * ```135     *136     * Once the `readlinePromises.Interface` instance is created, the most common case137     * is to listen for the `'line'` event:138     *139     * ```js140     * rl.on('line', (line) => {141     *   console.log(`Received: ${line}`);142     * });143     * ```144     *145     * If `terminal` is `true` for this instance then the `output` stream will get146     * the best compatibility if it defines an `output.columns` property and emits147     * a `'resize'` event on the `output` if or when the columns ever change148     * (`process.stdout` does this automatically when it is a TTY).149     * @since v17.0.0150     */151    function createInterface(152        input: NodeJS.ReadableStream,153        output?: NodeJS.WritableStream,154        completer?: Completer,155        terminal?: boolean,156    ): Interface;157    function createInterface(options: ReadLineOptions): Interface;158}159declare module "node:readline/promises" {160    export * from "readline/promises";161}162