Reputation: 3670
In particular I would like to send
ctrl + l
to clear the terminal so each time I test my script the terminal is clean.
Upvotes: 2
Views: 741
Reputation: 19040
If you're on linux :
console.log('\033[2J');
If you're on Windows, I think this works : (sets the cursor at 0,0)
var util = require('util');
util.print("\u001b[2J\u001b[0;0H");
We are basically using the power of ANSI escape codes:
These are ANSI escape codes. The first one (
\033[2J
) clears the entire screen (J
) from top to bottom (2
). The second code (\033[1;1H
) positions the cursor at row1
, column1
.
You may want to read the full Wikipedia article just here to fully understand it.
Upvotes: 2