hgext/color.py
changeset 10046 0c23b0b3516b
parent 10045 d1f9640e9a67
child 10222 98f630e15d82
--- 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):