try:
import ctypes
from ctypes import LibraryLoader
+
windll = LibraryLoader(ctypes.WinDLL)
from ctypes import wintypes
except (AttributeError, ImportError):
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
"""struct in wincon.h."""
+
_fields_ = [
("dwSize", COORD),
("dwCursorPosition", COORD),
("srWindow", wintypes.SMALL_RECT),
("dwMaximumWindowSize", COORD),
]
+
def __str__(self):
- return '(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)' % (
- self.dwSize.Y, self.dwSize.X
- , self.dwCursorPosition.Y, self.dwCursorPosition.X
- , self.wAttributes
- , self.srWindow.Top, self.srWindow.Left, self.srWindow.Bottom, self.srWindow.Right
- , self.dwMaximumWindowSize.Y, self.dwMaximumWindowSize.X
+ return "(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)" % (
+ self.dwSize.Y,
+ self.dwSize.X,
+ self.dwCursorPosition.Y,
+ self.dwCursorPosition.X,
+ self.wAttributes,
+ self.srWindow.Top,
+ self.srWindow.Left,
+ self.srWindow.Bottom,
+ self.srWindow.Right,
+ self.dwMaximumWindowSize.Y,
+ self.dwMaximumWindowSize.X,
)
_GetStdHandle = windll.kernel32.GetStdHandle
_FillConsoleOutputAttribute.restype = wintypes.BOOL
_SetConsoleTitleW = windll.kernel32.SetConsoleTitleA
- _SetConsoleTitleW.argtypes = [
- wintypes.LPCSTR
- ]
+ _SetConsoleTitleW.argtypes = [wintypes.LPCSTR]
_SetConsoleTitleW.restype = wintypes.BOOL
handles = {
def winapi_test():
handle = handles[STDOUT]
csbi = CONSOLE_SCREEN_BUFFER_INFO()
- success = _GetConsoleScreenBufferInfo(
- handle, byref(csbi))
+ success = _GetConsoleScreenBufferInfo(handle, byref(csbi))
return bool(success)
def GetConsoleScreenBufferInfo(stream_id=STDOUT):
handle = handles[stream_id]
csbi = CONSOLE_SCREEN_BUFFER_INFO()
- success = _GetConsoleScreenBufferInfo(
- handle, byref(csbi))
+ success = _GetConsoleScreenBufferInfo(handle, byref(csbi))
return csbi
def SetConsoleTextAttribute(stream_id, attrs):
num_written = wintypes.DWORD(0)
# Note that this is hard-coded for ANSI (vs wide) bytes.
success = _FillConsoleOutputCharacterA(
- handle, char, length, start, byref(num_written))
+ 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 )'''
+ """FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten )"""
handle = handles[stream_id]
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 _FillConsoleOutputAttribute(
- handle, attribute, length, start, byref(num_written))
+ handle, attribute, length, start, byref(num_written)
+ )
def SetConsoleTitle(title):
return _SetConsoleTitleW(title)