python - 程序如何覆盖先前的输出行?

标签 python terminal

诸如 vimtopalsamixer 之类的程序输出多行文本并以某种方式操纵已经写入的文本行。

我知道将 \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.

关于python - 程序如何覆盖先前的输出行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18287633/

相关文章:

python - PyQt 和 PyCairo

python - AWS Systems Manager "In Progress"命令限制为 5 个?

php - 为什么当我在 Ubuntu 中运行一个 .php 脚本时它只是回应脚本本身?

python - 为什么在连接到使用 supervisord 运行的进程时 stdout 不刷新?

终端中的 python - 如何获取当前颜色?

python - 在程序的后面部分使用变量(python)

python - 在 python 中将列表写入 csv 文件的末尾

python - 模块未定义属性/类

linux - 如何将 'stdout' 重定向到 'stderr' 并将 'stderr' 重定向到 'stdout'?

ruby - Ruby 中的终端颜色