##// END OF EJS Templates
color: add --color switch...
Brodie Rao -
r7455:c9fd5474 default
parent child Browse files
Show More
@@ -49,7 +49,7 b' qseries.unapplied = black bold'
49 49 qseries.missing = red bold
50 50 '''
51 51
52 import re, sys
52 import os, re, sys
53 53
54 54 from mercurial import commands, extensions
55 55 from mercurial.i18n import _
@@ -113,7 +113,7 b' def colorstatus(orig, ui, repo, *pats, *'
113 113 effects = _status_effects[status]
114 114 if effects:
115 115 lines[i] = render_effects(lines[i], *effects)
116 sys.stdout.write(lines[i] + delimiter)
116 ui.write(lines[i] + delimiter)
117 117 return retval
118 118
119 119 _status_abbreviations = { 'M': 'modified',
@@ -154,7 +154,7 b' def colorqseries(orig, ui, repo, *dummy,'
154 154 effects = _patch_effects['applied']
155 155 else:
156 156 effects = _patch_effects['unapplied']
157 sys.stdout.write(render_effects(patch, *effects) + '\n')
157 ui.write(render_effects(patch, *effects) + '\n')
158 158 return retval
159 159
160 160 _patch_effects = { 'applied': ('blue', 'bold', 'underline'),
@@ -171,13 +171,22 b' def uisetup(ui):'
171 171
172 172 def _setupcmd(ui, cmd, table, func, effectsmap):
173 173 '''patch in command to command table and load effect map'''
174 def nocolor(orig, *args, **kwargs):
175 if kwargs['no_color']:
176 return orig(*args, **kwargs)
177 return func(orig, *args, **kwargs)
174 def nocolor(orig, *args, **opts):
175
176 if (opts['no_color'] or opts['color'] == 'never' or
177 (opts['color'] == 'auto' and (os.environ.get('TERM') == 'dumb'
178 or not sys.__stdout__.isatty()))):
179 return orig(*args, **opts)
180
181 if func is not None:
182 return func(orig, *args, **opts)
183 return orig(*args, **opts)
178 184
179 185 entry = extensions.wrapcommand(table, cmd, nocolor)
180 entry[1].append(('', 'no-color', None, _("don't colorize output")))
186 entry[1].extend([
187 ('', 'color', 'auto', _("when to colorize (always, auto, or never)")),
188 ('', 'no-color', None, _("don't colorize output")),
189 ])
181 190
182 191 for status in effectsmap:
183 192 effects = ui.config('color', cmd + '.' + status)
General Comments 0
You need to be logged in to leave comments. Login now