]> jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_vendor/rich/_windows.py
init: venv aand flask
[dlqueue.git] / venv / lib / python3.11 / site-packages / pip / _vendor / rich / _windows.py
1 import sys
2 from dataclasses import dataclass
3
4
5 @dataclass
6 class WindowsConsoleFeatures:
7 """Windows features available."""
8
9 vt: bool = False
10 """The console supports VT codes."""
11 truecolor: bool = False
12 """The console supports truecolor."""
13
14
15 try:
16 import ctypes
17 from ctypes import LibraryLoader
18
19 if sys.platform == "win32":
20 windll = LibraryLoader(ctypes.WinDLL)
21 else:
22 windll = None
23 raise ImportError("Not windows")
24
25 from pip._vendor.rich._win32_console import (
26 ENABLE_VIRTUAL_TERMINAL_PROCESSING,
27 GetConsoleMode,
28 GetStdHandle,
29 LegacyWindowsError,
30 )
31
32 except (AttributeError, ImportError, ValueError):
33
34 # Fallback if we can't load the Windows DLL
35 def get_windows_console_features() -> WindowsConsoleFeatures:
36 features = WindowsConsoleFeatures()
37 return features
38
39 else:
40
41 def get_windows_console_features() -> WindowsConsoleFeatures:
42 """Get windows console features.
43
44 Returns:
45 WindowsConsoleFeatures: An instance of WindowsConsoleFeatures.
46 """
47 handle = GetStdHandle()
48 try:
49 console_mode = GetConsoleMode(handle)
50 success = True
51 except LegacyWindowsError:
52 console_mode = 0
53 success = False
54 vt = bool(success and console_mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)
55 truecolor = False
56 if vt:
57 win_version = sys.getwindowsversion()
58 truecolor = win_version.major > 10 or (
59 win_version.major == 10 and win_version.build >= 15063
60 )
61 features = WindowsConsoleFeatures(vt=vt, truecolor=truecolor)
62 return features
63
64
65 if __name__ == "__main__":
66 import platform
67
68 features = get_windows_console_features()
69 from pip._vendor.rich import print
70
71 print(f'platform="{platform.system()}"')
72 print(repr(features))