Open Tyriar opened 3 years ago
Hey @Tyriar :)
Yeah this is a naming issue. Most people want clearTerminal
, which emits the (correct) \x1b[2J\x1b[3J\x1b[H
.
clearScreen
should be renamed to fullReset
IMO, though this would be a major release.
@Qix- The problem with clearTerminal
is that it resets the scrollback buffer, which is not always what people want. So from the docs clearScreen
should actually clear the screen without resetting the buffer. So what I think what should happen is assign \u001B[H\u001B[2J
to clearScreen
(which is what the clear
command prints when executed) and use \u001Bc
as value for a new fullReset
command.
Something like this
exports.clearScreen = `${ESC}H${ESC}2J`;
exports.fullReset = '\u001Bc';
Then clearScreen
does what it's supposed to do according to the docs
Clear the terminal screen. (Viewport)
What do you think?
Yes sorry, I meant to edit addressing your original ticket but my internet cut out.
You want eraseScreen
. The cursor position should reset in that case, but if it doesn't then we should also add ESC[H
to it as well (though I don't think that's an issue).
The problem with eraseScreen
is that it seems to erase the screen but the cursor is not moved to the top left.
When I print the eraseScreen
sequence with printf '\u001B[2J'
So I think we have to add ESC[H
to move the cursor to the top left first.
Interesting, it seems to be random which terminals reset cursor position and which do not. Fun.
It's @sindresorhus's decision - should eraseScreen
be the pure terminal code or should it have the opinion that the cursor also goes to the top-left?
If the latter (which I would agree with), then ESC[H
should be appended to eraseScreen
and clearTerminal
should just have the codes ESC[2JESC[3JESC[H
directly instead of re-using eraseScreen
.
Maybe establish a difference between erase
and clear
. Idea:
eraseLine
- erasing line content, leaving the cursor aloneeraseLineLeft
- erasing line content left of the cursor, leaving the cursor aloneeraseLineRight
- erasing line content right of the cursor (+ content at cursor position), leaving the cursor aloneclearLine
- erasing line content + cursor to lefteraseScreen
- erasing screen content, leaving the cursor aloneeraseScreenTop
- erasing screen top content up to cursor position, leaving the cursor aloneeraseScreenBottom
- erasing screen bottom content from cursor position, leaving the cursor aloneclearScreen
- easing content + cursor to top-leftclearScrollback
- nullify scrollbackclearTerminal
- same as clearScreen
+ clearScrollback
resetTerminal
- RIS (or DECSTR, which is less "rebooty")This model tries to resemble the ECMA-48 sequence ideas (VT100+), have not looked up your existing definitions, thus it might collide here or there. Well see it as an inspiration.
There is some useful info in https://github.com/watchexec/clearscreen/blob/main/src/lib.rs
👋
We just had this issue reported which said
\x1bc
(fromclearScreen
) in xterm.js behaves differently to Terminal.app/iTerm https://github.com/xtermjs/xterm.js/issues/3315. We behave as xterm/VTE does and don't think we should change so I would suggest indicating the fact in this lib thatclearScreen
may actually clear everything.Note also that RIS is also more destructive than just clearing the buffer, also resetting modes among other things.