Skip to content

Commit 9d3a0c8

Browse files
Vadim Demedessindresorhus
Vadim Demedes
authored andcommitted
Add .clearTerminal to clear the whole terminal, not just visible part of it (#6)
1 parent e8a567f commit 9d3a0c8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ x.scrollUp = ESC + 'S';
7878
x.scrollDown = ESC + 'T';
7979

8080
x.clearScreen = '\u001Bc';
81+
82+
x.clearTerminal = process.platform === 'win32' ?
83+
`${x.eraseScreen}${ESC}0f` :
84+
// 1. Erases the screen (Only done in case `2` is not supported)
85+
// 2. Erases the whole screen including scrollback buffer
86+
// 3. Moves cursor to the top-left position
87+
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
88+
`${x.eraseScreen}${ESC}3J${ESC}H`;
89+
8190
x.beep = BEL;
8291

8392
x.link = (text, url) => {

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ Scroll display down one line.
117117

118118
### clearScreen
119119

120-
Clear the terminal screen.
120+
Clear the terminal screen. (Viewport)
121+
122+
### clearTerminal
123+
124+
Clear the whole terminal, including scrollback buffer. (Not just the visible part of it)
121125

122126
### beep
123127

0 commit comments

Comments
 (0)