2 from dataclasses
import dataclass
6 class WindowsConsoleFeatures
:
7 """Windows features available."""
10 """The console supports VT codes."""
11 truecolor
: bool = False
12 """The console supports truecolor."""
17 from ctypes
import LibraryLoader
19 if sys
.platform
== "win32":
20 windll
= LibraryLoader(ctypes
.WinDLL
)
23 raise ImportError("Not windows")
25 from pip
._vendor
.rich
._win
32_console
import (
26 ENABLE_VIRTUAL_TERMINAL_PROCESSING
,
32 except (AttributeError, ImportError, ValueError):
34 # Fallback if we can't load the Windows DLL
35 def get_windows_console_features() -> WindowsConsoleFeatures
:
36 features
= WindowsConsoleFeatures()
41 def get_windows_console_features() -> WindowsConsoleFeatures
:
42 """Get windows console features.
45 WindowsConsoleFeatures: An instance of WindowsConsoleFeatures.
47 handle
= GetStdHandle()
49 console_mode
= GetConsoleMode(handle
)
51 except LegacyWindowsError
:
54 vt
= bool(success
and console_mode
& ENABLE_VIRTUAL_TERMINAL_PROCESSING
)
57 win_version
= sys
.getwindowsversion()
58 truecolor
= win_version
.major
> 10 or (
59 win_version
.major
== 10 and win_version
.build
>= 15063
61 features
= WindowsConsoleFeatures(vt
=vt
, truecolor
=truecolor
)
65 if __name__
== "__main__":
68 features
= get_windows_console_features()
69 from pip
._vendor
.rich
import print
71 print(f
'platform="{platform.system()}"')