-2

I'm on a linux machine and what I need is a sh script/command to be able to remove all contents from a terminal window (even what appears as the contents of PS1 variable) and remove the ability to scroll.

Basically I need a blank terminal where you just see a program's output and you have no ability to scroll. Just like what nano command does.

I tried various methods, like clear, reset, tput reset and echo -en \\ec but all of them (although clearing almost all the content) leaves the prompt text intact, which I don't want. I also need not be able to scroll up or down in the terminal.

A solution could be to print some newline characters which amounts to the height of the terminal, but that way I could scroll up and eventually I'd see the prompt text, so this in combination with disabling scrolling/scrollbar could be a solution, but I don't know how to do it, and even then, I don't see this as a 'clean' solution.

Thanks.

Garmekain
  • 270
  • 2
  • 11

1 Answers1

6

all of them […] leaves the prompt text intact

Untrue. They all clear the screen (some of them — beware! — doing more than just that). Then your shell comes along, after they have finished running, and prints another prompt. If you wanted a program to run on a clear screen, you should have run it in the same command line, or script, where you ran the clear command, before the interactive shell prompts for another command line to be input.

clear ; some_program

what nano command does

nano is in the class of full screen TUI programs, alongside programs such as mc, less, nvim, tin, and so forth. What such programs do is use the termcap/terminfo database to obtain the control sequences for switching the terminal into and out of cursor addressing mode, which they emit to the terminal when they start up and tear down their user interfaces. Normally, the terminal is in scrolling mode.

For some terminal types, switching into cursor addressing mode under the covers switches to an alternate screen buffer, and the alternate screen buffer has no scrollback and hence no scroll bar widgets. This behaviour is not guaranteed for all terminal types, because not all terminal types even have an alternate screen buffer.

Further reading

JdeBP
  • 68,745