Skip to content

Instantly share code, notes, and snippets.

@iacore
Created May 16, 2022 19:28
Show Gist options
  • Save iacore/9adca67d6660e61dbde9c6b5b4a0547a to your computer and use it in GitHub Desktop.
Save iacore/9adca67d6660e61dbde9c6b5b4a0547a to your computer and use it in GitHub Desktop.
How to get alternate screen in terminal application

Use scrollback buffer

If terminal doesn't have a seperate screen buffer, but allow cursor movement, you can use new linereturn to create the new "screen", not touching the scrollback buffer above.

#############################
###### previous buffer ######
#############################
#############################
#############################
#############################
#############################
#############################
#############################
> new screen here
> new screen here
> new screen here
> new screen here
> new screen here
> new screen here
> new screen here
> new screen here

xterm

enter: CSI ? 1 0 4 7 h leave: CSI ? 1 0 4 7 l

See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html

termcap

ti and te switches to and back from an alternate screen buffer.

See man termcap.

terminfo

enter: smcup leave: rmcup

If nrrmc is set, then smcup will clean the alternate screen first.

See man terminfo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment