forked from python/cpython
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add colour to doctest output and create _colorize module
- Loading branch information
Showing
5 changed files
with
109 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import io | ||
import os | ||
import sys | ||
|
||
_COLORIZE = True | ||
|
||
|
||
class _ANSIColors: | ||
BOLD_GREEN = "\x1b[1;32m" | ||
BOLD_MAGENTA = "\x1b[1;35m" | ||
BOLD_RED = "\x1b[1;31m" | ||
GREEN = "\x1b[32m" | ||
GREY = "\x1b[90m" | ||
MAGENTA = "\x1b[35m" | ||
RED = "\x1b[31m" | ||
RESET = "\x1b[0m" | ||
YELLOW = "\x1b[33m" | ||
|
||
|
||
def _can_colorize(): | ||
if sys.platform == "win32": | ||
try: | ||
import nt | ||
|
||
if not nt._supports_virtual_terminal(): | ||
return False | ||
except (ImportError, AttributeError): | ||
return False | ||
|
||
if os.environ.get("PYTHON_COLORS") == "0": | ||
return False | ||
if os.environ.get("PYTHON_COLORS") == "1": | ||
return True | ||
if "NO_COLOR" in os.environ: | ||
return False | ||
if not _COLORIZE: | ||
return False | ||
if "FORCE_COLOR" in os.environ: | ||
return True | ||
if os.environ.get("TERM") == "dumb": | ||
return False | ||
try: | ||
return os.isatty(sys.stderr.fileno()) | ||
except io.UnsupportedOperation: | ||
return sys.stderr.isatty() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.