##// END OF EJS Templates
color: allow for user-configurable terminfo codes for effects...
Danek Duvall -
r30173:f34a8cff default
parent child Browse files
Show More
@@ -196,9 +196,12 b' def _terminfosetup(ui, mode):'
196 if mode not in ('auto', 'terminfo'):
196 if mode not in ('auto', 'terminfo'):
197 return
197 return
198
198
199 _terminfo_params.update((key[6:], (False, int(val)))
199 _terminfo_params.update((key[6:], (False, int(val), ''))
200 for key, val in ui.configitems('color')
200 for key, val in ui.configitems('color')
201 if key.startswith('color.'))
201 if key.startswith('color.'))
202 _terminfo_params.update((key[9:], (True, '', val.replace('\\E', '\x1b')))
203 for key, val in ui.configitems('color')
204 if key.startswith('terminfo.'))
202
205
203 try:
206 try:
204 curses.setupterm()
207 curses.setupterm()
@@ -206,10 +209,10 b' def _terminfosetup(ui, mode):'
206 _terminfo_params = {}
209 _terminfo_params = {}
207 return
210 return
208
211
209 for key, (b, e) in _terminfo_params.items():
212 for key, (b, e, c) in _terminfo_params.items():
210 if not b:
213 if not b:
211 continue
214 continue
212 if not curses.tigetstr(e):
215 if not c and not curses.tigetstr(e):
213 # Most terminals don't support dim, invis, etc, so don't be
216 # Most terminals don't support dim, invis, etc, so don't be
214 # noisy and use ui.debug().
217 # noisy and use ui.debug().
215 ui.debug("no terminfo entry for %s\n" % e)
218 ui.debug("no terminfo entry for %s\n" % e)
@@ -290,26 +293,26 b' def _modesetup(ui, coloropt):'
290
293
291 try:
294 try:
292 import curses
295 import curses
293 # Mapping from effect name to terminfo attribute name or color number.
296 # Mapping from effect name to terminfo attribute name (or raw code) or
294 # This will also force-load the curses module.
297 # color number. This will also force-load the curses module.
295 _terminfo_params = {'none': (True, 'sgr0'),
298 _terminfo_params = {'none': (True, 'sgr0', ''),
296 'standout': (True, 'smso'),
299 'standout': (True, 'smso', ''),
297 'underline': (True, 'smul'),
300 'underline': (True, 'smul', ''),
298 'reverse': (True, 'rev'),
301 'reverse': (True, 'rev', ''),
299 'inverse': (True, 'rev'),
302 'inverse': (True, 'rev', ''),
300 'blink': (True, 'blink'),
303 'blink': (True, 'blink', ''),
301 'dim': (True, 'dim'),
304 'dim': (True, 'dim', ''),
302 'bold': (True, 'bold'),
305 'bold': (True, 'bold', ''),
303 'invisible': (True, 'invis'),
306 'invisible': (True, 'invis', ''),
304 'italic': (True, 'sitm'),
307 'italic': (True, 'sitm', ''),
305 'black': (False, curses.COLOR_BLACK),
308 'black': (False, curses.COLOR_BLACK, ''),
306 'red': (False, curses.COLOR_RED),
309 'red': (False, curses.COLOR_RED, ''),
307 'green': (False, curses.COLOR_GREEN),
310 'green': (False, curses.COLOR_GREEN, ''),
308 'yellow': (False, curses.COLOR_YELLOW),
311 'yellow': (False, curses.COLOR_YELLOW, ''),
309 'blue': (False, curses.COLOR_BLUE),
312 'blue': (False, curses.COLOR_BLUE, ''),
310 'magenta': (False, curses.COLOR_MAGENTA),
313 'magenta': (False, curses.COLOR_MAGENTA, ''),
311 'cyan': (False, curses.COLOR_CYAN),
314 'cyan': (False, curses.COLOR_CYAN, ''),
312 'white': (False, curses.COLOR_WHITE)}
315 'white': (False, curses.COLOR_WHITE, '')}
313 except ImportError:
316 except ImportError:
314 _terminfo_params = {}
317 _terminfo_params = {}
315
318
@@ -375,9 +378,12 b' def _effect_str(effect):'
375 if effect.endswith('_background'):
378 if effect.endswith('_background'):
376 bg = True
379 bg = True
377 effect = effect[:-11]
380 effect = effect[:-11]
378 attr, val = _terminfo_params[effect]
381 attr, val, termcode = _terminfo_params[effect]
379 if attr:
382 if attr:
380 return curses.tigetstr(val)
383 if termcode:
384 return termcode
385 else:
386 return curses.tigetstr(val)
381 elif bg:
387 elif bg:
382 return curses.tparm(curses.tigetstr('setab'), val)
388 return curses.tparm(curses.tigetstr('setab'), val)
383 else:
389 else:
@@ -412,7 +418,7 b' def valideffect(effect):'
412
418
413 def configstyles(ui):
419 def configstyles(ui):
414 for status, cfgeffects in ui.configitems('color'):
420 for status, cfgeffects in ui.configitems('color'):
415 if '.' not in status or status.startswith('color.'):
421 if '.' not in status or status.startswith(('color.', 'terminfo.')):
416 continue
422 continue
417 cfgeffects = ui.configlist('color', status)
423 cfgeffects = ui.configlist('color', status)
418 if cfgeffects:
424 if cfgeffects:
@@ -237,6 +237,25 b' hg status -A (with terminfo color):'
237 \x1b[30m\x1b[30mC \x1b[30m\x1b[30m\x1b[30m.hgignore\x1b[30m (esc)
237 \x1b[30m\x1b[30mC \x1b[30m\x1b[30m\x1b[30m.hgignore\x1b[30m (esc)
238 \x1b[30m\x1b[30mC \x1b[30m\x1b[30m\x1b[30mmodified\x1b[30m (esc)
238 \x1b[30m\x1b[30mC \x1b[30m\x1b[30m\x1b[30mmodified\x1b[30m (esc)
239
239
240 The user can define effects with raw terminfo codes:
241
242 $ cat <<EOF >> $HGRCPATH
243 > # Completely bogus code for dim
244 > terminfo.dim = \E[88m
245 > # We can override what's in the terminfo database, too
246 > terminfo.bold = \E[2m
247 > EOF
248 $ TERM=hgterm TERMINFO="$TESTTMP/terminfo" hg status --config color.mode=terminfo --config color.status.clean=dim --color=always -A
249 \x1b[30m\x1b[32m\x1b[2mA \x1b[30m\x1b[30m\x1b[32m\x1b[2madded\x1b[30m (esc)
250 \x1b[30m\x1b[32m\x1b[2mA \x1b[30m\x1b[30m\x1b[32m\x1b[2mcopied\x1b[30m (esc)
251 \x1b[30m\x1b[30m modified\x1b[30m (esc)
252 \x1b[30m\x1b[31m\x1b[2mR \x1b[30m\x1b[30m\x1b[31m\x1b[2mremoved\x1b[30m (esc)
253 \x1b[30m\x1b[36m\x1b[2m\x1b[4m! \x1b[30m\x1b[30m\x1b[36m\x1b[2m\x1b[4mdeleted\x1b[30m (esc)
254 \x1b[30m\x1b[35m\x1b[2m\x1b[4m? \x1b[30m\x1b[30m\x1b[35m\x1b[2m\x1b[4munknown\x1b[30m (esc)
255 \x1b[30m\x1b[30m\x1b[2mI \x1b[30m\x1b[30m\x1b[30m\x1b[2mignored\x1b[30m (esc)
256 \x1b[30m\x1b[88mC \x1b[30m\x1b[30m\x1b[88m.hgignore\x1b[30m (esc)
257 \x1b[30m\x1b[88mC \x1b[30m\x1b[30m\x1b[88mmodified\x1b[30m (esc)
258
240 #endif
259 #endif
241
260
242
261
General Comments 0
You need to be logged in to leave comments. Login now