color: Add support for bookmarks
authorDavid Soria Parra <dsp@php.net>
Fri, 11 Dec 2009 11:04:31 +0100
changeset 10046 0c23b0b3516b
parent 10045 d1f9640e9a67
child 10049 5b9709f81986
color: Add support for bookmarks
hgext/color.py
--- a/hgext/color.py	Fri Dec 11 11:04:31 2009 +0100
+++ b/hgext/color.py	Fri Dec 11 11:04:31 2009 +0100
@@ -56,6 +56,8 @@
   diff.inserted = green
   diff.changed = white
   diff.trailingwhitespace = bold red_background
+
+  bookmarks.current = green
 '''
 
 import os, sys
@@ -138,6 +140,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()
@@ -275,6 +292,14 @@
     except KeyError:
         churn = None
 
+    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):