mercurial/color.py
changeset 30971 bb6385882cfa
parent 30970 683606a829e8
child 30972 a3c7e42c7a1f
equal deleted inserted replaced
30970:683606a829e8 30971:bb6385882cfa
     4 #
     4 #
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from __future__ import absolute_import
     8 from __future__ import absolute_import
       
     9 
       
    10 from .i18n import _
     9 
    11 
    10 try:
    12 try:
    11     import curses
    13     import curses
    12     # Mapping from effect name to terminfo attribute name (or raw code) or
    14     # Mapping from effect name to terminfo attribute name (or raw code) or
    13     # color number.  This will also force-load the curses module.
    15     # color number.  This will also force-load the curses module.
   112            'tags.local': 'black bold'}
   114            'tags.local': 'black bold'}
   113 
   115 
   114 def loadcolortable(ui, extname, colortable):
   116 def loadcolortable(ui, extname, colortable):
   115     _styles.update(colortable)
   117     _styles.update(colortable)
   116 
   118 
       
   119 def configstyles(ui):
       
   120     for status, cfgeffects in ui.configitems('color'):
       
   121         if '.' not in status or status.startswith(('color.', 'terminfo.')):
       
   122             continue
       
   123         cfgeffects = ui.configlist('color', status)
       
   124         if cfgeffects:
       
   125             good = []
       
   126             for e in cfgeffects:
       
   127                 if valideffect(e):
       
   128                     good.append(e)
       
   129                 else:
       
   130                     ui.warn(_("ignoring unknown color/effect %r "
       
   131                               "(configured in color.%s)\n")
       
   132                             % (e, status))
       
   133             _styles[status] = ' '.join(good)
       
   134 
   117 def valideffect(effect):
   135 def valideffect(effect):
   118     'Determine if the effect is valid or not.'
   136     'Determine if the effect is valid or not.'
   119     return ((not _terminfo_params and effect in _effects)
   137     return ((not _terminfo_params and effect in _effects)
   120              or (effect in _terminfo_params
   138              or (effect in _terminfo_params
   121                  or effect[:-11] in _terminfo_params))
   139                  or effect[:-11] in _terminfo_params))