diff hgext/churn.py @ 11302:e1dde7363601

color: labeled text should be passed to ui.write() as ui.labeled Some implementations of ui.label() (HTML versions in particular) must escape the provided text and then markup the text with their tags. When this marked up text is then passed to ui.write(), we must label the text as 'ui.labeled' so the implementation knows not to escape it a second time (exposing the initial markup). This required the addition of a 'ui.plain' label for text that is purposefully not marked up. I was a little pedantic here, passing even ' ' strings to ui.label() when it would be included with other labeled text in a ui.write() call. But it seemed appropriate to lean to the side of caution.
author Steve Borho <steve@borho.org>
date Thu, 03 Jun 2010 23:18:18 -0500
parents ffd85ab578be
children ac873ecfc3c2
line wrap: on
line diff
--- a/hgext/churn.py	Mon Jun 07 18:35:54 2010 +0200
+++ b/hgext/churn.py	Thu Jun 03 23:18:18 2010 -0500
@@ -150,8 +150,10 @@
     if opts.get('diffstat'):
         width -= 15
         def format(name, (added, removed)):
-            return "%s %15s %s%s\n" % (pad(name, maxname),
-                                       '+%d/-%d' % (added, removed),
+            return "%s %15s %s%s\n" % (ui.label(pad(name, maxname),
+                                                'ui.plain'),
+                                       ui.label('+%d/-%d' % (added, removed),
+                                                'ui.plain'),
                                        ui.label('+' * charnum(added),
                                                 'diffstat.inserted'),
                                        ui.label('-' * charnum(removed),
@@ -159,14 +161,14 @@
     else:
         width -= 6
         def format(name, count):
-            return "%s %6d %s\n" % (pad(name, maxname), sum(count),
-                                    '*' * charnum(sum(count)))
+            return ui.label("%s %6d %s\n" % (pad(name, maxname), sum(count),
+                            '*' * charnum(sum(count))), 'ui.plain')
 
     def charnum(count):
         return int(round(count * width / maxcount))
 
     for name, count in rate:
-        ui.write(format(name, count))
+        ui.write(format(name, count), label='ui.labeled')
 
 
 cmdtable = {