[PATCH] color: add support for terminfo-based attributes and color

Patrick Mézard pmezard at gmail.com
Sat Apr 23 16:42:27 CDT 2011


Le 23/04/11 23:16, Danek Duvall a écrit :
> Patrick Mézard wrote:
> 
>>> +    _terminfo_params.update(dict((
>>> +        (key[6:], (False, int(val)))
>>> +        for key, val in ui.configitems('color')
>>> +        if key.startswith('color.')
>>> +    )))
>>
>> FWIW, the dict and the inner generator are unnecessary.
> 
> Of course; thanks.
> 
>>>  def uisetup(ui):
>>> +    global _terminfo_params
>>>      if ui.plain():
>>>          return
>>>      mode = ui.config('color', 'mode', 'auto')
>>> @@ -199,14 +308,22 @@ def uisetup(ui):
>>>              # looks line a cmd.exe console, use win32 API or nothing
>>>              mode = w32effects and 'win32' or 'none'
>>>          else:
>>> -            mode = 'ansi'
>>> +            _terminfosetup(ui)
>>> +            if not _terminfo_params:
>>> +                mode = 'ansi'
>>> +            else:
>>> +                mode = 'terminfo'
>>>      if mode == 'win32':
>>>          if w32effects is None:
>>>              # only warn if color.mode is explicitly set to win32
>>>              ui.warn(_('warning: failed to set color mode to %s\n') % mode)
>>>              return
>>>          _effects.update(w32effects)
>>> -    elif mode != 'ansi':
>>> +    elif mode == 'ansi':
>>> +        _terminfo_params = {}
>>> +    elif mode == 'terminfo':
>>> +        _terminfosetup(ui)
>>> +    elif mode not in ('ansi', 'terminfo'):
>>>          return
>>
>> Why not a simple else ?
> 
> Probably just hewing close to the original code.  It certainly doesn't seem
> to be necessary.
> 
> Shall I submit a new patch?

I will fix it, and perhaps add something to hghave, a terminfo test fails when run on certain hosts.

--
Patrick Mézard


More information about the Mercurial-devel mailing list