是否可以/如何在python中将预终端格式的彩色文本呈现为curses.window
?在
基本上,我尝试在已经呈现彩色日志输出的现有控制台应用程序的基础上添加一些简单的基于curses的UI,我试图将其重定向到curses window
。在
然而,似乎诅咒会以某种方式关闭控制颜色的各种控制代码。在
下面是一个最小的脚本,使用colorama
作为文本源的代理:
import colorama
import curses
def run_gui():
stdscr = curses.initscr()
curses.start_color()
curses.use_default_colors()
stdscr.insertln()
stdscr.insertln()
stdscr.insstr(colorama.Fore.RED+'wattt'+colorama.Style.RESET_ALL)
stdscr.insertln()
stdscr.insstr(colorama.Fore.GREEN+'wattt'+colorama.Style.RESET_ALL)
stdscr.insertln()
stdscr.insstr(colorama.Fore.YELLOW+'wattt'+colorama.Style.RESET_ALL)
stdscr.insertln()
stdscr.refresh()
if __name__ == '__main__':
run_gui()
这将呈现:
^{pr2}$有没有一种方法我可以告诉诅咒允许正常的控制代码,或者我将不得不返工所有现有的颜色功能?在
简写:后者(“返工”)。在
长:
“正常控制代码”恰好与设备相关;curses为终端提供了一个与设备无关的接口。引用manual page:
实际上,大多数curses实现通过terminfo-based functions提供了一个低级接口,它允许您进行特殊调整,但是
Python文档提到属性,例如在^{}str[^{} attr]^{}
你的例子可以像
你问的问题以前也有人问过。例如:
相关问题 更多 >
编程相关推荐