How do programs overwrite previous lines of output?

血红的双手。 提交于 2020-08-27 21:48:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!