3

When you open vim or manpage you can't scroll up and check your previous commands, you just stay in this isolated display.

How does this magic work? How to implement it with python?

Or at least say how this thingy is called so I google it properly.

4

1 Answer 1

4

That is called The Alternate Screen Buffer. The terminal emulator provides two modes: primary and alternate; the latter has no scroll back, and when you switch between these buffers the contents in them is preserved. The smcup and rmcup ANSI Escape Sequences are used for switching.

For example, the following displays a FOOBAR banner text for three seconds in the alternate buffer, then switches back to the primary one:

$ tput smcup; banner foobar; sleep 3s; tput rmcup

In Python, you could print the corresponding escape sequences on application start and exit; there may even be a library that does that for you.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.