fixed color initialization, other bugs

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-06-10 17:55:33 -04:00
parent c56299b992
commit c27e561865
2 changed files with 45 additions and 10 deletions

View File

@ -33,6 +33,11 @@ def color256(name, fallback, abbrev, r, g, b):
abbrev2 = '%s%d%d%d' % (abbrev, r, g, b) abbrev2 = '%s%d%d%d' % (abbrev, r, g, b)
if curses.COLORS == 256: if curses.COLORS == 256:
value = 16 + r * 36 + g * 6 + b value = 16 + r * 36 + g * 6 + b
if curses.can_change_color():
try:
curses.init_color(value, r * 200, g * 200, b* 200)
except:
raise Exception("arghh: %d, %d, %d, %d", value, r * 200, g * 200, b * 200)
else: else:
value = fallback value = fallback
add_color(name2, value, abbrev2) add_color(name2, value, abbrev2)
@ -52,6 +57,11 @@ def init():
add_color('black', curses.COLOR_BLACK, 'B') add_color('black', curses.COLOR_BLACK, 'B')
add_color('white', curses.COLOR_WHITE, 'w') add_color('white', curses.COLOR_WHITE, 'w')
if default_color:
colors['default'] = -1
ascii_map['d'] = 'default'
rev_ascii_map['default'] = 'd'
inited = True inited = True
for i in range(0, 256): for i in range(0, 256):
@ -59,8 +69,20 @@ def init():
abbrev = 'f%02x' % i abbrev = 'f%02x' % i
add_color(name, i, abbrev) add_color(name, i, abbrev)
# GREY
for i in range(0, 24): for i in range(0, 24):
color256('grey', curses.COLOR_WHITE, 'G', i, i, i) name2 = 'grey%d' % i
abbrev2 = 'G%d' % i
if curses.COLORS == 256:
value = 232 + i
if curses.can_change_color():
try:
curses.init_color(value, i * 41, i * 41, i * 41)
except:
raise Exception("arghh: %d, %d, %d, %d", value, i * 41, i * 41, i * 41)
else:
value = curses.COLOR_WHITE
add_color(name2, value, abbrev2)
for i in range(1, 6): for i in range(1, 6):
for j in range(0, i): for j in range(0, i):
@ -75,11 +97,6 @@ def init():
color256('cyan', curses.COLOR_CYAN, 'c', j, i, i) color256('cyan', curses.COLOR_CYAN, 'c', j, i, i)
color256('magenta', curses.COLOR_MAGENTA, 'm', i, j, i) color256('magenta', curses.COLOR_MAGENTA, 'm', i, j, i)
if default_color:
colors['default'] = -1
ascii_map['d'] = 'default'
rev_ascii_map['default'] = 'd'
def build(fg, bg, *attr): def build(fg, bg, *attr):
v = curses.A_NORMAL | pairs(fg, bg) v = curses.A_NORMAL | pairs(fg, bg)
for x in attr: for x in attr:
@ -103,7 +120,10 @@ def pairs(fg, bg):
assert index < curses.COLOR_PAIRS, "too many colors" assert index < curses.COLOR_PAIRS, "too many colors"
assert type(fgi) == type(0), "illegal fgi: %r" % fgi assert type(fgi) == type(0), "illegal fgi: %r" % fgi
assert type(bgi) == type(0), "illegal bgi: %r" % bgi assert type(bgi) == type(0), "illegal bgi: %r" % bgi
try:
curses.init_pair(index, fgi, bgi) curses.init_pair(index, fgi, bgi)
except:
raise Exception('failed to init %d,%d,%d' % (index, fgi, bgi))
_pairs[key] = curses.color_pair(index) _pairs[key] = curses.color_pair(index)
_colors.append(key) _colors.append(key)
index = len(_colors) + 1 index = len(_colors) + 1

View File

@ -11,8 +11,23 @@ class Colortest(Fundamental):
name = 'Colortest' name = 'Colortest'
grammar = ColortestGrammar grammar = ColortestGrammar
colors = {} colors = {}
for i in range(0, 256):
c = '%02x' % i def abc(name, r, g, b):
colors['z' + c] = ('default', 'f' + c) name2 = name + str(r) + str(g) + str(b)
ColortestGrammar.rules.append(PatternRule('z-' + name2, name2))
Colortest.colors['z-' + name2] = (name2, 'default')
for i in range(1, 6):
for j in range(0, i):
for k in range(0, i):
abc('red', i, j, k)
abc('green', j, i, k)
abc('blue', j, k, i)
for i in range(1, 6):
for j in range(0, i):
abc('yellow', i, i, j)
abc('cyan', j, i, i)
abc('magenta', i, j, i)
install = Colortest.install install = Colortest.install