将 curses 与 colorama 结合使用
Use curses with colorama
是否可以使用 curses with 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)
我知道 Windows 不能使用 curses,只是想知道这是否可行
鉴于colorama的描述,没有(它使用硬编码的转义序列),没有其他形式的输出方法。
根据 Python documentation, UniCurses should work (on Windows). That's using PDCurses. ncurses itself works for Windows well enough, there being packages for it in MSYS2 和 Cygwin.
是否可以使用 curses with 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)
我知道 Windows 不能使用 curses,只是想知道这是否可行
鉴于colorama的描述,没有(它使用硬编码的转义序列),没有其他形式的输出方法。
根据 Python documentation, UniCurses should work (on Windows). That's using PDCurses. ncurses itself works for Windows well enough, there being packages for it in MSYS2 和 Cygwin.