诸如 vim
、top
或 alsamixer
之类的程序输出多行文本并以某种方式操纵已经写入的文本行。
我知道将 \r
字符写入标准输出,它会将光标返回到行的开头,允许覆盖当前行,但不能覆盖之前的任何行。
这些程序做了什么来拥有这些更高级的 UI 和精美的终端操作?就我而言,我正在寻找 Python 解决方案,但如果能提供任何一般信息,我们将不胜感激。
你需要看看python curses图书馆。
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.
我是一名优秀的程序员,十分优秀!