[PATCH] color: Add support for bookmarks

David Soria Parra sn_ at gmx.net
Tue Dec 8 16:40:05 CST 2009


 hgext/color.py |  22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)


# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1260311948 -3600
# Node ID 0d3e548ec45d37cf8c9aa519c4813bfcb0c5320b
# Parent  4b773fcc8969ca20e32bd3ce824e95aaeff7c795
color: Add support for bookmarks

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -138,6 +138,21 @@
                     'clean': ['none'],
                     'copied': ['none'], }
 
+_bookmark_effects = { 'current': ['green'] }
+
+def colorbookmarks(orig, ui, repo, *pats, **opts):
+    def colorize(orig, s):
+        lines = s.split('\n')
+        for i, line in enumerate(lines):
+            if line.startswith(" *"):
+                lines[i] = render_effects(line, _bookmark_effects['current'])
+        orig('\n'.join(lines))
+    oldwrite = extensions.wrapfunction(ui, 'write', colorize)
+    try:
+        orig(ui, repo, *pats, **opts)
+    finally:
+        ui.write = oldwrite
+
 def colorqseries(orig, ui, repo, *dummy, **opts):
     '''run the qseries command with colored output'''
     ui.pushbuffer()
@@ -235,6 +250,13 @@
         # The mq extension is not enabled
         pass
 
+    try:
+        bookmarks = extensions.find('bookmarks')
+        _setupcmd(ui, 'bookmarks', bookmarks.cmdtable, colorbookmarks, _bookmark_effects)
+    except KeyError:
+        # The bookmarks extension is not enabled
+        pass
+
 def _setupcmd(ui, cmd, table, func, effectsmap):
     '''patch in command to command table and load effect map'''
     def nocolor(orig, *args, **opts):


More information about the Mercurial-devel mailing list