Mercurial > hg
comparison hgext/color.py @ 10046:0c23b0b3516b
color: Add support for bookmarks
author | David Soria Parra <dsp@php.net> |
---|---|
date | Fri, 11 Dec 2009 11:04:31 +0100 |
parents | d1f9640e9a67 |
children | 98f630e15d82 |
comparison
equal
deleted
inserted
replaced
10045:d1f9640e9a67 | 10046:0c23b0b3516b |
---|---|
54 diff.hunk = magenta | 54 diff.hunk = magenta |
55 diff.deleted = red | 55 diff.deleted = red |
56 diff.inserted = green | 56 diff.inserted = green |
57 diff.changed = white | 57 diff.changed = white |
58 diff.trailingwhitespace = bold red_background | 58 diff.trailingwhitespace = bold red_background |
59 | |
60 bookmarks.current = green | |
59 ''' | 61 ''' |
60 | 62 |
61 import os, sys | 63 import os, sys |
62 | 64 |
63 from mercurial import cmdutil, commands, extensions, error | 65 from mercurial import cmdutil, commands, extensions, error |
136 'unknown': ['magenta', 'bold', 'underline'], | 138 'unknown': ['magenta', 'bold', 'underline'], |
137 'ignored': ['black', 'bold'], | 139 'ignored': ['black', 'bold'], |
138 'clean': ['none'], | 140 'clean': ['none'], |
139 'copied': ['none'], } | 141 'copied': ['none'], } |
140 | 142 |
143 _bookmark_effects = { 'current': ['green'] } | |
144 | |
145 def colorbookmarks(orig, ui, repo, *pats, **opts): | |
146 def colorize(orig, s): | |
147 lines = s.split('\n') | |
148 for i, line in enumerate(lines): | |
149 if line.startswith(" *"): | |
150 lines[i] = render_effects(line, _bookmark_effects['current']) | |
151 orig('\n'.join(lines)) | |
152 oldwrite = extensions.wrapfunction(ui, 'write', colorize) | |
153 try: | |
154 orig(ui, repo, *pats, **opts) | |
155 finally: | |
156 ui.write = oldwrite | |
157 | |
141 def colorqseries(orig, ui, repo, *dummy, **opts): | 158 def colorqseries(orig, ui, repo, *dummy, **opts): |
142 '''run the qseries command with colored output''' | 159 '''run the qseries command with colored output''' |
143 ui.pushbuffer() | 160 ui.pushbuffer() |
144 retval = orig(ui, repo, **opts) | 161 retval = orig(ui, repo, **opts) |
145 patchlines = ui.popbuffer().splitlines() | 162 patchlines = ui.popbuffer().splitlines() |
273 churn = extensions.find('churn') | 290 churn = extensions.find('churn') |
274 _setupcmd(ui, 'churn', churn.cmdtable, colorchurn, _diff_effects) | 291 _setupcmd(ui, 'churn', churn.cmdtable, colorchurn, _diff_effects) |
275 except KeyError: | 292 except KeyError: |
276 churn = None | 293 churn = None |
277 | 294 |
295 try: | |
296 bookmarks = extensions.find('bookmarks') | |
297 _setupcmd(ui, 'bookmarks', bookmarks.cmdtable, colorbookmarks, | |
298 _bookmark_effects) | |
299 except KeyError: | |
300 # The bookmarks extension is not enabled | |
301 pass | |
302 | |
278 def _setupcmd(ui, cmd, table, func, effectsmap): | 303 def _setupcmd(ui, cmd, table, func, effectsmap): |
279 '''patch in command to command table and load effect map''' | 304 '''patch in command to command table and load effect map''' |
280 def nocolor(orig, *args, **opts): | 305 def nocolor(orig, *args, **opts): |
281 | 306 |
282 if (opts['no_color'] or opts['color'] == 'never' or | 307 if (opts['no_color'] or opts['color'] == 'never' or |