Escape sequence to clear the alternate screen adds contents to main screen's scrollback
Bug report
- iTerm2 version: 3.4.19
- OS version: macOS 13.0.1
- Attach
~/Library/Preferences/com.googlecode.iterm2.plist
here (drag-drop from finder into this window) com.googlecode.iterm2.plist - Attach a debug log, if possible. debuglog.txt
- Attach a screen capture video if it would make the reproduction steps clearer. bug-recording
PLEASE ATTACH YOUR PLIST FILE FOR BUG REPORTS! Seriously! I'll probably ask you for it if you don’t.
Detailed steps to reproduce the problem
- cat the attached bug file: bug:
$ cat bug
What happened
The bug file contains the following sequence:
- String
This should be visible!\n
; - Escape sequence to enter the alternate screen;
- Escape sequence to move the cursor to (0, 0);
- Escape sequence to set the foreground to magenta;
- String
XXX This should not be visible! XXX\n
; - Escape sequence to clear the whole screen; and
- Escape sequence to leave the alternate screen.
Step 6 not only clears the alternate screen, but it also seems to add magenta text from step 5 into the scroll back of the main screen. In the attached video, you can see where I scroll up and the magenta text shows up.
What should have happened
I think that clearing the alternate screen should not cause anything to be written to the main screen. Apple's Terminal and Visual Studio Code's terminal emulator do not show the magenta text outside the alternate screen.
There is a workaround: get the size of the terminal, and then for each row, move to that row and then clear the line. Here's an example file. Note that this depends on the size of the terminal, of course. I believe this is for a 25-row terminal working.