File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed
Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -360,12 +360,20 @@ added: v0.7.7
360360The `readline.clearLine()` method clears current line of given [TTY][] stream
361361in a specified direction identified by `dir`.
362362
363- ## readline.clearScreenDown(stream)
363+ ## readline.clearScreenDown(stream[, callback] )
364364<!-- YAML
365365added: v0.7.7
366+ changes:
367+ - version: REPLACEME
368+ pr-url: https://github.com/nodejs/node/pull/28641
369+ description: The stream's write() callback and return value are exposed.
366370-->
367371
368372* `stream` {stream.Writable}
373+ * `callback` {Function} Invoked once the operation completes.
374+ * Returns: {boolean} `false` if `stream` wishes for the calling code to wait for
375+ the `'drain'` event to be emitted before continuing to write additional data;
376+ otherwise `true`.
369377
370378The `readline.clearScreenDown()` method clears the given [TTY][] stream from
371379the current position of the cursor down.
Original file line number Diff line number Diff line change 3030const { Math, Object } = primordials;
3131
3232const {
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
12631270module.exports = {
Original file line number Diff line number Diff line change @@ -29,8 +29,19 @@ class TestWritable extends Writable {
2929
3030const writable = new TestWritable();
3131
32- readline.clearScreenDown(writable);
32+ assert.strictEqual( readline.clearScreenDown(writable), true );
3333assert.deepStrictEqual(writable.data, CSI.kClearScreenDown);
34+ assert.strictEqual(readline.clearScreenDown(writable, common.mustCall()), true);
35+
36+ // Verify that clearScreenDown() throws on invalid callback.
37+ assert.throws(() => {
38+ readline.clearScreenDown(writable, null);
39+ }, /ERR_INVALID_CALLBACK/);
40+
41+ // Verify that clearScreenDown() does not throw on null or undefined stream.
42+ assert.strictEqual(readline.clearScreenDown(null, common.mustCall()), true);
43+ assert.strictEqual(readline.clearScreenDown(undefined, common.mustCall()),
44+ true);
3445
3546writable.data = '';
3647readline.clearLine(writable, -1);
You can’t perform that action at this time.
0 commit comments