From e957b84defa7085a830a906dfcd181fa7f1816dc Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 2 Oct 2021 17:54:11 +0000 Subject: [PATCH] init_color(): allow disabling of color with num_colors=0 --- mmgen/color.py | 11 +++++++---- test/colortest.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mmgen/color.py b/mmgen/color.py index 939148e2..b64cfa35 100755 --- a/mmgen/color.py +++ b/mmgen/color.py @@ -90,11 +90,11 @@ def get_terminfo_colors(term=None): return None def init_color(num_colors='auto'): - assert num_colors in ('auto',8,16,256) + assert num_colors in ('auto',8,16,256,0) - globals()['_reset'] = '\033[0m' + globals()['_reset'] = '\033[0m' if num_colors else '' - if num_colors in (8,16): + if num_colors in (0,8,16): pfx = '_16_' else: import os @@ -105,6 +105,9 @@ def init_color(num_colors='auto'): pfx = '_16_' for c in _colors: - globals()['_clr_'+c] = globals()[pfx+c] + if num_colors == 0: + globals()['_clr_'+c] = '' + else: + globals()['_clr_'+c] = globals()[pfx+c] set_vt100() diff --git a/test/colortest.py b/test/colortest.py index a8ed4d4a..6ad985ed 100755 --- a/test/colortest.py +++ b/test/colortest.py @@ -31,7 +31,7 @@ def test_color(): set_vt100() gmsg("Terminal display:") - for desc,n in (('auto','auto'),('8-color',8),('256-color',256)): + for desc,n in (('auto','auto'),('8-color',8),('256-color',256),('off',0)): init_color(num_colors=n) msg('{:9}: {}'.format( desc,