support ANSI escapes under MSWin
This commit is contained in:
parent
7faa90cf40
commit
0c832c9c0c
4 changed files with 13 additions and 23 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)])
|
||||
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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)):
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue