Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
11301:3d0591a66118 | 11302:e1dde7363601 |
---|---|
148 width = ttywidth - maxname - 2 - 2 - 2 | 148 width = ttywidth - maxname - 2 - 2 - 2 |
149 | 149 |
150 if opts.get('diffstat'): | 150 if opts.get('diffstat'): |
151 width -= 15 | 151 width -= 15 |
152 def format(name, (added, removed)): | 152 def format(name, (added, removed)): |
153 return "%s %15s %s%s\n" % (pad(name, maxname), | 153 return "%s %15s %s%s\n" % (ui.label(pad(name, maxname), |
154 '+%d/-%d' % (added, removed), | 154 'ui.plain'), |
155 ui.label('+%d/-%d' % (added, removed), | |
156 'ui.plain'), | |
155 ui.label('+' * charnum(added), | 157 ui.label('+' * charnum(added), |
156 'diffstat.inserted'), | 158 'diffstat.inserted'), |
157 ui.label('-' * charnum(removed), | 159 ui.label('-' * charnum(removed), |
158 'diffstat.deleted')) | 160 'diffstat.deleted')) |
159 else: | 161 else: |
160 width -= 6 | 162 width -= 6 |
161 def format(name, count): | 163 def format(name, count): |
162 return "%s %6d %s\n" % (pad(name, maxname), sum(count), | 164 return ui.label("%s %6d %s\n" % (pad(name, maxname), sum(count), |
163 '*' * charnum(sum(count))) | 165 '*' * charnum(sum(count))), 'ui.plain') |
164 | 166 |
165 def charnum(count): | 167 def charnum(count): |
166 return int(round(count * width / maxcount)) | 168 return int(round(count * width / maxcount)) |
167 | 169 |
168 for name, count in rate: | 170 for name, count in rate: |
169 ui.write(format(name, count)) | 171 ui.write(format(name, count), label='ui.labeled') |
170 | 172 |
171 | 173 |
172 cmdtable = { | 174 cmdtable = { |
173 "churn": | 175 "churn": |
174 (churn, | 176 (churn, |