init_color(): allow disabling of color with num_colors=0
This commit is contained in:
parent
ea5eedcff3
commit
e957b84def
2 changed files with 8 additions and 5 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue