[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Stretch]Typing ""clear" on terminal restricts the scrollback to only a screenful



Am 2017-06-21 05:57, schrieb Avinash Sonawane:
On Wed, Jun 21, 2017 at 3:26 AM, Larry Dighera <LDighera@att.net> wrote:

Try: tput clear

Right. My bad! I already did that. But I have always considered
`clear` and `tput clear` to be the same so I didn't mention it before.
Anyways I got exactly same behavior with `tput clear`.

'clear' and 'tput clear' are identical in Stretch, both are from
ncurses-bin. This was not true in Jessie though, ncurses did
change behavior between Jessie and Stretch.

The following escape sequences are printed by clear / tput clear:

            |  Jessie                 |  Stretch
------------+-------------------------+------------------------
clear       |  \033[3;J\033[H\033[2J  |  \033[3J\033[H\033[2J
tput clear  |  \033[H\033[2J          |  \033[3J\033[H\033[2J


To decode them (man 4 console_codes):

 \033[3J or \033[3;J
           clear the entire scrollback buffer
 \033[H
           go to position on the screen,
           default: top left corner
 \033[2J
           clear entire screen

So what happened is that 'tput clear' in Stretch now behaves the
same as 'clear', while the version in Jessie of 'tput clear'
wouldn't clear the scrollback buffer.

Furthermore, whether the scrollback buffer is actually cleared is
also up to the program managing the buffer; the Linux text console
respects that, but e.g. 'Konsole' from KDE doesn't, there \033[3J
has the same effect as \033[2J - the scrollback buffer remains
intact regardless. (At least in the default settings, haven't
checked if that behavior can be changed.) It could also be that
the terminal emulator you're using has also changed it's behavior.

In any case: if you want 'clear' to act the same way 'tput clear'
acted in Jessie, you can simply add

alias clear="printf '\033[H\033[2J'"

to your .bashrc (or similar if you're using a different shell),
that should get you the behavior you had beforehand. [1]

Regards,
Christian

[1] Technically this alias is not 100% correct, as both 'clear'
and 'tput clear' will interpret the TERM environment variable and
make sure that the sequences they send out are actually understood
by the terminal. However, in practice any terminal you're going to
use this on is going to support this specific sequence, so you
don't need to worry about these details. In case you're accessing
from ancient terminal hardware (think 70s mainframes or similar)
this alias might not work though.


Reply to: