Show More
@@ -74,7 +74,7 b" Any value other than 'ansi', 'win32', or" | |||
|
74 | 74 | |
|
75 | 75 | import os, sys |
|
76 | 76 | |
|
77 | from mercurial import commands, dispatch, extensions | |
|
77 | from mercurial import commands, dispatch, extensions, ui as uimod | |
|
78 | 78 | from mercurial.i18n import _ |
|
79 | 79 | |
|
80 | 80 | # start and stop parameters for effects |
@@ -140,49 +140,50 b' def configstyles(ui):' | |||
|
140 | 140 | % (e, status)) |
|
141 | 141 | _styles[status] = ' '.join(good) |
|
142 | 142 | |
|
143 | _buffers = None | |
|
144 | def style(msg, label): | |
|
145 | effects = [] | |
|
146 | for l in label.split(): | |
|
147 | s = _styles.get(l, '') | |
|
148 | if s: | |
|
149 | effects.append(s) | |
|
150 | effects = ''.join(effects) | |
|
151 | if effects: | |
|
152 | return '\n'.join([render_effects(s, effects) | |
|
153 | for s in msg.split('\n')]) | |
|
154 | return msg | |
|
143 | class colorui(uimod.ui): | |
|
144 | def popbuffer(self, labeled=False): | |
|
145 | if labeled: | |
|
146 | return ''.join(self.label(a, label) for a, label | |
|
147 | in self._buffers.pop()) | |
|
148 | return ''.join(a for a, label in self._buffers.pop()) | |
|
155 | 149 | |
|
156 | def popbuffer(orig, labeled=False): | |
|
157 | global _buffers | |
|
158 | if labeled: | |
|
159 | return ''.join(style(a, label) for a, label in _buffers.pop()) | |
|
160 | return ''.join(a for a, label in _buffers.pop()) | |
|
150 | _colormode = 'ansi' | |
|
151 | def write(self, *args, **opts): | |
|
152 | label = opts.get('label', '') | |
|
153 | if self._buffers: | |
|
154 | self._buffers[-1].extend([(str(a), label) for a in args]) | |
|
155 | elif self._colormode == 'win32': | |
|
156 | for a in args: | |
|
157 | win32print(a, orig, **opts) | |
|
158 | else: | |
|
159 | return super(colorui, self).write( | |
|
160 | *[self.label(str(a), label) for a in args], **opts) | |
|
161 | 161 | |
|
162 | mode = 'ansi' | |
|
163 | def write(orig, *args, **opts): | |
|
164 | label = opts.get('label', '') | |
|
165 | global _buffers | |
|
166 | if _buffers: | |
|
167 | _buffers[-1].extend([(str(a), label) for a in args]) | |
|
168 | elif mode == 'win32': | |
|
169 | for a in args: | |
|
170 | win32print(a, orig, **opts) | |
|
171 | else: | |
|
172 | return orig(*[style(str(a), label) for a in args], **opts) | |
|
162 | def write_err(self, *args, **opts): | |
|
163 | label = opts.get('label', '') | |
|
164 | if self._colormode == 'win32': | |
|
165 | for a in args: | |
|
166 | win32print(a, orig, **opts) | |
|
167 | else: | |
|
168 | return super(colorui, self).write( | |
|
169 | *[self.label(str(a), label) for a in args], **opts) | |
|
173 | 170 | |
|
174 | def write_err(orig, *args, **opts): | |
|
175 | label = opts.get('label', '') | |
|
176 | if mode == 'win32': | |
|
177 | for a in args: | |
|
178 | win32print(a, orig, **opts) | |
|
179 | else: | |
|
180 | return orig(*[style(str(a), label) for a in args], **opts) | |
|
171 | def label(self, msg, label): | |
|
172 | effects = [] | |
|
173 | for l in label.split(): | |
|
174 | s = _styles.get(l, '') | |
|
175 | if s: | |
|
176 | effects.append(s) | |
|
177 | effects = ''.join(effects) | |
|
178 | if effects: | |
|
179 | return '\n'.join([render_effects(s, effects) | |
|
180 | for s in msg.split('\n')]) | |
|
181 | return msg | |
|
182 | ||
|
181 | 183 | |
|
182 | 184 | def uisetup(ui): |
|
183 | 185 | if ui.plain(): |
|
184 | 186 | return |
|
185 | global mode | |
|
186 | 187 | mode = ui.config('color', 'mode', 'auto') |
|
187 | 188 | if mode == 'auto': |
|
188 | 189 | if os.name == 'nt' and 'TERM' not in os.environ: |
@@ -202,14 +203,11 b' def uisetup(ui):' | |||
|
202 | 203 | if (opts['color'] == 'always' or |
|
203 | 204 | (opts['color'] == 'auto' and (os.environ.get('TERM') != 'dumb' |
|
204 | 205 | and ui_.formatted()))): |
|
205 | global _buffers | |
|
206 |
|
|
|
207 | extensions.wrapfunction(ui_, 'popbuffer', popbuffer) | |
|
208 | extensions.wrapfunction(ui_, 'write', write) | |
|
209 | extensions.wrapfunction(ui_, 'write_err', write_err) | |
|
210 | ui_.label = style | |
|
206 | colorui._colormode = mode | |
|
207 | colorui.__bases__ = (ui_.__class__,) | |
|
208 | ui_.__class__ = colorui | |
|
211 | 209 | extstyles() |
|
212 | configstyles(ui) | |
|
210 | configstyles(ui_) | |
|
213 | 211 | return orig(ui_, opts, cmd, cmdfunc) |
|
214 | 212 | extensions.wrapfunction(dispatch, '_runcommand', colorcmd) |
|
215 | 213 |
@@ -45,7 +45,6 b' num characters, or ``+<num>`` for the fi' | |||
|
45 | 45 | import sys |
|
46 | 46 | import time |
|
47 | 47 | |
|
48 | from mercurial import extensions | |
|
49 | 48 | from mercurial import util |
|
50 | 49 | |
|
51 | 50 | def spacejoin(*args): |
@@ -159,7 +158,7 b' class progbar(object):' | |||
|
159 | 158 | tw = util.termwidth() |
|
160 | 159 | return min(int(self.ui.config('progress', 'width', default=tw)), tw) |
|
161 | 160 | |
|
162 |
def progress(self |
|
|
161 | def progress(self, topic, pos, item='', unit='', total=None): | |
|
163 | 162 | if pos is None: |
|
164 | 163 | if self.topics and self.topics[-1] == topic and self.printed: |
|
165 | 164 | self.complete() |
@@ -172,29 +171,35 b' class progbar(object):' | |||
|
172 | 171 | and topic == self.topics[-1]): |
|
173 | 172 | self.lastprint = now |
|
174 | 173 | self.show(topic, pos, item, unit, total) |
|
175 | return orig(topic, pos, item=item, unit=unit, total=total) | |
|
176 | ||
|
177 | def write(self, orig, *args, **opts): | |
|
178 | if self.printed: | |
|
179 | self.clear() | |
|
180 | return orig(*args, **opts) | |
|
181 | ||
|
182 | sharedprog = None | |
|
183 | 174 | |
|
184 | 175 | def uisetup(ui): |
|
176 | class progressui(ui.__class__): | |
|
177 | _progbar = None | |
|
178 | ||
|
179 | def progress(self, *args, **opts): | |
|
180 | self._progbar.progress(*args, **opts) | |
|
181 | return super(progressui, self).progress(*args, **opts) | |
|
182 | ||
|
183 | def write(self, *args, **opts): | |
|
184 | if self._progbar.printed: | |
|
185 | self._progbar.clear() | |
|
186 | return super(progressui, self).write(*args, **opts) | |
|
187 | ||
|
188 | def write_err(self, *args, **opts): | |
|
189 | if self._progbar.printed: | |
|
190 | self._progbar.clear() | |
|
191 | return super(progressui, self).write_err(*args, **opts) | |
|
192 | ||
|
185 | 193 | # Apps that derive a class from ui.ui() can use |
|
186 | 194 | # setconfig('progress', 'disable', 'True') to disable this extension |
|
187 | 195 | if ui.configbool('progress', 'disable'): |
|
188 | 196 | return |
|
189 | 197 | if shouldprint(ui) and not ui.debugflag and not ui.quiet: |
|
198 | ui.__class__ = progressui | |
|
190 | 199 | # we instantiate one globally shared progress bar to avoid |
|
191 | 200 | # competing progress bars when multiple UI objects get created |
|
192 | global sharedprog | |
|
193 | if not sharedprog: | |
|
194 | sharedprog = progbar(ui) | |
|
195 | extensions.wrapfunction(ui, 'progress', sharedprog.progress) | |
|
196 | extensions.wrapfunction(ui, 'write', sharedprog.write) | |
|
197 | extensions.wrapfunction(ui, 'write_err', sharedprog.write) | |
|
201 | if not progressui._progbar: | |
|
202 | progressui._progbar = progbar(ui) | |
|
198 | 203 | |
|
199 | 204 | def reposetup(ui, repo): |
|
200 | 205 | uisetup(repo.ui) |
@@ -398,6 +398,8 b' def _dispatch(ui, args):' | |||
|
398 | 398 | # times so we keep track of configured extensions in _loaded. |
|
399 | 399 | extensions.loadall(lui) |
|
400 | 400 | exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded] |
|
401 | # Propagate any changes to lui.__class__ by extensions | |
|
402 | ui.__class__ = lui.__class__ | |
|
401 | 403 | |
|
402 | 404 | # (uisetup and extsetup are handled in extensions.loadall) |
|
403 | 405 |
@@ -80,6 +80,9 b" echo ' .hgignore:'" | |||
|
80 | 80 | cat .hg/patches/.hgignore |
|
81 | 81 | echo ' series:' |
|
82 | 82 | cat .hg/patches/series |
|
83 | ||
|
84 | echo '% status --mq with color (issue2096)' | |
|
85 | hg status --mq --config extensions.color= --color=always | |
|
83 | 86 | cd .. |
|
84 | 87 | |
|
85 | 88 | echo '% init --mq without repo' |
@@ -93,6 +93,11 b' bleh' | |||
|
93 | 93 | series: |
|
94 | 94 | A |
|
95 | 95 | B |
|
96 | % status --mq with color (issue2096) | |
|
97 | [0;32;1mA .hgignore[0m | |
|
98 | [0;32;1mA A[0m | |
|
99 | [0;32;1mA B[0m | |
|
100 | [0;32;1mA series[0m | |
|
96 | 101 | % init --mq without repo |
|
97 | 102 | abort: There is no Mercurial repository here (.hg not found) |
|
98 | 103 | % init --mq with repo path |
General Comments 0
You need to be logged in to leave comments.
Login now