Display screen caption on the first line of the terminal

gnu-screenterminal

When I start a new terminal, the prompt is on the first line. After working for a while (or running a command which produces some output), the prompt is on the last line. There it'll stay during the rest of the session unless I press Ctrll, run clear or reset or something similar.

To obtain some measure of continuity in the work, I use screen with a trick to display the session name in the caption (I use the last one with the two screen commands in .screenrc).

To avoid cognitive overhead by cluttering the work area, I'd like this caption to be displayed at the top of the terminal.

Best Answer

You're lucky, screen does honor save and resore commands. So with bash it can be done.

This gives instructions how to move the cursor around with special escape sequences. You can write "Hello World!" to the top left corner with this:

echo -e "\033[s\033[2;0HHello World!            \n                        \033[u"

Explained: The character \033[s saves the current cursor position, which is what we want b/c screen terminal sizes can vary, a lot. Then \033[2;0 moves the cursor to the third row to the first character (we begin counting in the top left corner and with 0). Then comes the text and a little illustration of what is possible. Finally the code \033[u puts the cursor back to where it was wenn \033[s was emmited.

This example moves the cursor to the second row because when issuing the command 2 newlines are printed so what is the current third row will be the first row.

You can use this together with the session caption you can already get by the explanation you already linked.

Related Question