0

When I want to provide a visual break after a long list of output lines from a command I normally run clear so that the terminal will clear the screen, put my prompt back at 0,0 while also keeping the history (vs reset).

The problem is that when I scroll up, the terminal is now back to the long lines of output, without any kind of break in history.

I had the idea of "echo'ing a screen's worth of empty lines" by doing yes '' | head -n $(tput lines), but then my cursor is at the bottom of the screen. So I try to run clear but it seems to remove the empty lines. I also tried tput cup 0 0 but that also removes the empty lines (I guess by "reverting" my screen's worth of empty lines).

I can force the empty lines by printing any character with yes instead of the empty string, or I can print some character/message at the end of the empty lines. But now I'm adding garbage.

The only thing I've been able to get to work is:

yes '' | head -n $(($(tput lines) * 2))
tput cup 0 0

Is there another way or is this my only option?

mmlb
  • 877
  • 10
  • 24

1 Answers1

0

Essentially yes - you can express the script in various ways, but most terminals don't allow one aspect which could be used to improve your script: when scrolling up, they don't move blank lines into the scrollbar. So you can't (for example) do it like this:

tput cup $(tput lines)
tput indn $(($(tput lines) * 2))
tput cup 0 0
tput ed

since the blank lines that you would expect from indn (index) are ignored.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105