From 0c832c9c0cf566b8be1d8208d07cba910c7612ff Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 26 Jul 2021 18:26:21 +0000 Subject: [PATCH] support ANSI escapes under MSWin --- mmgen/color.py | 20 ++++++++------------ mmgen/opts.py | 4 +--- test/colortest.py | 10 +++------- test/test.py | 2 +- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/mmgen/color.py b/mmgen/color.py index df62e902..eae636cb 100755 --- a/mmgen/color.py +++ b/mmgen/color.py @@ -52,6 +52,13 @@ for _c in _colors: def nocolor(s): return s +def set_vt100(): + 'hack to put term into VT100 mode under MSWin' + from .globalvars import g + if g.platform == 'win': + from subprocess import run + run([],shell=True) + def get_terminfo_colors(term=None): from subprocess import run,PIPE cmd = ['infocmp','-0'] @@ -91,15 +98,4 @@ def init_color(num_colors='auto'): for c in _colors: globals()['_clr_'+c] = globals()[pfx+c] -def start_mscolor(): - import sys - from .globalvars import g - try: - import colorama - colorama.init(strip=True,convert=True) - except: - from .util import msg - msg('Import of colorama module failed') - else: - g.stdout = sys.stdout - g.stderr = sys.stderr + set_vt100() diff --git a/mmgen/opts.py b/mmgen/opts.py index 810a3262..99ccbfe3 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -310,9 +310,7 @@ def init(opts_data=None,add_opts=None,init_opts=None,opt_filter=None,parse_only= g.color is finalized, so initialize color """ if g.color: # MMGEN_DISABLE_COLOR sets this to False - from .color import start_mscolor,init_color - if g.platform == 'win': - start_mscolor() + from .color import init_color init_color(num_colors=('auto',256)[bool(g.force_256_color)]) """ diff --git a/test/colortest.py b/test/colortest.py index ea48f383..9a2da5c5 100755 --- a/test/colortest.py +++ b/test/colortest.py @@ -11,20 +11,16 @@ import include.tests_header from include.common import * from mmgen.color import * from mmgen.color import _colors -init_color() def test_color(): - try: - import colorama - start_mscolor() - except: - pass + init_color() gmsg("Parsed terminfo 'colors' values:") for t,c in (('rxvt',8),('xterm',8),('rxvt-unicode',88),('screen-256color',256),('xterm-256color',256)): ret = get_terminfo_colors(t) if ret == None: + set_vt100() ymsg('Warning: unable to get info for terminal {!r}'.format(t)) continue msg('{}: {}'.format(t,ret)) @@ -32,7 +28,7 @@ def test_color(): ret = get_terminfo_colors() msg('This terminal ({}): {}'.format(os.getenv('TERM'),ret)) - + set_vt100() gmsg("Terminal display:") for desc,n in (('auto','auto'),('8-color',8),('256-color',256)): diff --git a/test/test.py b/test/test.py index 1f831705..181b062e 100755 --- a/test/test.py +++ b/test/test.py @@ -704,7 +704,7 @@ class TestSuiteRunner(object): self.ts.test_name, cmd_disp)) - os.environ['MMGEN_FORCE_COLOR'] = ('1' if self.ts.color and g.platform == 'linux' else '') + os.environ['MMGEN_FORCE_COLOR'] = '1' if self.ts.color else '' from test.include.pexpect import MMGenPexpect return MMGenPexpect(args,no_output=no_output)