Returns current colors of console.

        https://docs.microsoft.com/en-us/windows/console/getconsolescreenbufferinfo

        Arguments:
            name:   one of ('background', 'bg', 'foreground', 'fg')
            stream: Handle to stdout, stderr, etc.

        Returns:
            int:  a color id from the conhost palette.
                  Ids under 0x8 (8) are dark colors, above light.

def get_color(name, stream=STD_OUTPUT_HANDLE):
    ''' Returns current colors of console.

        https://docs.microsoft.com/en-us/windows/console/getconsolescreenbufferinfo

        Arguments:
            name:   one of ('background', 'bg', 'foreground', 'fg')
            stream: Handle to stdout, stderr, etc.

        Returns:
            int:  a color id from the conhost palette.
                  Ids under 0x8 (8) are dark colors, above light.
    '''
    stream = kernel32.GetStdHandle(stream)
    csbi = CONSOLE_SCREEN_BUFFER_INFO()
    kernel32.GetConsoleScreenBufferInfo(stream, byref(csbi))
    color_id = csbi.wAttributes & _mask_map.get(name, name)
    log.debug('color_id from conhost: %d', color_id)
    if name in ('background', 'bg'):
        color_id /= 16  # divide by 16
        log.debug('color_id divided: %d', color_id)

    # convert to ansi order
    color_id = _win_to_ansi_offset_map.get(color_id, color_id)
    log.debug('ansi color_id: %d', color_id)
    return color_id