|
28 | 28 | except ImportError: |
29 | 29 | CURSES_ENABLED = False |
30 | 30 |
|
31 | | -IS_WIN: Final = sys.platform == "win32" |
32 | | - |
33 | 31 | T = TypeVar("T") |
34 | 32 |
|
35 | 33 | TYPESHED_DIR: Final = str(importlib_resources.files("mypy") / "typeshed") |
@@ -606,7 +604,7 @@ def __init__( |
606 | 604 | if not should_force_color() and (not f_out.isatty() or not f_err.isatty()): |
607 | 605 | self.dummy_term = True |
608 | 606 | return |
609 | | - if IS_WIN: |
| 607 | + if sys.platform == "win32": |
610 | 608 | self.dummy_term = not self.initialize_win_colors() |
611 | 609 | elif sys.platform == "emscripten": |
612 | 610 | self.dummy_term = not self.initialize_vt100_colors() |
@@ -640,32 +638,34 @@ def initialize_win_colors(self) -> bool: |
640 | 638 | # Windows ANSI escape sequences are only supported on Threshold 2 and above. |
641 | 639 | # we check with an assert at runtime and an if check for mypy, as asserts do not |
642 | 640 | # yet narrow platform |
643 | | - assert IS_WIN, "Running not on Windows" |
644 | | - winver = sys.getwindowsversion() |
645 | | - if ( |
646 | | - winver.major < MINIMUM_WINDOWS_MAJOR_VT100 |
647 | | - or winver.build < MINIMUM_WINDOWS_BUILD_VT100 |
648 | | - ): |
649 | | - return False |
650 | | - import ctypes |
651 | | - |
652 | | - kernel32 = ctypes.windll.kernel32 |
653 | | - ENABLE_PROCESSED_OUTPUT = 0x1 |
654 | | - ENABLE_WRAP_AT_EOL_OUTPUT = 0x2 |
655 | | - ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4 |
656 | | - STD_OUTPUT_HANDLE = -11 |
657 | | - kernel32.SetConsoleMode( |
658 | | - kernel32.GetStdHandle(STD_OUTPUT_HANDLE), |
659 | | - ENABLE_PROCESSED_OUTPUT |
660 | | - | ENABLE_WRAP_AT_EOL_OUTPUT |
661 | | - | ENABLE_VIRTUAL_TERMINAL_PROCESSING, |
662 | | - ) |
663 | | - self.initialize_vt100_colors() |
| 641 | + assert sys.platform == "win32", "Running not on Windows" |
| 642 | + if sys.platform == "win32": # needed to find win specific sys apis |
| 643 | + winver = sys.getwindowsversion() |
| 644 | + if ( |
| 645 | + winver.major < MINIMUM_WINDOWS_MAJOR_VT100 |
| 646 | + or winver.build < MINIMUM_WINDOWS_BUILD_VT100 |
| 647 | + ): |
| 648 | + return False |
| 649 | + import ctypes |
| 650 | + |
| 651 | + kernel32 = ctypes.windll.kernel32 |
| 652 | + ENABLE_PROCESSED_OUTPUT = 0x1 |
| 653 | + ENABLE_WRAP_AT_EOL_OUTPUT = 0x2 |
| 654 | + ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4 |
| 655 | + STD_OUTPUT_HANDLE = -11 |
| 656 | + kernel32.SetConsoleMode( |
| 657 | + kernel32.GetStdHandle(STD_OUTPUT_HANDLE), |
| 658 | + ENABLE_PROCESSED_OUTPUT |
| 659 | + | ENABLE_WRAP_AT_EOL_OUTPUT |
| 660 | + | ENABLE_VIRTUAL_TERMINAL_PROCESSING, |
| 661 | + ) |
| 662 | + self.initialize_vt100_colors() |
664 | 663 | return True |
665 | 664 |
|
666 | 665 | def initialize_unix_colors(self) -> bool: |
667 | 666 | """Return True if initialization was successful and we can use colors, False otherwise""" |
668 | | - if IS_WIN or not CURSES_ENABLED: |
| 667 | + is_win = sys.platform == "win32" |
| 668 | + if is_win or not CURSES_ENABLED: |
669 | 669 | return False |
670 | 670 | try: |
671 | 671 | # setupterm wants a fd to potentially write an "initialization sequence". |
|
0 commit comments