【问题标题】:curses: Straight line with last color at the bottom of the window in windows cmd诅咒:在windows cmd中窗口底部带有最后一种颜色的直线
【发布时间】:2021-01-21 19:03:00
【问题描述】:

问题

当我通过 windows cmd.exe 运行一个输出彩色文本的 curses 程序时,我在窗口底部看到一条无法选择的行。 如何删除它?

示例

import curses

def main(stdscr):
    curses.init_pair(1, 200, 100)
    stdscr.addstr("test ", curses.color_pair(1))
    stdscr.refresh()
    stdscr.getch()

curses.wrapper(main)

原因

问题是curses认为终端更小并调整窗口大小导致底部有这条线。

如果我这样做

curses.resize_term(10, 10)

第二条线出现在侧面并变得更大;我想这是 cmd 处理较小术语的方式

解决方案

要修复这个错误,我应该使用另一个终端或告诉用户,如果他在 Windows 上,他不应该继续使用 cmd,而是使用 PowerShellWindows Terminal 之类的东西

【问题讨论】:

  • 信息不足。在cmd.exe 中运行,可能是 PDCurses。前景色/背景色的合法范围可能是 16。
  • 在文本输出后尝试restoring the terminal to its previous graphics mode 使用curses.endwin()。您可能还想检查使用的颜色对是否有效

标签: python cmd curses python-curses


【解决方案1】:

我会以stdscr.clear() 开头(如果您需要清屏)

但是你应该在你的 addstr() 和 getch() 之间添加一个stdscr.refresh()

正如 T3ERR0R 所说,不要忘记脚本结束前的curses.endwin()

【讨论】:

  • 谢谢,stdscr.refresh() 有时确实会使行变小(在运行期间更改终端大小时)
猜你喜欢
  • 2013-10-26
  • 2022-08-14
  • 2013-06-10
  • 1970-01-01
  • 2011-11-11
  • 1970-01-01
  • 2012-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多