diff options
author | Shubham Saini <shubham6405@gmail.com> | 2018-12-11 10:01:23 +0000 |
---|---|---|
committer | Shubham Saini <shubham6405@gmail.com> | 2018-12-11 10:01:23 +0000 |
commit | 68df54d6629ec019142eb149dd037774f2d11e7c (patch) | |
tree | 345bc22d46b4e01a4ba8303b94278952a4ed2b9e /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/colorama/win32.py |
First commit
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/colorama/win32.py')
-rw-r--r-- | venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/colorama/win32.py | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/colorama/win32.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/colorama/win32.py new file mode 100644 index 0000000..1485e69 --- /dev/null +++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/colorama/win32.py | |||
@@ -0,0 +1,156 @@ | |||
1 | # Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file. | ||
2 | |||
3 | # from winbase.h | ||
4 | STDOUT = -11 | ||
5 | STDERR = -12 | ||
6 | |||
7 | try: | ||
8 | import ctypes | ||
9 | from ctypes import LibraryLoader | ||
10 | windll = LibraryLoader(ctypes.WinDLL) | ||
11 | from ctypes import wintypes | ||
12 | except (AttributeError, ImportError): | ||
13 | windll = None | ||
14 | SetConsoleTextAttribute = lambda *_: None | ||
15 | winapi_test = lambda *_: None | ||
16 | else: | ||
17 | from ctypes import byref, Structure, c_char, POINTER | ||
18 | |||
19 | COORD = wintypes._COORD | ||
20 | |||
21 | class CONSOLE_SCREEN_BUFFER_INFO(Structure): | ||
22 | """struct in wincon.h.""" | ||
23 | _fields_ = [ | ||
24 | ("dwSize", COORD), | ||
25 | ("dwCursorPosition", COORD), | ||
26 | ("wAttributes", wintypes.WORD), | ||
27 | ("srWindow", wintypes.SMALL_RECT), | ||
28 | ("dwMaximumWindowSize", COORD), | ||
29 | ] | ||
30 | def __str__(self): | ||
31 | return '(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)' % ( | ||
32 | self.dwSize.Y, self.dwSize.X | ||
33 | , self.dwCursorPosition.Y, self.dwCursorPosition.X | ||
34 | , self.wAttributes | ||
35 | , self.srWindow.Top, self.srWindow.Left, self.srWindow.Bottom, self.srWindow.Right | ||
36 | , self.dwMaximumWindowSize.Y, self.dwMaximumWindowSize.X | ||
37 | ) | ||
38 | |||
39 | _GetStdHandle = windll.kernel32.GetStdHandle | ||
40 | _GetStdHandle.argtypes = [ | ||
41 | wintypes.DWORD, | ||
42 | ] | ||
43 | _GetStdHandle.restype = wintypes.HANDLE | ||
44 | |||
45 | _GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo | ||
46 | _GetConsoleScreenBufferInfo.argtypes = [ | ||
47 | wintypes.HANDLE, | ||
48 | POINTER(CONSOLE_SCREEN_BUFFER_INFO), | ||
49 | ] | ||
50 | _GetConsoleScreenBufferInfo.restype = wintypes.BOOL | ||
51 | |||
52 | _SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute | ||
53 | _SetConsoleTextAttribute.argtypes = [ | ||
54 | wintypes.HANDLE, | ||
55 | wintypes.WORD, | ||
56 | ] | ||
57 | _SetConsoleTextAttribute.restype = wintypes.BOOL | ||
58 | |||
59 | _SetConsoleCursorPosition = windll.kernel32.SetConsoleCursorPosition | ||
60 | _SetConsoleCursorPosition.argtypes = [ | ||
61 | wintypes.HANDLE, | ||
62 | COORD, | ||
63 | ] | ||
64 | _SetConsoleCursorPosition.restype = wintypes.BOOL | ||
65 | |||
66 | _FillConsoleOutputCharacterA = windll.kernel32.FillConsoleOutputCharacterA | ||
67 | _FillConsoleOutputCharacterA.argtypes = [ | ||
68 | wintypes.HANDLE, | ||
69 | c_char, | ||
70 | wintypes.DWORD, | ||
71 | COORD, | ||
72 | POINTER(wintypes.DWORD), | ||
73 | ] | ||
74 | _FillConsoleOutputCharacterA.restype = wintypes.BOOL | ||
75 | |||
76 | _FillConsoleOutputAttribute = windll.kernel32.FillConsoleOutputAttribute | ||
77 | _FillConsoleOutputAttribute.argtypes = [ | ||
78 | wintypes.HANDLE, | ||
79 | wintypes.WORD, | ||
80 | wintypes.DWORD, | ||
81 | COORD, | ||
82 | POINTER(wintypes.DWORD), | ||
83 | ] | ||
84 | _FillConsoleOutputAttribute.restype = wintypes.BOOL | ||
85 | |||
86 | _SetConsoleTitleW = windll.kernel32.SetConsoleTitleW | ||
87 | _SetConsoleTitleW.argtypes = [ | ||
88 | wintypes.LPCWSTR | ||
89 | ] | ||
90 | _SetConsoleTitleW.restype = wintypes.BOOL | ||
91 | |||
92 | handles = { | ||
93 | STDOUT: _GetStdHandle(STDOUT), | ||
94 | STDERR: _GetStdHandle(STDERR), | ||
95 | } | ||
96 | |||
97 | def _winapi_test(handle): | ||
98 | csbi = CONSOLE_SCREEN_BUFFER_INFO() | ||
99 | success = _GetConsoleScreenBufferInfo( | ||
100 | handle, byref(csbi)) | ||
101 | return bool(success) | ||
102 | |||
103 | def winapi_test(): | ||
104 | return any(_winapi_test(h) for h in handles.values()) | ||
105 | |||
106 | def GetConsoleScreenBufferInfo(stream_id=STDOUT): | ||
107 | handle = handles[stream_id] | ||
108 | csbi = CONSOLE_SCREEN_BUFFER_INFO() | ||
109 | success = _GetConsoleScreenBufferInfo( | ||
110 | handle, byref(csbi)) | ||
111 | return csbi | ||
112 | |||
113 | def SetConsoleTextAttribute(stream_id, attrs): | ||
114 | handle = handles[stream_id] | ||
115 | return _SetConsoleTextAttribute(handle, attrs) | ||
116 | |||
117 | def SetConsoleCursorPosition(stream_id, position, adjust=True): | ||
118 | position = COORD(*position) | ||
119 | # If the position is out of range, do nothing. | ||
120 | if position.Y <= 0 or position.X <= 0: | ||
121 | return | ||
122 | # Adjust for Windows' SetConsoleCursorPosition: | ||
123 | # 1. being 0-based, while ANSI is 1-based. | ||
124 | # 2. expecting (x,y), while ANSI uses (y,x). | ||
125 | adjusted_position = COORD(position.Y - 1, position.X - 1) | ||
126 | if adjust: | ||
127 | # Adjust for viewport's scroll position | ||
128 | sr = GetConsoleScreenBufferInfo(STDOUT).srWindow | ||
129 | adjusted_position.Y += sr.Top | ||
130 | adjusted_position.X += sr.Left | ||
131 | # Resume normal processing | ||
132 | handle = handles[stream_id] | ||
133 | return _SetConsoleCursorPosition(handle, adjusted_position) | ||
134 | |||
135 | def FillConsoleOutputCharacter(stream_id, char, length, start): | ||
136 | handle = handles[stream_id] | ||
137 | char = c_char(char.encode()) | ||
138 | length = wintypes.DWORD(length) | ||
139 | num_written = wintypes.DWORD(0) | ||
140 | # Note that this is hard-coded for ANSI (vs wide) bytes. | ||
141 | success = _FillConsoleOutputCharacterA( | ||
142 | handle, char, length, start, byref(num_written)) | ||
143 | return num_written.value | ||
144 | |||
145 | def FillConsoleOutputAttribute(stream_id, attr, length, start): | ||
146 | ''' FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten )''' | ||
147 | handle = handles[stream_id] | ||
148 | attribute = wintypes.WORD(attr) | ||
149 | length = wintypes.DWORD(length) | ||
150 | num_written = wintypes.DWORD(0) | ||
151 | # Note that this is hard-coded for ANSI (vs wide) bytes. | ||
152 | return _FillConsoleOutputAttribute( | ||
153 | handle, attribute, length, start, byref(num_written)) | ||
154 | |||
155 | def SetConsoleTitle(title): | ||
156 | return _SetConsoleTitleW(title) | ||