Mercurial > hg
comparison hgext/color.py @ 19072:b7b50a54bec9 stable
color: turn colorui functions into forwards when color is None
colorui will be set to None as necessary in an upcoming patch.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Fri, 19 Apr 2013 16:57:20 -0700 |
parents | 7ae12ce87594 |
children | d78d0256198e |
comparison
equal
deleted
inserted
replaced
19071:64ea454e7d76 | 19072:b7b50a54bec9 |
---|---|
315 % (e, status)) | 315 % (e, status)) |
316 _styles[status] = ' '.join(good) | 316 _styles[status] = ' '.join(good) |
317 | 317 |
318 class colorui(uimod.ui): | 318 class colorui(uimod.ui): |
319 def popbuffer(self, labeled=False): | 319 def popbuffer(self, labeled=False): |
320 if self._colormode is None: | |
321 return super(colorui, self).popbuffer(labeled) | |
322 | |
320 if labeled: | 323 if labeled: |
321 return ''.join(self.label(a, label) for a, label | 324 return ''.join(self.label(a, label) for a, label |
322 in self._buffers.pop()) | 325 in self._buffers.pop()) |
323 return ''.join(a for a, label in self._buffers.pop()) | 326 return ''.join(a for a, label in self._buffers.pop()) |
324 | 327 |
325 _colormode = 'ansi' | 328 _colormode = 'ansi' |
326 def write(self, *args, **opts): | 329 def write(self, *args, **opts): |
330 if self._colormode is None: | |
331 return super(colorui, self).write(*args, **opts) | |
332 | |
327 label = opts.get('label', '') | 333 label = opts.get('label', '') |
328 if self._buffers: | 334 if self._buffers: |
329 self._buffers[-1].extend([(str(a), label) for a in args]) | 335 self._buffers[-1].extend([(str(a), label) for a in args]) |
330 elif self._colormode == 'win32': | 336 elif self._colormode == 'win32': |
331 for a in args: | 337 for a in args: |
333 else: | 339 else: |
334 return super(colorui, self).write( | 340 return super(colorui, self).write( |
335 *[self.label(str(a), label) for a in args], **opts) | 341 *[self.label(str(a), label) for a in args], **opts) |
336 | 342 |
337 def write_err(self, *args, **opts): | 343 def write_err(self, *args, **opts): |
344 if self._colormode is None: | |
345 return super(colorui, self).write_err(*args, **opts) | |
346 | |
338 label = opts.get('label', '') | 347 label = opts.get('label', '') |
339 if self._colormode == 'win32': | 348 if self._colormode == 'win32': |
340 for a in args: | 349 for a in args: |
341 win32print(a, super(colorui, self).write_err, **opts) | 350 win32print(a, super(colorui, self).write_err, **opts) |
342 else: | 351 else: |
343 return super(colorui, self).write_err( | 352 return super(colorui, self).write_err( |
344 *[self.label(str(a), label) for a in args], **opts) | 353 *[self.label(str(a), label) for a in args], **opts) |
345 | 354 |
346 def label(self, msg, label): | 355 def label(self, msg, label): |
356 if self._colormode is None: | |
357 return super(colorui, self).label(msg, label) | |
358 | |
347 effects = [] | 359 effects = [] |
348 for l in label.split(): | 360 for l in label.split(): |
349 s = _styles.get(l, '') | 361 s = _styles.get(l, '') |
350 if s: | 362 if s: |
351 effects.append(s) | 363 effects.append(s) |