@@ -32,18 +32,23 @@ try:
'bold': (True, 'bold', ''),
'invisible': (True, 'invis', ''),
'italic': (True, 'sitm', ''),
- 'black': (False, curses.COLOR_BLACK, ''),
- 'red': (False, curses.COLOR_RED, ''),
- 'green': (False, curses.COLOR_GREEN, ''),
- 'yellow': (False, curses.COLOR_YELLOW, ''),
- 'blue': (False, curses.COLOR_BLUE, ''),
- 'magenta': (False, curses.COLOR_MAGENTA, ''),
- 'cyan': (False, curses.COLOR_CYAN, ''),
- 'white': (False, curses.COLOR_WHITE, ''),
}
+
+ TERMINFO_COLOR_8 = {
+ 'black': curses.COLOR_BLACK,
+ 'red': curses.COLOR_RED,
+ 'green': curses.COLOR_GREEN,
+ 'yellow': curses.COLOR_YELLOW,
+ 'blue': curses.COLOR_BLUE,
+ 'magenta': curses.COLOR_MAGENTA,
+ 'cyan': curses.COLOR_CYAN,
+ 'white': curses.COLOR_WHITE,
+ }
+
except ImportError:
curses = None
_baseterminfoparams = {}
+ TERMINFO_COLOR_8 = {}
_enabledbydefault = True
@@ -132,6 +137,21 @@ except ImportError:
def loadcolortable(ui, extname, colortable):
_defaultstyles.update(colortable)
+def _terminfocolors(ui):
+ """Obtain defined terminfo colors as a dict.
+
+ Keys are color names. Values are tuples of (value, user-defined).
+ """
+ colors = {}
+ for color, value in TERMINFO_COLOR_8.items():
+ colors[color] = (value, False)
+
+ for key, value in ui.configitems('color'):
+ if key.startswith('color.'):
+ colors[key[6:]] = (int(value), True)
+
+ return colors
+
def _terminfosetup(ui, mode):
'''Initialize terminfo data and the terminal if we're in terminfo mode.'''
@@ -150,11 +170,11 @@ def _terminfosetup(ui, mode):
ui._terminfoparams.update(_baseterminfoparams)
+ for color, value in _terminfocolors(ui).items():
+ ui._terminfoparams[color] = (False, value[0], '')
+
for key, val in ui.configitems('color'):
- if key.startswith('color.'):
- newval = (False, int(val), '')
- ui._terminfoparams[key[6:]] = newval
- elif key.startswith('terminfo.'):
+ if key.startswith('terminfo.'):
newval = (True, '', val.replace('\\E', '\x1b'))
ui._terminfoparams[key[9:]] = newval
@@ -405,10 +405,11 @@ def _debugdisplaycolor(ui):
for effect in color._activeeffects(ui).keys():
ui._styles[effect] = effect
if ui._terminfoparams:
+ for k, v in color._terminfocolors(ui).items():
+ ui._styles['color.%s' % k if v[1] else k] = k
+
for k, v in ui.configitems('color'):
- if k.startswith('color.'):
- ui._styles[k] = k[6:]
- elif k.startswith('terminfo.'):
+ if k.startswith('terminfo.'):
ui._styles[k] = k[9:]
ui.write(_('available colors:\n'))
# sort label with a '_' after the other to group '_background' entry.