From 60750494b8966c90020365e666de43e86e9078a1 Mon Sep 17 00:00:00 2001 From: calvin Date: Tue, 9 Nov 2004 14:02:18 +0000 Subject: [PATCH] implement windows ANSI color support check git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@1937 e7d03fd6-7b0d-0410-9947-9c21f3af8025 --- linkcheck/ansicolor.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/linkcheck/ansicolor.py b/linkcheck/ansicolor.py index d03c379b..ae7b1375 100644 --- a/linkcheck/ansicolor.py +++ b/linkcheck/ansicolor.py @@ -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: