问题
Programs such as vim, top, or alsamixer output multiple lines of text and somehow manipulate lines of text that have already been written.
I know about writing the \r character to stdout, which returns the cursor to the start of the line, allowing overwriting of the current line, but not any lines before that.
What are these programs doing to have these more advanced UIs with fancy terminal manipulation? In my case I'm looking for a Python solution, but any general information would be appreciated.
回答1:
You need to look at the python curses library.
The curses module provides an interface to the curses library, the de-facto standard for portable advanced terminal handling.
While curses is most widely used in the Unix environment, versions are available for DOS, OS/2, and possibly other systems as well. This extension module is designed to match the API of ncurses, an open-source curses library hosted on Linux and the BSD variants of Unix.
来源:https://stackoverflow.com/questions/18287633/how-do-programs-overwrite-previous-lines-of-output