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
360
360
The ` readline.clearLine() ` method clears current line of given [ TTY] [ ] stream
361
361
in a specified direction identified by ` dir ` .
362
362
363
- ## readline.clearScreenDown(stream)
363
+ ## readline.clearScreenDown(stream[ , callback ] )
364
364
<!-- YAML
365
365
added: 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.
366
370
-->
367
371
368
372
* ` 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 ` .
369
377
370
378
The ` readline.clearScreenDown() ` method clears the given [ TTY] [ ] stream from
371
379
the current position of the cursor down.
Original file line number Diff line number Diff line change 30
30
const { Math, Object } = primordials ;
31
31
32
32
const {
33
+ ERR_INVALID_CALLBACK ,
33
34
ERR_INVALID_CURSOR_POS ,
34
35
ERR_INVALID_OPT_VALUE
35
36
} = require ( 'internal/errors' ) . codes ;
@@ -1253,11 +1254,17 @@ function clearLine(stream, dir) {
1253
1254
* clears the screen from the current position of the cursor down
1254
1255
*/
1255
1256
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
+ }
1259
1266
1260
- stream . write ( kClearScreenDown ) ;
1267
+ return stream . write ( kClearScreenDown , callback ) ;
1261
1268
}
1262
1269
1263
1270
module . exports = {
Original file line number Diff line number Diff line change @@ -29,8 +29,19 @@ class TestWritable extends Writable {
29
29
30
30
const writable = new TestWritable ( ) ;
31
31
32
- readline . clearScreenDown ( writable ) ;
32
+ assert . strictEqual ( readline . clearScreenDown ( writable ) , true ) ;
33
33
assert . 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
+ } , / E R R _ I N V A L I D _ C A L L B A C K / ) ;
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 ) ;
34
45
35
46
writable . data = '' ;
36
47
readline . clearLine ( writable , - 1 ) ;
You can’t perform that action at this time.
0 commit comments