| Index: third_party/colorama/win32.py
|
| diff --git a/third_party/colorama/win32.py b/third_party/colorama/win32.py
|
| index 591176131f56c4d29c179d830b9b017f099d3c06..f4024f95ee04b15163f151170d84e41a96ccdfbd 100644
|
| --- a/third_party/colorama/win32.py
|
| +++ b/third_party/colorama/win32.py
|
| @@ -1,3 +1,4 @@
|
| +# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
|
|
|
| # from winbase.h
|
| STDOUT = -11
|
| @@ -5,48 +6,23 @@ STDERR = -12
|
|
|
| try:
|
| from ctypes import windll
|
| + from ctypes import wintypes
|
| except ImportError:
|
| windll = None
|
| SetConsoleTextAttribute = lambda *_: None
|
| else:
|
| from ctypes import (
|
| - byref, Structure, c_char, c_short, c_uint32, c_ushort
|
| + byref, Structure, c_char, c_short, c_uint32, c_ushort, POINTER
|
| )
|
|
|
| - handles = {
|
| - STDOUT: windll.kernel32.GetStdHandle(STDOUT),
|
| - STDERR: windll.kernel32.GetStdHandle(STDERR),
|
| - }
|
| -
|
| - SHORT = c_short
|
| - WORD = c_ushort
|
| - DWORD = c_uint32
|
| - TCHAR = c_char
|
| -
|
| - class COORD(Structure):
|
| - """struct in wincon.h"""
|
| - _fields_ = [
|
| - ('X', SHORT),
|
| - ('Y', SHORT),
|
| - ]
|
| -
|
| - class SMALL_RECT(Structure):
|
| - """struct in wincon.h."""
|
| - _fields_ = [
|
| - ("Left", SHORT),
|
| - ("Top", SHORT),
|
| - ("Right", SHORT),
|
| - ("Bottom", SHORT),
|
| - ]
|
| -
|
| class CONSOLE_SCREEN_BUFFER_INFO(Structure):
|
| """struct in wincon.h."""
|
| _fields_ = [
|
| - ("dwSize", COORD),
|
| - ("dwCursorPosition", COORD),
|
| - ("wAttributes", WORD),
|
| - ("srWindow", SMALL_RECT),
|
| - ("dwMaximumWindowSize", COORD),
|
| + ("dwSize", wintypes._COORD),
|
| + ("dwCursorPosition", wintypes._COORD),
|
| + ("wAttributes", wintypes.WORD),
|
| + ("srWindow", wintypes.SMALL_RECT),
|
| + ("dwMaximumWindowSize", wintypes._COORD),
|
| ]
|
| def __str__(self):
|
| return '(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)' % (
|
| @@ -57,53 +33,102 @@ else:
|
| , self.dwMaximumWindowSize.Y, self.dwMaximumWindowSize.X
|
| )
|
|
|
| + _GetStdHandle = windll.kernel32.GetStdHandle
|
| + _GetStdHandle.argtypes = [
|
| + wintypes.DWORD,
|
| + ]
|
| + _GetStdHandle.restype = wintypes.HANDLE
|
| +
|
| + _GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo
|
| + _GetConsoleScreenBufferInfo.argtypes = [
|
| + wintypes.HANDLE,
|
| + POINTER(CONSOLE_SCREEN_BUFFER_INFO),
|
| + ]
|
| + _GetConsoleScreenBufferInfo.restype = wintypes.BOOL
|
| +
|
| + _SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute
|
| + _SetConsoleTextAttribute.argtypes = [
|
| + wintypes.HANDLE,
|
| + wintypes.WORD,
|
| + ]
|
| + _SetConsoleTextAttribute.restype = wintypes.BOOL
|
| +
|
| + _SetConsoleCursorPosition = windll.kernel32.SetConsoleCursorPosition
|
| + _SetConsoleCursorPosition.argtypes = [
|
| + wintypes.HANDLE,
|
| + wintypes._COORD,
|
| + ]
|
| + _SetConsoleCursorPosition.restype = wintypes.BOOL
|
| +
|
| + _FillConsoleOutputCharacterA = windll.kernel32.FillConsoleOutputCharacterA
|
| + _FillConsoleOutputCharacterA.argtypes = [
|
| + wintypes.HANDLE,
|
| + c_char,
|
| + wintypes.DWORD,
|
| + wintypes._COORD,
|
| + POINTER(wintypes.DWORD),
|
| + ]
|
| + _FillConsoleOutputCharacterA.restype = wintypes.BOOL
|
| +
|
| + _FillConsoleOutputAttribute = windll.kernel32.FillConsoleOutputAttribute
|
| + _FillConsoleOutputAttribute.argtypes = [
|
| + wintypes.HANDLE,
|
| + wintypes.WORD,
|
| + wintypes.DWORD,
|
| + wintypes._COORD,
|
| + POINTER(wintypes.DWORD),
|
| + ]
|
| + _FillConsoleOutputAttribute.restype = wintypes.BOOL
|
| +
|
| + handles = {
|
| + STDOUT: _GetStdHandle(STDOUT),
|
| + STDERR: _GetStdHandle(STDERR),
|
| + }
|
| +
|
| def GetConsoleScreenBufferInfo(stream_id=STDOUT):
|
| handle = handles[stream_id]
|
| csbi = CONSOLE_SCREEN_BUFFER_INFO()
|
| - success = windll.kernel32.GetConsoleScreenBufferInfo(
|
| + success = _GetConsoleScreenBufferInfo(
|
| handle, byref(csbi))
|
| return csbi
|
|
|
| -
|
| def SetConsoleTextAttribute(stream_id, attrs):
|
| handle = handles[stream_id]
|
| - return windll.kernel32.SetConsoleTextAttribute(handle, attrs)
|
| -
|
| + return _SetConsoleTextAttribute(handle, attrs)
|
|
|
| def SetConsoleCursorPosition(stream_id, position):
|
| - position = COORD(*position)
|
| + position = wintypes._COORD(*position)
|
| # If the position is out of range, do nothing.
|
| if position.Y <= 0 or position.X <= 0:
|
| return
|
| # Adjust for Windows' SetConsoleCursorPosition:
|
| # 1. being 0-based, while ANSI is 1-based.
|
| # 2. expecting (x,y), while ANSI uses (y,x).
|
| - adjusted_position = COORD(position.Y - 1, position.X - 1)
|
| + adjusted_position = wintypes._COORD(position.Y - 1, position.X - 1)
|
| # Adjust for viewport's scroll position
|
| sr = GetConsoleScreenBufferInfo(STDOUT).srWindow
|
| adjusted_position.Y += sr.Top
|
| adjusted_position.X += sr.Left
|
| # Resume normal processing
|
| handle = handles[stream_id]
|
| - return windll.kernel32.SetConsoleCursorPosition(handle, adjusted_position)
|
| + return _SetConsoleCursorPosition(handle, adjusted_position)
|
|
|
| def FillConsoleOutputCharacter(stream_id, char, length, start):
|
| handle = handles[stream_id]
|
| - char = TCHAR(char)
|
| - length = DWORD(length)
|
| - num_written = DWORD(0)
|
| + char = c_char(char)
|
| + length = wintypes.DWORD(length)
|
| + num_written = wintypes.DWORD(0)
|
| # Note that this is hard-coded for ANSI (vs wide) bytes.
|
| - success = windll.kernel32.FillConsoleOutputCharacterA(
|
| + success = _FillConsoleOutputCharacterA(
|
| handle, char, length, start, byref(num_written))
|
| return num_written.value
|
|
|
| def FillConsoleOutputAttribute(stream_id, attr, length, start):
|
| ''' FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten )'''
|
| handle = handles[stream_id]
|
| - attribute = WORD(attr)
|
| - length = DWORD(length)
|
| - num_written = DWORD(0)
|
| + attribute = wintypes.WORD(attr)
|
| + length = wintypes.DWORD(length)
|
| + num_written = wintypes.DWORD(0)
|
| # Note that this is hard-coded for ANSI (vs wide) bytes.
|
| - return windll.kernel32.FillConsoleOutputAttribute(
|
| + return _FillConsoleOutputAttribute(
|
| handle, attribute, length, start, byref(num_written))
|
| -
|
|
|