diff --git a/doc/api/readline.md b/doc/api/readline.md index c8f23646a81322..cf2cf8a15377ce 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -682,7 +682,7 @@ was passed to the constructor. added: REPLACEME --> -* Returns: {Promise} +* Returns: this The `rl.rollback` methods clears the internal list of pending actions without sending it to the associated `stream`. diff --git a/lib/internal/readline/promises.js b/lib/internal/readline/promises.js index dc0cebcfacf141..1a0c7b4c809d47 100644 --- a/lib/internal/readline/promises.js +++ b/lib/internal/readline/promises.js @@ -4,7 +4,6 @@ const { ArrayPrototypeJoin, ArrayPrototypePush, Promise, - PromiseResolve, } = primordials; const { CSI } = require('internal/readline/utils'); @@ -38,6 +37,7 @@ class Readline { * Moves the cursor to the x and y coordinate on the given stream. * @param {integer} x * @param {integer} [y] + * @returns {Readline} this */ cursorTo(x, y = undefined) { validateInteger(x, 'x'); @@ -54,6 +54,7 @@ class Readline { * Moves the cursor relative to its current location. * @param {integer} dx * @param {integer} dy + * @returns {Readline} this */ moveCursor(dx, dy) { if (dx || dy) { @@ -80,10 +81,12 @@ class Readline { } /** - * Clears the current line the cursor is on: + * Clears the current line the cursor is on. + * @param {-1|0|1} dir Direction to clear: * -1 for left of the cursor * +1 for right of the cursor * 0 for the entire line + * @returns {Readline} this */ clearLine(dir) { validateInteger(dir, 'dir', -1, 1); @@ -99,6 +102,7 @@ class Readline { /** * Clears the screen from the current position of the cursor down. + * @returns {Readline} this */ clearScreenDown() { if (this.#autoCommit) { @@ -109,15 +113,27 @@ class Readline { return this; } + /** + * Sends all the pending actions to the associated `stream` and clears the + * internal list of pending actions. + * @returns {Promise} Resolves when all pending actions have been + * flushed to the associated `stream`. + */ commit() { return new Promise((resolve) => { this.#stream.write(ArrayPrototypeJoin(this.#todo, ''), resolve); this.#todo = []; }); } + + /** + * Clears the internal list of pending actions without sending it to the + * associated `stream`. + * @returns {Readline} this + */ rollback() { this.#todo = []; - return PromiseResolve(); + return this; } }