Skip to main content
 首页 » 编程设计

'htop, atop' 实用程序中的 python termios 模式

2025年05月04日81shihaiming

当可以通过坐标对每个单元格进行操作时,如何在模式下使用终端窗口?我不知道这个模式是怎么命名的,这就是为什么我不能用谷歌搜索它。另外,我知道 this approach ,但现在我很感兴趣如何在低级别上使用它。

更新: 好的,我阅读了所有 termios 手册页和其他一些文档,现在我唯一能说的是 - 我仍然不知道如何在终端的某个地方制作旋转条,即按帧:-\|/- .:(

UPD2 哦,突然发现了there :

import sys 
import time 
 
f='-\\|/' 
 
for i in range(10): 
    sys.stdout.write("\r{0}".format(f[i%4])) 
    sys.stdout.flush() 
    time.sleep(0.5) 

那么,本主题的最后一个问题 - 仅使用 termios 的坐标怎么样?

子问题[已解决]:

当我使用 curses 时,即来自 this post 的第二个代码 list - 它使我的半透明终端窗口不透明,当 top 不这样做时。如何保持透明?

解决方案:在 def pbar(window): 的第一个字符串中插入 curses.use_default_colors()

请您参考如下方法:

curses ( http://docs.python.org/library/curses.html ) 或控制台 ( http://effbot.org/zone/console-handbook.htm ) 模块是你想要的

Console.py 的源代码可在此处获得 http://www.math.uiuc.edu/~gfrancis/illimath/windows/aszgard_mini/pylibs/readline/Console.py我确定您可以看看那个……虽然我确定这可能是一个很大的痛苦,这就是人们总是使用诅咒的原因……

在 Windows 上你可能想浏览 msdn http://msdn.microsoft.com/en-us/library/system.console.aspx 并使用 ctypes.cdll.whatever 调用它