Mercurial > public > mercurial-scm > hg-stable
diff mercurial/color.py @ 31527:44c591f63458
templater: make pad() strip color codes before computing width (issue5416)
Tested in ANSI mode. We might have to extend _ansieffectre to support
terminfo mode.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 18 Mar 2017 21:02:20 +0900 |
parents | 43d6ef658874 |
children | 57a22f699179 |
line wrap: on
line diff
--- a/mercurial/color.py Sat Mar 18 20:50:15 2017 +0900 +++ b/mercurial/color.py Sat Mar 18 21:02:20 2017 +0900 @@ -7,6 +7,8 @@ from __future__ import absolute_import +import re + from .i18n import _ from . import ( @@ -327,6 +329,12 @@ stop = '\033[' + str(_effects['none']) + 'm' return _mergeeffects(text, start, stop) +_ansieffectre = re.compile(br'\x1b\[[0-9;]*m') + +def stripeffects(text): + """Strip ANSI control codes which could be inserted by colorlabel()""" + return _ansieffectre.sub('', text) + def colorlabel(ui, msg, label): """add color control code according to the mode""" if ui._colormode == 'debug': @@ -352,7 +360,6 @@ w32effects = None if pycompat.osname == 'nt': import ctypes - import re _kernel32 = ctypes.windll.kernel32