"
window.inch(0,0)
将返回在包括该位置的属性的窗口中读取位置(0,0)处字符的值。如果您使用stdscr
作为窗口,则应获取整个屏幕的当前颜色。引用官方文档:
“返回窗口中给定位置的字符。底部8位是字符本身,上部位是属性。”
"
colors = stdscr.inch(0,0) & curses.A_COLOR
应该提取当前前景色和背景色。分离前景色和背景色是我目前正在尝试解决的问题,但是还没有什么好的方法。在Windows机器上,curses实现是PDCurses,PDCurses的源代码似乎表明两种颜色组合在4字节整数字段的最左侧字节中,但我还没有确认过。
还有一个window.getbkgd(),文档说会:
“返回给定窗口的当前背景字符/属性对。”
这有点含糊不清。我正在努力确定该函数实际返回的内容,尽管它听起来很像从inch函数返回的值。
希望对你有所帮助。
彼得
[编辑]这个curses调用序列可靠地给出了前景色和背景色编号。在*ix系统上,默认值为fg=-1和bg=-1(-1表示init_color()函数的“默认”),但在Windows(python 3.8+,windows-curses 2.2.0)上,缺省值为fg=7(COLOR_WHITE)和bg=0(COLOR_BLACK)。
attr = stdscr.getbkgd()
stdscr.addstr("scrbkgd={:08X}={}\n".format(attr, attr))
pair = curses.pair_number(attr)
if platform.system() == "Windows":
pair = pair >> 16
fg, bg = curses.pair_content (pair)
stdscr.addstr("color(scrbkgd) fg={:08X}={},bg={:08X}={}\n".format(fg, fg, bg, bg))
stdscr.getch()