Show More
@@ -196,9 +196,12 b' def _terminfosetup(ui, mode):' | |||
|
196 | 196 | if mode not in ('auto', 'terminfo'): |
|
197 | 197 | return |
|
198 | 198 | |
|
199 | _terminfo_params.update((key[6:], (False, int(val))) | |
|
199 | _terminfo_params.update((key[6:], (False, int(val), '')) | |
|
200 | 200 | for key, val in ui.configitems('color') |
|
201 | 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 | 206 | try: |
|
204 | 207 | curses.setupterm() |
@@ -206,10 +209,10 b' def _terminfosetup(ui, mode):' | |||
|
206 | 209 | _terminfo_params = {} |
|
207 | 210 | return |
|
208 | 211 | |
|
209 | for key, (b, e) in _terminfo_params.items(): | |
|
212 | for key, (b, e, c) in _terminfo_params.items(): | |
|
210 | 213 | if not b: |
|
211 | 214 | continue |
|
212 | if not curses.tigetstr(e): | |
|
215 | if not c and not curses.tigetstr(e): | |
|
213 | 216 | # Most terminals don't support dim, invis, etc, so don't be |
|
214 | 217 | # noisy and use ui.debug(). |
|
215 | 218 | ui.debug("no terminfo entry for %s\n" % e) |
@@ -290,26 +293,26 b' def _modesetup(ui, coloropt):' | |||
|
290 | 293 | |
|
291 | 294 | try: |
|
292 | 295 | import curses |
|
293 |
# Mapping from effect name to terminfo attribute name |
|
|
294 | # This will also force-load the curses module. | |
|
295 | _terminfo_params = {'none': (True, 'sgr0'), | |
|
296 | 'standout': (True, 'smso'), | |
|
297 | 'underline': (True, 'smul'), | |
|
298 | 'reverse': (True, 'rev'), | |
|
299 | 'inverse': (True, 'rev'), | |
|
300 | 'blink': (True, 'blink'), | |
|
301 | 'dim': (True, 'dim'), | |
|
302 | 'bold': (True, 'bold'), | |
|
303 | 'invisible': (True, 'invis'), | |
|
304 | 'italic': (True, 'sitm'), | |
|
305 | 'black': (False, curses.COLOR_BLACK), | |
|
306 | 'red': (False, curses.COLOR_RED), | |
|
307 | 'green': (False, curses.COLOR_GREEN), | |
|
308 | 'yellow': (False, curses.COLOR_YELLOW), | |
|
309 | 'blue': (False, curses.COLOR_BLUE), | |
|
310 | 'magenta': (False, curses.COLOR_MAGENTA), | |
|
311 | 'cyan': (False, curses.COLOR_CYAN), | |
|
312 | 'white': (False, curses.COLOR_WHITE)} | |
|
296 | # Mapping from effect name to terminfo attribute name (or raw code) or | |
|
297 | # color number. This will also force-load the curses module. | |
|
298 | _terminfo_params = {'none': (True, 'sgr0', ''), | |
|
299 | 'standout': (True, 'smso', ''), | |
|
300 | 'underline': (True, 'smul', ''), | |
|
301 | 'reverse': (True, 'rev', ''), | |
|
302 | 'inverse': (True, 'rev', ''), | |
|
303 | 'blink': (True, 'blink', ''), | |
|
304 | 'dim': (True, 'dim', ''), | |
|
305 | 'bold': (True, 'bold', ''), | |
|
306 | 'invisible': (True, 'invis', ''), | |
|
307 | 'italic': (True, 'sitm', ''), | |
|
308 | 'black': (False, curses.COLOR_BLACK, ''), | |
|
309 | 'red': (False, curses.COLOR_RED, ''), | |
|
310 | 'green': (False, curses.COLOR_GREEN, ''), | |
|
311 | 'yellow': (False, curses.COLOR_YELLOW, ''), | |
|
312 | 'blue': (False, curses.COLOR_BLUE, ''), | |
|
313 | 'magenta': (False, curses.COLOR_MAGENTA, ''), | |
|
314 | 'cyan': (False, curses.COLOR_CYAN, ''), | |
|
315 | 'white': (False, curses.COLOR_WHITE, '')} | |
|
313 | 316 | except ImportError: |
|
314 | 317 | _terminfo_params = {} |
|
315 | 318 | |
@@ -375,9 +378,12 b' def _effect_str(effect):' | |||
|
375 | 378 | if effect.endswith('_background'): |
|
376 | 379 | bg = True |
|
377 | 380 | effect = effect[:-11] |
|
378 | attr, val = _terminfo_params[effect] | |
|
381 | attr, val, termcode = _terminfo_params[effect] | |
|
379 | 382 | if attr: |
|
380 | return curses.tigetstr(val) | |
|
383 | if termcode: | |
|
384 | return termcode | |
|
385 | else: | |
|
386 | return curses.tigetstr(val) | |
|
381 | 387 | elif bg: |
|
382 | 388 | return curses.tparm(curses.tigetstr('setab'), val) |
|
383 | 389 | else: |
@@ -412,7 +418,7 b' def valideffect(effect):' | |||
|
412 | 418 | |
|
413 | 419 | def configstyles(ui): |
|
414 | 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 | 422 | continue |
|
417 | 423 | cfgeffects = ui.configlist('color', status) |
|
418 | 424 | if cfgeffects: |
@@ -237,6 +237,25 b' hg status -A (with terminfo color):' | |||
|
237 | 237 | \x1b[30m\x1b[30mC \x1b[30m\x1b[30m\x1b[30m.hgignore\x1b[30m (esc) |
|
238 | 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 | 259 |
|
|
241 | 260 |
|
|
242 | 261 |
General Comments 0
You need to be logged in to leave comments.
Login now