On 2021-11-09 17:42:57 -0600, Derek Martin wrote:
> On Tue, Nov 02, 2021 at 07:10:24PM +0100, Petr Pisar wrote:
> > V Mon, Nov 01, 2021 at 11:44:25AM +1100, Cameron Simpson napsal(a):
> > For that purposes I added ^[3J sequence into Linux 3.0 which erases not only
> > whole display but also a scroll-back buffer of the terminal. (Though Linux
> > 4.something removed scrollback buffer completely, you cannot Shift+PgUp
> > anymore.)
> > 
> > Maybe it's time to send a feature request to a terminal emulator of your
> > choice to implement it. (I remember xterm's maintainer was not against.)
> > clear of ncurses emmits it:
> > 
> > $ clear | hexdump -C
> > 00000000  1b 5b 48 1b 5b 32 4a 1b  5b 33 4a                 |.[H.[2J.[3J|
> > 0000000b
> > 
> > Naturaly it should also extend to altearnative screens. As the
> > purpose of the sequence is to erase all data for security reasons.
> 
> No that's not "natural."  The whole point of having alternative
> screens is to retain the data on one while you do work in the other.

The main point of the alternate screen is to retain data on the main
screen, which is typically a shell session. I doubt that people wish
to retain data on the alternate screen in general, and most terminals
don't offer an option to display the content of the alternate screen
(switching to the alternate screen with "tput smcup" won't work,
because it is automatically cleared at this time, even with xterm).
And note that even when the content of the alternate screen is kept
and can be retrieved, these are only partial data, because the
alternate screen does not have a scroll-back buffer.

BTW, in the past, xterm was clearing the alternate screen when
switching back to the main screen:

  https://invisible-island.net/xterm/xterm.faq.html#xterm_tite

  "The 1049 code is a refinement of 1047 and 1048, clearing the
  alternate screen before switching to it rather than after switching
  back to the normal screen. Since patch #90 in 1998 xterm allows you
  (with a popup menu entry designed to exploit this behavior) to
  switch the display back to the alternate screen to select text from
  it, to paste into the normal screen. You can also set or clear the
  titeInhibit resource using another popup menu entry (Enable
  Alternate Screen Switching)."

This is an interesting feature when an external command is run from
the application. For instance, with Mutt, this happens when replying
to a mail: Mutt quits the alternate screen before running the editor,
but one may still want the data that were displayed before the editor
was run.

> If you want the alternate screen cleared, clear it.  If worse comes to
> worst, close the terminal.  A command-line option to clear might be
> nice to make this easy for the user, but it should not be the default
> behavior.  Then if it really is what you want, all the time, you can
> just make a shell alias:
> 
> alias clear="clear --clear-alternate-screen-also"

That doesn't exist, but a solution to clear the alternate screen
is "tput smcup; tput rmcup" (and you can add "clear" if you want
to clear the main screen too).

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to