[PATCH 2 of 4] color: stop mutating the default effects map

Yuya Nishihara yuya at tcha.org
Mon Mar 27 10:39:33 EDT 2017


On Mon, 27 Mar 2017 14:41:46 +0200, Pierre-Yves David wrote:
> On 03/26/2017 04:35 PM, Yuya Nishihara wrote:
> > On Sun, 26 Mar 2017 00:41:05 -0400, Matt Harbison wrote:
> >> # HG changeset patch
> >> # User Matt Harbison <matt_harbison at yahoo.com>
> >> # Date 1490464217 14400
> >> #      Sat Mar 25 13:50:17 2017 -0400
> >> # Node ID a263702b064a5a3ce1ca74b227e8e624e4b05874
> >> # Parent  22533c3af63d5a67d9210596eafd4b99ab9c7904
> >> color: stop mutating the default effects map
> >
> > I re-read the code, and noticed that both _effects and w32effects are mostly
> > constants. Perhaps we can simply switch them by ui._colormode.
> >
> >   if ui._colormode == 'win32':
> >       activeeffects = w32neffects
> >   else:
> >       activeeffects = _effects
> >   ... embed escape sequences by using activeeffects ...
> 
> Ultimately, yes we want to be there, but I remember other things muding
> with the effects dict so someone would have to give a close look to the 
> current magic before moving forward.

Maybe that is debugcolor (and w32effects.)

% grep _effects  **/*.py
mercurial/color.py:_effects = {
mercurial/color.py:        _effects.update(w32effects)
mercurial/color.py:    return ((not ui._terminfoparams and effect in _effects)
mercurial/color.py:    '''Helper function for render_effects().'''
mercurial/color.py:def _render_effects(ui, text, effects):
mercurial/color.py:        start = [str(_effects[e]) for e in ['none'] + effects.split()]
mercurial/color.py:        stop = '\033[' + str(_effects['none']) + 'm'
mercurial/color.py:            msg = '\n'.join([_render_effects(ui, line, effects)
mercurial/debugcommands.py:    for effect in color._effects.keys():


More information about the Mercurial-devel mailing list