File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ The following special commands are supported by all REPL instances:
39
39
further input or processing of that expression.
40
40
* ` .clear ` : Resets the REPL ` context ` to an empty object and clears any
41
41
multi-line expression being input.
42
+ * ` .cls ` : Clear the screen (or press <kbd >Ctrl</kbd >+<kbd >L</kbd >).
42
43
* ` .exit ` : Close the I/O stream, causing the REPL to exit.
43
44
* ` .help ` : Show this list of special commands.
44
45
* ` .save ` : Save the current REPL session to a file:
Original file line number Diff line number Diff line change @@ -190,6 +190,11 @@ const {
190
190
const {
191
191
makeContextifyScript,
192
192
} = require ( 'internal/vm' ) ;
193
+ const {
194
+ clearScreenDown,
195
+ cursorTo,
196
+ } = require ( 'internal/readline/callbacks' ) ;
197
+
193
198
let nextREPLResourceNumber = 1 ;
194
199
// This prevents v8 code cache from getting confused and using a different
195
200
// cache from a resource of the same name
@@ -1821,6 +1826,16 @@ function defineDefaultCommands(repl) {
1821
1826
this . displayPrompt ( ) ;
1822
1827
} ,
1823
1828
} ) ;
1829
+
1830
+ repl . defineCommand ( 'cls' , {
1831
+ help : 'Clear the screen' ,
1832
+ action : function ( ) {
1833
+ cursorTo ( this . output , 0 , 0 ) ;
1834
+ clearScreenDown ( this . output ) ;
1835
+ this . displayPrompt ( ) ;
1836
+ } ,
1837
+ } ) ;
1838
+
1824
1839
if ( repl . terminal ) {
1825
1840
repl . defineCommand ( 'editor' , {
1826
1841
help : 'Enter editor mode' ,
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ require ( '../common' ) ;
4
+ const assert = require ( 'assert' ) ;
5
+ const repl = require ( 'repl' ) ;
6
+ const ArrayStream = require ( '../common/arraystream' ) ;
7
+
8
+ // eslint-disable-next-line no-control-regex
9
+ const clearChar = / \[ 1 ; 1 H \u001b \[ 0 J > / ;
10
+ let accum = '' ;
11
+ const output = new ArrayStream ( ) ;
12
+ output . write = ( data ) => ( accum += data . replace ( '\r' , '' ) ) ;
13
+
14
+ const r = repl . start ( {
15
+ input : new ArrayStream ( ) ,
16
+ output,
17
+ } ) ;
18
+ [ 'new Error' , 'Promise' ] . forEach ( ( cmd ) => r . write ( `${ cmd } \n` ) ) ;
19
+ assert . strictEqual ( accum . match ( clearChar ) , null ) ;
20
+ r . write ( '.cls\n' ) ;
21
+ assert . strictEqual ( accum . match ( clearChar ) . length > 0 , true ) ;
22
+ r . write ( '.exit\n' ) ;
Original file line number Diff line number Diff line change @@ -458,6 +458,7 @@ const errorTests = [
458
458
expect : [
459
459
/ \. b r e a k / ,
460
460
/ \. c l e a r / ,
461
+ / \. c l s / ,
461
462
/ \. e x i t / ,
462
463
/ \. h e l p / ,
463
464
/ \. l o a d / ,
You can’t perform that action at this time.
0 commit comments