程序如何覆盖之前的输出行? [英] How do programs overwrite previous lines of output?

查看:22
本文介绍了程序如何覆盖之前的输出行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Programs such as vim, top, or alsamixer output multiple lines of text and somehow manipulate lines of text that have already been written.

我知道将 \r 字符写入 stdout,它会将光标返回到行首,允许覆盖当前行,但不能覆盖之前的任何行.

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.

这些程序做了什么来拥有这些更高级的带有花哨终端操作的用户界面?在我的情况下,我正在寻找 Python 解决方案,但任何一般信息将不胜感激.

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.

推荐答案

需要看python curses 库.

You need to look at the python curses library.

curses 模块提供了一个到 curses 库的接口,便携式高级终端处理的事实标准.

The curses module provides an interface to the curses library, the de-facto standard for portable advanced terminal handling.

虽然 curses 在 Unix 环境中使用最广泛,但版本是可用于 DOS、OS/2 和其他可能的系统.这个扩展模块旨在匹配 ncurses 的 API,一个托管在 Linux 上的开源 curses 库和 BSD 变体Unix.

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.

这篇关于程序如何覆盖之前的输出行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆