Return True if initialization was successful and we can use colors, False otherwise
(self)
| 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""" |
no test coverage detected