Mercurial > public > mercurial-scm > hg
diff mercurial/debugcommands.py @ 31120:c4e8fa2b1c40
color: move 'debugcolor' into the 'debugcommands' modules
This is the last bits we needed to move out of the extensions. 'hgext/color.py'
now only contains logic to changes the default color behavior to 'auto'.
However, more cleanups are on the way and we need to document the new config
directly in core.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Tue, 21 Feb 2017 18:41:37 +0100 |
parents | 2912b06905dc |
children | 8fc55bbd2235 |
line wrap: on
line diff
--- a/mercurial/debugcommands.py Tue Feb 28 11:13:25 2017 -0800 +++ b/mercurial/debugcommands.py Tue Feb 21 18:41:37 2017 +0100 @@ -31,6 +31,7 @@ bundle2, changegroup, cmdutil, + color, commands, context, dagparser, @@ -344,6 +345,51 @@ error = _(".hg/dirstate inconsistent with current parent's manifest") raise error.Abort(error) +@command('debugcolor', + [('', 'style', None, _('show all configured styles'))], + 'hg debugcolor') +def debugcolor(ui, repo, **opts): + """show available color, effects or style""" + ui.write(('color mode: %s\n') % ui._colormode) + if opts.get('style'): + return _debugdisplaystyle(ui) + else: + return _debugdisplaycolor(ui) + +def _debugdisplaycolor(ui): + oldstyle = ui._styles.copy() + try: + ui._styles.clear() + for effect in color._effects.keys(): + ui._styles[effect] = effect + if ui._terminfoparams: + for k, v in ui.configitems('color'): + if k.startswith('color.'): + ui._styles[k] = k[6:] + elif k.startswith('terminfo.'): + ui._styles[k] = k[9:] + ui.write(_('available colors:\n')) + # sort label with a '_' after the other to group '_background' entry. + items = sorted(ui._styles.items(), + key=lambda i: ('_' in i[0], i[0], i[1])) + for colorname, label in items: + ui.write(('%s\n') % colorname, label=label) + finally: + ui._styles.clear() + ui._styles.update(oldstyle) + +def _debugdisplaystyle(ui): + ui.write(_('available style:\n')) + width = max(len(s) for s in ui._styles) + for label, effects in sorted(ui._styles.items()): + ui.write('%s' % label, label=label) + if effects: + # 50 + ui.write(': ') + ui.write(' ' * (max(0, width - len(label)))) + ui.write(', '.join(ui.label(e, e) for e in effects.split())) + ui.write('\n') + @command('debugcommands', [], _('[COMMAND]'), norepo=True) def debugcommands(ui, cmd='', *args): """list all available commands and options"""