Query the default terminal, for colors, etc.

        Direct queries supported on xterm, iTerm, perhaps others.

        Arguments:
            str:  name,  one of ('foreground', 'fg', 'background', 'bg',
                                 or 'index')  # index grabs a palette index
            int:  or a "dynamic color number of (4, 10-19)," see links below.
            str:  number - if name is index, number should be an int from 0…255

        Queries terminal using ``OSC # ? BEL`` sequence,
        call responds with a color in this X Window format syntax:

            - ``rgb:DEAD/BEEF/CAFE``
            - `Control sequences
              <http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands>`_
            - `X11 colors
              <https://www.x.org/releases/X11R7.7/doc/libX11/libX11/libX11.html#RGB_Device_String_Specification>`_

        Returns:
            tuple[int]: 
                A tuple of four-digit hex strings after parsing,
                the last two digits are the least significant and can be
                chopped if needed:

                ``('DEAD', 'BEEF', 'CAFE')``

                If an error occurs during retrieval or parsing,
                the tuple will be empty.

        Examples:
            >>> get_color('bg')
            ('0000', '0000', '0000')

            >>> get_color('index', 2)   # second color in indexed
            ('4e4d', '9a9a', '0605')    # palette, 2 aka 32 in basic

        Note:
            Blocks if terminal does not support the function.
            Checks is_a_tty() first, since function would also block if i/o
            were redirected through a pipe.

            On Windows, only able to find palette defaults,
            which may be different if they were customized.
            To find the palette index instead,
            see ``windows.get_color``.

def get_color(name, number=None):
    ''' Query the default terminal, for colors, etc.

        Direct queries supported on xterm, iTerm, perhaps others.

        Arguments:
            str:  name,  one of ('foreground', 'fg', 'background', 'bg',
                                 or 'index')  # index grabs a palette index
            int:  or a "dynamic color number of (4, 10-19)," see links below.
            str:  number - if name is index, number should be an int from 0…255

        Queries terminal using ``OSC # ? BEL`` sequence,
        call responds with a color in this X Window format syntax:

            - ``rgb:DEAD/BEEF/CAFE``
            - `Control sequences
              <http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands>`_
            - `X11 colors
              <https://www.x.org/releases/X11R7.7/doc/libX11/libX11/libX11.html#RGB_Device_String_Specification>`_

        Returns:
            tuple[int]: 
                A tuple of four-digit hex strings after parsing,
                the last two digits are the least significant and can be
                chopped if needed:

                ``('DEAD', 'BEEF', 'CAFE')``

                If an error occurs during retrieval or parsing,
                the tuple will be empty.

        Examples:
            >>> get_color('bg')
            ('0000', '0000', '0000')

            >>> get_color('index', 2)   # second color in indexed
            ('4e4d', '9a9a', '0605')    # palette, 2 aka 32 in basic

        Note:
            Blocks if terminal does not support the function.
            Checks is_a_tty() first, since function would also block if i/o
            were redirected through a pipe.

            On Windows, only able to find palette defaults,
            which may be different if they were customized.
            To find the palette index instead,
            see ``windows.get_color``.
    '''
    colors = ()
    if is_a_tty() and not env.SSH_CLIENT:
        if not 'index' in _color_code_map:
            _color_code_map['index'] = '4;' + str(number or '')

        if os_name == 'nt':
            from .windows import get_color
            color_id = get_color(name)
            if sys.getwindowsversion()[2] > 16299:  # Win10 FCU, new palette
                basic_palette = color_tables.cmd1709_palette4
            else:
                basic_palette = color_tables.cmd_palette4
            colors = (f'{i:02x}' for i in basic_palette[color_id]) # compat

        elif sys.platform == 'darwin':
            if env.TERM_PROGRAM == 'iTerm.app':
                # supports, though returns two chars per
                colors = _get_color_xterm(name, number)

        elif os_name == 'posix':
            if sys.platform.startswith('freebsd'):
                pass
            elif env.TERM and env.TERM.startswith('xterm'):
                colors = _get_color_xterm(name, number)

    return tuple(colors)