hgext/color.py
changeset 30969 ddc80d1777a6
parent 30968 0d2a58a04080
child 30971 bb6385882cfa
equal deleted inserted replaced
30968:0d2a58a04080 30969:ddc80d1777a6
   330         start = ''.join(_effect_str(effect)
   330         start = ''.join(_effect_str(effect)
   331                         for effect in ['none'] + effects.split())
   331                         for effect in ['none'] + effects.split())
   332         stop = _effect_str('none')
   332         stop = _effect_str('none')
   333     return ''.join([start, text, stop])
   333     return ''.join([start, text, stop])
   334 
   334 
   335 def valideffect(effect):
       
   336     'Determine if the effect is valid or not.'
       
   337     good = False
       
   338     if not color._terminfo_params and effect in color._effects:
       
   339         good = True
       
   340     elif (effect in color._terminfo_params
       
   341           or effect[:-11] in color._terminfo_params):
       
   342         good = True
       
   343     return good
       
   344 
       
   345 def configstyles(ui):
   335 def configstyles(ui):
   346     for status, cfgeffects in ui.configitems('color'):
   336     for status, cfgeffects in ui.configitems('color'):
   347         if '.' not in status or status.startswith(('color.', 'terminfo.')):
   337         if '.' not in status or status.startswith(('color.', 'terminfo.')):
   348             continue
   338             continue
   349         cfgeffects = ui.configlist('color', status)
   339         cfgeffects = ui.configlist('color', status)
   350         if cfgeffects:
   340         if cfgeffects:
   351             good = []
   341             good = []
   352             for e in cfgeffects:
   342             for e in cfgeffects:
   353                 if valideffect(e):
   343                 if color.valideffect(e):
   354                     good.append(e)
   344                     good.append(e)
   355                 else:
   345                 else:
   356                     ui.warn(_("ignoring unknown color/effect %r "
   346                     ui.warn(_("ignoring unknown color/effect %r "
   357                               "(configured in color.%s)\n")
   347                               "(configured in color.%s)\n")
   358                             % (e, status))
   348                             % (e, status))
   410         effects = []
   400         effects = []
   411         for l in label.split():
   401         for l in label.split():
   412             s = color._styles.get(l, '')
   402             s = color._styles.get(l, '')
   413             if s:
   403             if s:
   414                 effects.append(s)
   404                 effects.append(s)
   415             elif valideffect(l):
   405             elif color.valideffect(l):
   416                 effects.append(l)
   406                 effects.append(l)
   417         effects = ' '.join(effects)
   407         effects = ' '.join(effects)
   418         if effects:
   408         if effects:
   419             return '\n'.join([render_effects(line, effects)
   409             return '\n'.join([render_effects(line, effects)
   420                               for line in msg.split('\n')])
   410                               for line in msg.split('\n')])