MCPcopy Index your code
hub / github.com/python/mypy / initialize_win_colors

Method initialize_win_colors

mypy/util.py:654–681  ·  view source on GitHub ↗

Return True if initialization was successful and we can use colors, False otherwise

(self)

Source from the content-addressed store, hash-verified

652 return True
653
654 def initialize_win_colors(self) -> bool:
655 """Return True if initialization was successful and we can use colors, False otherwise"""
656 # Windows ANSI escape sequences are only supported on Threshold 2 and above.
657 # we check with an assert at runtime and an if check for mypy, as asserts do not
658 # yet narrow platform
659 if sys.platform == "win32": # needed to find win specific sys apis
660 winver = sys.getwindowsversion()
661 if (
662 winver.major < MINIMUM_WINDOWS_MAJOR_VT100
663 or winver.build < MINIMUM_WINDOWS_BUILD_VT100
664 ):
665 return False
666 import ctypes
667
668 kernel32 = ctypes.windll.kernel32
669 ENABLE_PROCESSED_OUTPUT = 0x1
670 ENABLE_WRAP_AT_EOL_OUTPUT = 0x2
671 ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
672 STD_OUTPUT_HANDLE = -11
673 kernel32.SetConsoleMode(
674 kernel32.GetStdHandle(STD_OUTPUT_HANDLE),
675 ENABLE_PROCESSED_OUTPUT
676 | ENABLE_WRAP_AT_EOL_OUTPUT
677 | ENABLE_VIRTUAL_TERMINAL_PROCESSING,
678 )
679 self.initialize_vt100_colors()
680 return True
681 assert False, "Running not on Windows"
682
683 def initialize_unix_colors(self) -> bool:
684 """Return True if initialization was successful and we can use colors, False otherwise"""

Callers 1

__init__Method · 0.95

Calls 1

Tested by

no test coverage detected