comparison hgext/color.py @ 31084:1482b57701ad

color: inline the 'showlabel' method This function is quite simple and only have one call siteā€¦ located a handful of line under the definition. We inline the function for the sake of simplicity. One of the motivation to do that now is that it reduce the amount of new method we will have to add to the core 'ui' class for color support.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Mon, 20 Feb 2017 12:13:23 +0100
parents c42feb5f3143
children 3422de9b657e
comparison
equal deleted inserted replaced
31083:c42feb5f3143 31084:1482b57701ad
326 color.win32print(a, super(colorui, self).write_err, **opts) 326 color.win32print(a, super(colorui, self).write_err, **opts)
327 else: 327 else:
328 return super(colorui, self).write_err( 328 return super(colorui, self).write_err(
329 *[self.label(a, label) for a in args], **opts) 329 *[self.label(a, label) for a in args], **opts)
330 330
331 def showlabel(self, msg, label):
332 if label and msg:
333 if msg[-1] == '\n':
334 return "[%s|%s]\n" % (label, msg[:-1])
335 else:
336 return "[%s|%s]" % (label, msg)
337 else:
338 return msg
339
340 def label(self, msg, label): 331 def label(self, msg, label):
341 if self._colormode is None: 332 if self._colormode is None:
342 return super(colorui, self).label(msg, label) 333 return super(colorui, self).label(msg, label)
343 334
344 if self._colormode == 'debug': 335 if self._colormode == 'debug':
345 return self.showlabel(msg, label) 336 if label and msg:
337 if msg[-1] == '\n':
338 return "[%s|%s]\n" % (label, msg[:-1])
339 else:
340 return "[%s|%s]" % (label, msg)
341 else:
342 return msg
346 343
347 effects = [] 344 effects = []
348 for l in label.split(): 345 for l in label.split():
349 s = color._styles.get(l, '') 346 s = color._styles.get(l, '')
350 if s: 347 if s: