Search code examples
linuxterminalttypty

How to run another program and have it output to only a specific part of the terminal


I'm developing a tool to share a terminal session between multiple users.

Therefore my tool ramps up a pty, starts a shell and maps its i/o to the PTY.
stdin/stdout then gets mapped to the pty aswell.

On start and on terminal window resize, the PTY gets a TIOCGWINSZ syscall with the new sizes.

Now I'd like to keep the last line on my terminal free to render a ui/statusbar down there.
Reducing the amount of rows in the TIOCGWINSZ call by 1 seems to be semi working.

For demo purposes I set the size in TIOCGWINSZ to always be 80x23
Now, when running bash it's actually not limited by 23 rows as I had hoped.
When running vim, vim itself is adhereing to the size - which is nice.
But after quitting vim, bash now is limited to the 80x23?

It works as long as the terminal doesn't get resized, after that bash is using the full terminal size again.

See: https://asciinema.org/a/IXz2e0ni2ASPQcYpvcze8TePK

What is vim doing there to limit the "terminal size"? Some kind of magical escape sequence?
And since this is probably a hack - what would be the correct solution, especially if I not only want a spare line at the end, but have the whole output render at a specific offset with a specific size, e.g. like tmux panes?


Solution

  • Actually, nevermind.

    Solved this very case by actually using some obscure ansi escpae code (DECSTBM), e.g.: echo -en '\033[0;23r'