mercurial/color.py
changeset 31521 44c591f63458
parent 31518 43d6ef658874
child 31689 57a22f699179
equal deleted inserted replaced
31520:6f150bb19317 31521:44c591f63458
     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 import re
     9 
    11 
    10 from .i18n import _
    12 from .i18n import _
    11 
    13 
    12 from . import (
    14 from . import (
    13     encoding,
    15     encoding,
   325         start = [str(_effects[e]) for e in ['none'] + effects.split()]
   327         start = [str(_effects[e]) for e in ['none'] + effects.split()]
   326         start = '\033[' + ';'.join(start) + 'm'
   328         start = '\033[' + ';'.join(start) + 'm'
   327         stop = '\033[' + str(_effects['none']) + 'm'
   329         stop = '\033[' + str(_effects['none']) + 'm'
   328     return _mergeeffects(text, start, stop)
   330     return _mergeeffects(text, start, stop)
   329 
   331 
       
   332 _ansieffectre = re.compile(br'\x1b\[[0-9;]*m')
       
   333 
       
   334 def stripeffects(text):
       
   335     """Strip ANSI control codes which could be inserted by colorlabel()"""
       
   336     return _ansieffectre.sub('', text)
       
   337 
   330 def colorlabel(ui, msg, label):
   338 def colorlabel(ui, msg, label):
   331     """add color control code according to the mode"""
   339     """add color control code according to the mode"""
   332     if ui._colormode == 'debug':
   340     if ui._colormode == 'debug':
   333         if label and msg:
   341         if label and msg:
   334             if msg[-1] == '\n':
   342             if msg[-1] == '\n':
   350     return msg
   358     return msg
   351 
   359 
   352 w32effects = None
   360 w32effects = None
   353 if pycompat.osname == 'nt':
   361 if pycompat.osname == 'nt':
   354     import ctypes
   362     import ctypes
   355     import re
       
   356 
   363 
   357     _kernel32 = ctypes.windll.kernel32
   364     _kernel32 = ctypes.windll.kernel32
   358 
   365 
   359     _WORD = ctypes.c_ushort
   366     _WORD = ctypes.c_ushort
   360 
   367