readline: expose stream API in clearScreenDown() · nodejs/node@17df75f · GitHub
Skip to content

Commit 17df75f

Browse files
cjihrigtargos
authored andcommitted
readline: expose stream API in clearScreenDown()
This commit adds an optional callback to clearScreenDown(), which is passed to the stream's write() method. It also exposes the return value of write(). PR-URL: #28641 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 3f65b91 commit 17df75f

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

doc/api/readline.md

Lines changed: 9 additions & 1 deletion

lib/readline.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
const { Math, Object } = primordials;
3131

3232
const {
33+
ERR_INVALID_CALLBACK,
3334
ERR_INVALID_CURSOR_POS,
3435
ERR_INVALID_OPT_VALUE
3536
} = require('internal/errors').codes;
@@ -1253,11 +1254,17 @@ function clearLine(stream, dir) {
12531254
* clears the screen from the current position of the cursor down
12541255
*/
12551256

1256-
function clearScreenDown(stream) {
1257-
if (stream === null || stream === undefined)
1258-
return;
1257+
function clearScreenDown(stream, callback) {
1258+
if (callback !== undefined && typeof callback !== 'function')
1259+
throw new ERR_INVALID_CALLBACK(callback);
1260+
1261+
if (stream === null || stream === undefined) {
1262+
if (typeof callback === 'function')
1263+
process.nextTick(callback);
1264+
return true;
1265+
}
12591266

1260-
stream.write(kClearScreenDown);
1267+
return stream.write(kClearScreenDown, callback);
12611268
}
12621269

12631270
module.exports = {

test/parallel/test-readline-csi.js

Lines changed: 12 additions & 1 deletion

0 commit comments

Comments
 (0)