在正确的诅咒/窗口初始化之后,我可以对默认颜色对进行颜色配对,例如使用前景色、-1 和 -1、背景色,但是当我开始使用自定义对 #s 和 bg/fg 颜色值 > 0x8 自定义对时,我得到了意外或错误的结果。
术语的环境 $TERM == 'xterm-256color'
Python 的 curses.COLORS == 256
Python 的 curses.COLOR_PAIRS == 32767
Python 的版本 == 2.7.7,curses == 2.2
#!/usr/bin/env python
"""Dumbed down code to follow:"""
import curses
# init
window = curses.initscr()
curses.start_color()
curses.use_default_colors()
# assign 'default' pairs, pairs are assigned +1 MORE than the color value!
for each in range(curses.COLORS):
curses.init_pair(each + 1, each, -1)
for each in range(curses.COLORS):
curses.init_pair(each + 1 + curses.COLORS, -1, each)
# custom/non-default pair
curses.init_pair(1 + 2*curses.COLORS, 0x0f, 0x15) # white on cobalt according to colors above ???
curses.init_pair(4321, 0xd5, 0x81) # hot pink on violet according to colors above ???
# setup
curses.meta(1)
curses.noecho()
curses.cbreak()
window.leaveok(1)
window.scrollok(0)
window.keypad(1)
window.refresh()
# print all pairs in their colors
for each in range(1 + 2*curses.COLORS):
window.addstr(hex(each).join(' '), curses.color_pair(each)) # these are all perfect
window.addstr(hex(1 + 2*curses.COLORS).join(' '), curses.color_pair(1 + 2*curses.COLORS)) # nope: this prints 0,-1: black on default ???
window.addstr(hex(4321).join(' '), curses.color_pair(4321)) # nope: this prints 0xe1,-1: pinkish on default ???
# update
window.noutrefresh()
curses.doupdate()
# pause
window.getch()
# teardown
window.leaveok(0)
window.scrollok(1)
window.keypad(0)
curses.echo()
curses.nocbreak()
curses.endwin()
检查上面的“???”。我错过了什么概念?我想为每个 256 色加上一些自定义 fg/bg 有一个颜色对?