Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/debugcommands.py @ 31136:8fc55bbd2235
color: cleanup 'debugcolor' logic
Now that style are carried by the 'ui' object, we no longer need complicated
logic to restore the original style. We just need to copy the 'ui' and work on
the copied version.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Sat, 25 Feb 2017 19:43:14 +0100 |
parents | c4e8fa2b1c40 |
children | 21fa3d3688f3 |
comparison
equal
deleted
inserted
replaced
31135:c4e8fa2b1c40 | 31136:8fc55bbd2235 |
---|---|
355 return _debugdisplaystyle(ui) | 355 return _debugdisplaystyle(ui) |
356 else: | 356 else: |
357 return _debugdisplaycolor(ui) | 357 return _debugdisplaycolor(ui) |
358 | 358 |
359 def _debugdisplaycolor(ui): | 359 def _debugdisplaycolor(ui): |
360 oldstyle = ui._styles.copy() | 360 ui = ui.copy() |
361 try: | 361 ui._styles.clear() |
362 ui._styles.clear() | 362 for effect in color._effects.keys(): |
363 for effect in color._effects.keys(): | 363 ui._styles[effect] = effect |
364 ui._styles[effect] = effect | 364 if ui._terminfoparams: |
365 if ui._terminfoparams: | 365 for k, v in ui.configitems('color'): |
366 for k, v in ui.configitems('color'): | 366 if k.startswith('color.'): |
367 if k.startswith('color.'): | 367 ui._styles[k] = k[6:] |
368 ui._styles[k] = k[6:] | 368 elif k.startswith('terminfo.'): |
369 elif k.startswith('terminfo.'): | 369 ui._styles[k] = k[9:] |
370 ui._styles[k] = k[9:] | 370 ui.write(_('available colors:\n')) |
371 ui.write(_('available colors:\n')) | 371 # sort label with a '_' after the other to group '_background' entry. |
372 # sort label with a '_' after the other to group '_background' entry. | 372 items = sorted(ui._styles.items(), |
373 items = sorted(ui._styles.items(), | 373 key=lambda i: ('_' in i[0], i[0], i[1])) |
374 key=lambda i: ('_' in i[0], i[0], i[1])) | 374 for colorname, label in items: |
375 for colorname, label in items: | 375 ui.write(('%s\n') % colorname, label=label) |
376 ui.write(('%s\n') % colorname, label=label) | |
377 finally: | |
378 ui._styles.clear() | |
379 ui._styles.update(oldstyle) | |
380 | 376 |
381 def _debugdisplaystyle(ui): | 377 def _debugdisplaystyle(ui): |
382 ui.write(_('available style:\n')) | 378 ui.write(_('available style:\n')) |
383 width = max(len(s) for s in ui._styles) | 379 width = max(len(s) for s in ui._styles) |
384 for label, effects in sorted(ui._styles.items()): | 380 for label, effects in sorted(ui._styles.items()): |