Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open vim-like, manpage-like isolated display using python?

Tags:

python

vim

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.

like image 970
aiven Avatar asked Apr 05 '26 17:04

aiven


1 Answers

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.

like image 58
Ingo Karkat Avatar answered Apr 08 '26 05:04

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!