hgext/color.py
changeset 18290 323e1267de36
parent 17806 dc7010ed0101
child 18829 8843182f3514
equal deleted inserted replaced
18289:9bfb53106328 18290:323e1267de36
   101 '''
   101 '''
   102 
   102 
   103 import os
   103 import os
   104 
   104 
   105 from mercurial import commands, dispatch, extensions, ui as uimod, util
   105 from mercurial import commands, dispatch, extensions, ui as uimod, util
       
   106 from mercurial import templater
   106 from mercurial.i18n import _
   107 from mercurial.i18n import _
   107 
   108 
   108 testedwith = 'internal'
   109 testedwith = 'internal'
   109 
   110 
   110 # start and stop parameters for effects
   111 # start and stop parameters for effects
   352         if effects:
   353         if effects:
   353             return '\n'.join([render_effects(s, effects)
   354             return '\n'.join([render_effects(s, effects)
   354                               for s in msg.split('\n')])
   355                               for s in msg.split('\n')])
   355         return msg
   356         return msg
   356 
   357 
       
   358 def templatelabel(context, mapping, args):
       
   359     if len(args) != 2:
       
   360         # i18n: "label" is a keyword
       
   361         raise error.ParseError(_("label expects two arguments"))
       
   362 
       
   363     thing = templater.stringify(args[1][0](context, mapping, args[1][1]))
       
   364     thing = templater.runtemplate(context, mapping,
       
   365                                   templater.compiletemplate(thing, context))
       
   366 
       
   367     # apparently, repo could be a string that is the favicon?
       
   368     repo = mapping.get('repo', '')
       
   369     if isinstance(repo, str):
       
   370         return thing
       
   371 
       
   372     label = templater.stringify(args[0][0](context, mapping, args[0][1]))
       
   373     label = templater.runtemplate(context, mapping,
       
   374                                   templater.compiletemplate(label, context))
       
   375 
       
   376     thing = templater.stringify(thing)
       
   377     label = templater.stringify(label)
       
   378 
       
   379     return repo.ui.label(thing, label)
   357 
   380 
   358 def uisetup(ui):
   381 def uisetup(ui):
   359     global _terminfo_params
   382     global _terminfo_params
   360     if ui.plain():
   383     if ui.plain():
   361         return
   384         return
   368                 ui_.__class__ = colorui
   391                 ui_.__class__ = colorui
   369             extstyles()
   392             extstyles()
   370             configstyles(ui_)
   393             configstyles(ui_)
   371         return orig(ui_, opts, cmd, cmdfunc)
   394         return orig(ui_, opts, cmd, cmdfunc)
   372     extensions.wrapfunction(dispatch, '_runcommand', colorcmd)
   395     extensions.wrapfunction(dispatch, '_runcommand', colorcmd)
       
   396     templater.funcs['label'] = templatelabel
   373 
   397 
   374 def extsetup(ui):
   398 def extsetup(ui):
   375     commands.globalopts.append(
   399     commands.globalopts.append(
   376         ('', 'color', 'auto',
   400         ('', 'color', 'auto',
   377          # i18n: 'always', 'auto', and 'never' are keywords and should
   401          # i18n: 'always', 'auto', and 'never' are keywords and should