mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-24 14:13:43 +00:00
implement windows ANSI color support check
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@1937 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
a87b8a64d2
commit
60750494b8
1 changed files with 22 additions and 4 deletions
|
|
@ -139,10 +139,7 @@ def has_colors (fp):
|
|||
# redirected streams, as this is almost never what we want
|
||||
if hasattr(fp, "isatty") and fp.isatty():
|
||||
if os.name == 'nt':
|
||||
# windows has no curses; assume we are running in a DOS
|
||||
# command prompt which supports ANSI colors (ie. assume
|
||||
# that ANSI.SYS is loaded)
|
||||
return True
|
||||
return has_colors_nt()
|
||||
try:
|
||||
import curses
|
||||
curses.setupterm()
|
||||
|
|
@ -155,6 +152,27 @@ def has_colors (fp):
|
|||
return False
|
||||
|
||||
|
||||
def has_colors_nt ():
|
||||
"""windows has no curses; check if running in an environment
|
||||
which supports ANSI colors
|
||||
"""
|
||||
_in = None
|
||||
_out = None
|
||||
try:
|
||||
_in, _out = os.popen4("mem /c")
|
||||
line = _out.readline()
|
||||
while line:
|
||||
if "ANSI" in line:
|
||||
return True
|
||||
line = _out.readline()
|
||||
return False
|
||||
finally:
|
||||
if _in is not None:
|
||||
_in.close()
|
||||
if _out is not None:
|
||||
_out.close()
|
||||
|
||||
|
||||
def colorize (text, color=None):
|
||||
"""return text colorized if color is given"""
|
||||
if color is not None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue