【问题标题】:Use curses with colorama对 colorama 使用诅咒
【发布时间】:2017-02-14 11:05:14
【问题描述】:

是否可以在 colorama 中使用诅咒?这是我的代码,它打印转义序列:

from curses import wrapper
import colorama

STYLE = colorama.Fore.GREEN + colorama.Back.BLUE
TITLE = STYLE + 'Current terminal size:'
HEIGHT_STRING = STYLE + 'Screen height: {}\n'
WIDTH_STRING = STYLE + 'Screen width:  {}\n'
STR_LEN = 18


def main(stdscr):

    colorama.init()
    stdscr.clear()

    height, width = stdscr.getmaxyx()
    y = height//2 - 2
    x = width//2 - STR_LEN//2

    stdscr.addstr(y - 2, x, TITLE)
    stdscr.addstr(y, x, HEIGHT_STRING.format(height))
    stdscr.addstr(y + 1, x, WIDTH_STRING.format(width))

    stdscr.refresh()
    stdscr.getkey(y + 2, x)

if __name__ == '__main__':
    wrapper(main)

我知道 curses 不能在 Windows 上使用,只是想知道这是否可能

【问题讨论】:

    标签: python python-curses colorama


    【解决方案1】:

    鉴于colorama的描述,不(它使用硬编码的转义序列),没有其他形式的输出方法。

    根据Python documentationUniCurses 应该可以工作(在 Windows 上)。那是使用 PDCurses。 ncurses 本身在 Windows 上运行得很好,在 MSYS2 和 Cygwin 中有它的软件包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 2012-04-08
      • 2017-09-16
      • 1970-01-01
      • 2022-07-07
      • 2014-04-23
      • 2013-11-22
      相关资源
      最近更新 更多