##// END OF EJS Templates
color: move the 'colorlabel' function in the core module...
Pierre-Yves David -
r31086:e6082078 default
parent child Browse files
Show More
@@ -331,29 +331,7 b' class colorui(uimod.ui):'
331 def label(self, msg, label):
331 def label(self, msg, label):
332 if self._colormode is None:
332 if self._colormode is None:
333 return super(colorui, self).label(msg, label)
333 return super(colorui, self).label(msg, label)
334 return colorlabel(self, msg, label)
334 return color.colorlabel(self, msg, label)
335
336 def colorlabel(ui, msg, label):
337 """add color control code according to the mode"""
338 if ui._colormode == 'debug':
339 if label and msg:
340 if msg[-1] == '\n':
341 msg = "[%s|%s]\n" % (label, msg[:-1])
342 else:
343 msg = "[%s|%s]" % (label, msg)
344 elif ui._colormode is not None:
345 effects = []
346 for l in label.split():
347 s = color._styles.get(l, '')
348 if s:
349 effects.append(s)
350 elif color.valideffect(l):
351 effects.append(l)
352 effects = ' '.join(effects)
353 if effects:
354 msg = '\n'.join([color._render_effects(line, effects)
355 for line in msg.split('\n')])
356 return msg
357
335
358 def uisetup(ui):
336 def uisetup(ui):
359 if ui.plain():
337 if ui.plain():
@@ -175,6 +175,28 b' def _render_effects(text, effects):'
175 stop = '\033[' + str(_effects['none']) + 'm'
175 stop = '\033[' + str(_effects['none']) + 'm'
176 return ''.join([start, text, stop])
176 return ''.join([start, text, stop])
177
177
178 def colorlabel(ui, msg, label):
179 """add color control code according to the mode"""
180 if ui._colormode == 'debug':
181 if label and msg:
182 if msg[-1] == '\n':
183 msg = "[%s|%s]\n" % (label, msg[:-1])
184 else:
185 msg = "[%s|%s]" % (label, msg)
186 elif ui._colormode is not None:
187 effects = []
188 for l in label.split():
189 s = _styles.get(l, '')
190 if s:
191 effects.append(s)
192 elif valideffect(l):
193 effects.append(l)
194 effects = ' '.join(effects)
195 if effects:
196 msg = '\n'.join([_render_effects(line, effects)
197 for line in msg.split('\n')])
198 return msg
199
178 w32effects = None
200 w32effects = None
179 if pycompat.osname == 'nt':
201 if pycompat.osname == 'nt':
180 import ctypes
202 import ctypes
General Comments 0
You need to be logged in to leave comments. Login now