# HG changeset patch # User Pierre-Yves David # Date 2024-12-12 15:00:44 # Node ID c2ee1ad78414f2c6a92df8ca050a2180f975aeaa # Parent cbd2f3509df8c182293c349ee52e3fa691f0347c run-tests: add a function to colorize a piece of text This will get handy to color some error message diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -97,6 +97,7 @@ try: # is pygments installed import pygments.formatters as formatters import pygments.token as token import pygments.style as style + from pygments.console import ansiformat if WINDOWS: hgpath = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -113,8 +114,17 @@ try: # is pygments installed pygmentspresent = True difflexer = lexers.DiffLexer() terminal256formatter = formatters.Terminal256Formatter() + + def colorize(text: str, style: str, color: bool = True) -> str: + if not color: + return text + return ansiformat(style, text) + except ImportError: - pass + + def colorize(text: str, style: str, color: bool = True) -> str: + return text + progress_type = {}