Show More
@@ -0,0 +1,62 b'' | |||||
|
1 | # utility for color output for Mercurial commands | |||
|
2 | # | |||
|
3 | # Copyright (C) 2007 Kevin Christen <kevin.christen@gmail.com> and other | |||
|
4 | # | |||
|
5 | # This software may be used and distributed according to the terms of the | |||
|
6 | # GNU General Public License version 2 or any later version. | |||
|
7 | ||||
|
8 | from __future__ import absolute_import | |||
|
9 | ||||
|
10 | _styles = {'grep.match': 'red bold', | |||
|
11 | 'grep.linenumber': 'green', | |||
|
12 | 'grep.rev': 'green', | |||
|
13 | 'grep.change': 'green', | |||
|
14 | 'grep.sep': 'cyan', | |||
|
15 | 'grep.filename': 'magenta', | |||
|
16 | 'grep.user': 'magenta', | |||
|
17 | 'grep.date': 'magenta', | |||
|
18 | 'bookmarks.active': 'green', | |||
|
19 | 'branches.active': 'none', | |||
|
20 | 'branches.closed': 'black bold', | |||
|
21 | 'branches.current': 'green', | |||
|
22 | 'branches.inactive': 'none', | |||
|
23 | 'diff.changed': 'white', | |||
|
24 | 'diff.deleted': 'red', | |||
|
25 | 'diff.diffline': 'bold', | |||
|
26 | 'diff.extended': 'cyan bold', | |||
|
27 | 'diff.file_a': 'red bold', | |||
|
28 | 'diff.file_b': 'green bold', | |||
|
29 | 'diff.hunk': 'magenta', | |||
|
30 | 'diff.inserted': 'green', | |||
|
31 | 'diff.tab': '', | |||
|
32 | 'diff.trailingwhitespace': 'bold red_background', | |||
|
33 | 'changeset.public' : '', | |||
|
34 | 'changeset.draft' : '', | |||
|
35 | 'changeset.secret' : '', | |||
|
36 | 'diffstat.deleted': 'red', | |||
|
37 | 'diffstat.inserted': 'green', | |||
|
38 | 'histedit.remaining': 'red bold', | |||
|
39 | 'ui.prompt': 'yellow', | |||
|
40 | 'log.changeset': 'yellow', | |||
|
41 | 'patchbomb.finalsummary': '', | |||
|
42 | 'patchbomb.from': 'magenta', | |||
|
43 | 'patchbomb.to': 'cyan', | |||
|
44 | 'patchbomb.subject': 'green', | |||
|
45 | 'patchbomb.diffstats': '', | |||
|
46 | 'rebase.rebased': 'blue', | |||
|
47 | 'rebase.remaining': 'red bold', | |||
|
48 | 'resolve.resolved': 'green bold', | |||
|
49 | 'resolve.unresolved': 'red bold', | |||
|
50 | 'shelve.age': 'cyan', | |||
|
51 | 'shelve.newest': 'green bold', | |||
|
52 | 'shelve.name': 'blue bold', | |||
|
53 | 'status.added': 'green bold', | |||
|
54 | 'status.clean': 'none', | |||
|
55 | 'status.copied': 'none', | |||
|
56 | 'status.deleted': 'cyan bold underline', | |||
|
57 | 'status.ignored': 'black bold', | |||
|
58 | 'status.modified': 'blue bold', | |||
|
59 | 'status.removed': 'red bold', | |||
|
60 | 'status.unknown': 'magenta bold underline', | |||
|
61 | 'tags.normal': 'green', | |||
|
62 | 'tags.local': 'black bold'} |
@@ -167,6 +167,7 b' from __future__ import absolute_import' | |||||
167 | from mercurial.i18n import _ |
|
167 | from mercurial.i18n import _ | |
168 | from mercurial import ( |
|
168 | from mercurial import ( | |
169 | cmdutil, |
|
169 | cmdutil, | |
|
170 | color, | |||
170 | commands, |
|
171 | commands, | |
171 | dispatch, |
|
172 | dispatch, | |
172 | encoding, |
|
173 | encoding, | |
@@ -323,61 +324,6 b' try:' | |||||
323 | except ImportError: |
|
324 | except ImportError: | |
324 | _terminfo_params = {} |
|
325 | _terminfo_params = {} | |
325 |
|
326 | |||
326 | _styles = {'grep.match': 'red bold', |
|
|||
327 | 'grep.linenumber': 'green', |
|
|||
328 | 'grep.rev': 'green', |
|
|||
329 | 'grep.change': 'green', |
|
|||
330 | 'grep.sep': 'cyan', |
|
|||
331 | 'grep.filename': 'magenta', |
|
|||
332 | 'grep.user': 'magenta', |
|
|||
333 | 'grep.date': 'magenta', |
|
|||
334 | 'bookmarks.active': 'green', |
|
|||
335 | 'branches.active': 'none', |
|
|||
336 | 'branches.closed': 'black bold', |
|
|||
337 | 'branches.current': 'green', |
|
|||
338 | 'branches.inactive': 'none', |
|
|||
339 | 'diff.changed': 'white', |
|
|||
340 | 'diff.deleted': 'red', |
|
|||
341 | 'diff.diffline': 'bold', |
|
|||
342 | 'diff.extended': 'cyan bold', |
|
|||
343 | 'diff.file_a': 'red bold', |
|
|||
344 | 'diff.file_b': 'green bold', |
|
|||
345 | 'diff.hunk': 'magenta', |
|
|||
346 | 'diff.inserted': 'green', |
|
|||
347 | 'diff.tab': '', |
|
|||
348 | 'diff.trailingwhitespace': 'bold red_background', |
|
|||
349 | 'changeset.public' : '', |
|
|||
350 | 'changeset.draft' : '', |
|
|||
351 | 'changeset.secret' : '', |
|
|||
352 | 'diffstat.deleted': 'red', |
|
|||
353 | 'diffstat.inserted': 'green', |
|
|||
354 | 'histedit.remaining': 'red bold', |
|
|||
355 | 'ui.prompt': 'yellow', |
|
|||
356 | 'log.changeset': 'yellow', |
|
|||
357 | 'patchbomb.finalsummary': '', |
|
|||
358 | 'patchbomb.from': 'magenta', |
|
|||
359 | 'patchbomb.to': 'cyan', |
|
|||
360 | 'patchbomb.subject': 'green', |
|
|||
361 | 'patchbomb.diffstats': '', |
|
|||
362 | 'rebase.rebased': 'blue', |
|
|||
363 | 'rebase.remaining': 'red bold', |
|
|||
364 | 'resolve.resolved': 'green bold', |
|
|||
365 | 'resolve.unresolved': 'red bold', |
|
|||
366 | 'shelve.age': 'cyan', |
|
|||
367 | 'shelve.newest': 'green bold', |
|
|||
368 | 'shelve.name': 'blue bold', |
|
|||
369 | 'status.added': 'green bold', |
|
|||
370 | 'status.clean': 'none', |
|
|||
371 | 'status.copied': 'none', |
|
|||
372 | 'status.deleted': 'cyan bold underline', |
|
|||
373 | 'status.ignored': 'black bold', |
|
|||
374 | 'status.modified': 'blue bold', |
|
|||
375 | 'status.removed': 'red bold', |
|
|||
376 | 'status.unknown': 'magenta bold underline', |
|
|||
377 | 'tags.normal': 'green', |
|
|||
378 | 'tags.local': 'black bold'} |
|
|||
379 |
|
||||
380 |
|
||||
381 | def _effect_str(effect): |
|
327 | def _effect_str(effect): | |
382 | '''Helper function for render_effects().''' |
|
328 | '''Helper function for render_effects().''' | |
383 |
|
329 | |||
@@ -415,7 +361,7 b' def render_effects(text, effects):' | |||||
415 |
|
361 | |||
416 | def extstyles(): |
|
362 | def extstyles(): | |
417 | for name, ext in extensions.extensions(): |
|
363 | for name, ext in extensions.extensions(): | |
418 | _styles.update(getattr(ext, 'colortable', {})) |
|
364 | color._styles.update(getattr(ext, 'colortable', {})) | |
419 |
|
365 | |||
420 | def valideffect(effect): |
|
366 | def valideffect(effect): | |
421 | 'Determine if the effect is valid or not.' |
|
367 | 'Determine if the effect is valid or not.' | |
@@ -440,7 +386,7 b' def configstyles(ui):' | |||||
440 | ui.warn(_("ignoring unknown color/effect %r " |
|
386 | ui.warn(_("ignoring unknown color/effect %r " | |
441 | "(configured in color.%s)\n") |
|
387 | "(configured in color.%s)\n") | |
442 | % (e, status)) |
|
388 | % (e, status)) | |
443 | _styles[status] = ' '.join(good) |
|
389 | color._styles[status] = ' '.join(good) | |
444 |
|
390 | |||
445 | class colorui(uimod.ui): |
|
391 | class colorui(uimod.ui): | |
446 | _colormode = 'ansi' |
|
392 | _colormode = 'ansi' | |
@@ -493,7 +439,7 b' class colorui(uimod.ui):' | |||||
493 |
|
439 | |||
494 | effects = [] |
|
440 | effects = [] | |
495 | for l in label.split(): |
|
441 | for l in label.split(): | |
496 | s = _styles.get(l, '') |
|
442 | s = color._styles.get(l, '') | |
497 | if s: |
|
443 | if s: | |
498 | effects.append(s) |
|
444 | effects.append(s) | |
499 | elif valideffect(l): |
|
445 | elif valideffect(l): | |
@@ -546,31 +492,31 b' def debugcolor(ui, repo, **opts):' | |||||
546 | return _debugdisplaycolor(ui) |
|
492 | return _debugdisplaycolor(ui) | |
547 |
|
493 | |||
548 | def _debugdisplaycolor(ui): |
|
494 | def _debugdisplaycolor(ui): | |
549 | oldstyle = _styles.copy() |
|
495 | oldstyle = color._styles.copy() | |
550 | try: |
|
496 | try: | |
551 | _styles.clear() |
|
497 | color._styles.clear() | |
552 | for effect in _effects.keys(): |
|
498 | for effect in _effects.keys(): | |
553 | _styles[effect] = effect |
|
499 | color._styles[effect] = effect | |
554 | if _terminfo_params: |
|
500 | if _terminfo_params: | |
555 | for k, v in ui.configitems('color'): |
|
501 | for k, v in ui.configitems('color'): | |
556 | if k.startswith('color.'): |
|
502 | if k.startswith('color.'): | |
557 | _styles[k] = k[6:] |
|
503 | color._styles[k] = k[6:] | |
558 | elif k.startswith('terminfo.'): |
|
504 | elif k.startswith('terminfo.'): | |
559 | _styles[k] = k[9:] |
|
505 | color._styles[k] = k[9:] | |
560 | ui.write(_('available colors:\n')) |
|
506 | ui.write(_('available colors:\n')) | |
561 | # sort label with a '_' after the other to group '_background' entry. |
|
507 | # sort label with a '_' after the other to group '_background' entry. | |
562 | items = sorted(_styles.items(), |
|
508 | items = sorted(color._styles.items(), | |
563 | key=lambda i: ('_' in i[0], i[0], i[1])) |
|
509 | key=lambda i: ('_' in i[0], i[0], i[1])) | |
564 | for colorname, label in items: |
|
510 | for colorname, label in items: | |
565 | ui.write(('%s\n') % colorname, label=label) |
|
511 | ui.write(('%s\n') % colorname, label=label) | |
566 | finally: |
|
512 | finally: | |
567 | _styles.clear() |
|
513 | color._styles.clear() | |
568 | _styles.update(oldstyle) |
|
514 | color._styles.update(oldstyle) | |
569 |
|
515 | |||
570 | def _debugdisplaystyle(ui): |
|
516 | def _debugdisplaystyle(ui): | |
571 | ui.write(_('available style:\n')) |
|
517 | ui.write(_('available style:\n')) | |
572 | width = max(len(s) for s in _styles) |
|
518 | width = max(len(s) for s in color._styles) | |
573 | for label, effects in sorted(_styles.items()): |
|
519 | for label, effects in sorted(color._styles.items()): | |
574 | ui.write('%s' % label, label=label) |
|
520 | ui.write('%s' % label, label=label) | |
575 | if effects: |
|
521 | if effects: | |
576 | # 50 |
|
522 | # 50 | |
@@ -687,7 +633,7 b' else:' | |||||
687 |
|
633 | |||
688 | # determine console attributes based on labels |
|
634 | # determine console attributes based on labels | |
689 | for l in label.split(): |
|
635 | for l in label.split(): | |
690 | style = _styles.get(l, '') |
|
636 | style = color._styles.get(l, '') | |
691 | for effect in style.split(): |
|
637 | for effect in style.split(): | |
692 | try: |
|
638 | try: | |
693 | attr = mapcolor(w32effects[effect], attr) |
|
639 | attr = mapcolor(w32effects[effect], attr) |
General Comments 0
You need to be logged in to leave comments.
Login now