def get_console_info(kernel32, handle):
    # Query Win32 API.
    csbi = ConsoleScreenBufferInfo()  # Populated by GetConsoleScreenBufferInfo.
    try:
        if not kernel32.GetConsoleScreenBufferInfo(handle, ctypes.byref(csbi)):
            raise IOError('Unable to get console screen buffer info from win32 API.')
    except ctypes.ArgumentError:
        raise IOError('Unable to get console screen buffer info from win32 API.')

    # Parse data.
    # buffer_width = int(csbi.dwSize.X - 1)
    # buffer_height = int(csbi.dwSize.Y)
    # terminal_width = int(csbi.srWindow.Right - csbi.srWindow.Left)
    # terminal_height = int(csbi.srWindow.Bottom - csbi.srWindow.Top)
    fg_color = csbi.wAttributes % 16
    bg_color = csbi.wAttributes & 240

    return fg_color, bg_color
Get information about this current console window.
dataset/ETHPy150Open Robpol86/colorclass/colorclass/windows.py/get_console_info