# Path: src/click/_compat.py
# class _NonClosingTextIOWrapper(io.TextIOWrapper):
#     def __init__(
#         self,
#         stream: t.BinaryIO,
#         encoding: t.Optional[str],
#         errors: t.Optional[str],
#         force_readable: bool = False,
#         force_writable: bool = False,
#         **extra: t.Any,
#     ) -> None:
#         self._stream = stream = t.cast(
#             t.BinaryIO, _FixupStream(stream, force_readable, force_writable)
#         )
#         super().__init__(stream, encoding, errors, **extra)
# 
#     def __del__(self) -> None:
#         try:
#             self.detach()
#         except Exception:
#             pass
# 
#     def isatty(self) -> bool:
#         # https://bitbucket.org/pypy/pypy/issue/1803
#         return self._stream.isatty()


import io
import sys
import time
import typing as t
import msvcrt  # noqa: E402
from ctypes import byref
from ctypes import c_char
from ctypes import c_char_p
from ctypes import c_int
from ctypes import c_ssize_t
from ctypes import c_ulong
from ctypes import c_void_p
from ctypes import POINTER
from ctypes import py_object
from ctypes import Structure
from ctypes.wintypes import DWORD
from ctypes.wintypes import HANDLE
from ctypes.wintypes import LPCWSTR
from ctypes.wintypes import LPWSTR
from ._compat import _NonClosingTextIOWrapper
from ctypes import windll  # noqa: E402
from ctypes import WINFUNCTYPE  # noqa: E402
    from ctypes import pythonapi
        try:
            buffer_type = c_char * buf.len
            return buffer_type.from_address(buf.buf)
        finally:
            PyBuffer_Release(byref(buf))


class _WindowsConsoleRawIOBase(io.RawIOBase):
    def __init__(self, handle):
        self.handle = handle

    def isatty(self):
        super().isatty()
        return True


class _WindowsConsoleReader(_WindowsConsoleRawIOBase):
    def readable(self):
        return True

    def readinto(self, b):
        bytes_to_be_read = len(b)
        if not bytes_to_be_read:
            return 0
        elif bytes_to_be_read % 2:
            raise ValueError(
                "cannot read odd number of bytes from UTF-16-LE encoded console"
            )

        buffer = get_buffer(b, writable=True)

# Path: src/click/_compat.py
# class _NonClosingTextIOWrapper(io.TextIOWrapper):
#     def __init__(
#         self,
#         stream: t.BinaryIO,
#         encoding: t.Optional[str],
#         errors: t.Optional[str],
#         force_readable: bool = False,
#         force_writable: bool = False,
#         **extra: t.Any,
#     ) -> None:
#         self._stream = stream = t.cast(
#             t.BinaryIO, _FixupStream(stream, force_readable, force_writable)
#         )
#         super().__init__(stream, encoding, errors, **extra)
# 
#     def __del__(self) -> None:
#         try:
#             self.detach()
#         except Exception:
#             pass
# 
#     def isatty(self) -> bool:
#         # https://bitbucket.org/pypy/pypy/issue/1803
#         return self._stream.isatty()


# Path: src/click/_winconsole.py
import io
import sys
import time
import typing as t
import msvcrt  # noqa: E402
from ctypes import byref
from ctypes import c_char
from ctypes import c_char_p
from ctypes import c_int
from ctypes import c_ssize_t
from ctypes import c_ulong
from ctypes import c_void_p
from ctypes import POINTER
from ctypes import py_object
from ctypes import Structure
from ctypes.wintypes import DWORD
from ctypes.wintypes import HANDLE
from ctypes.wintypes import LPCWSTR
from ctypes.wintypes import LPWSTR
from ._compat import _NonClosingTextIOWrapper
from ctypes import windll  # noqa: E402
from ctypes import WINFUNCTYPE  # noqa: E402
    from ctypes import pythonapi

        try:
            buffer_type = c_char * buf.len
            return buffer_type.from_address(buf.buf)
        finally:
            PyBuffer_Release(byref(buf))


class _WindowsConsoleRawIOBase(io.RawIOBase):
    def __init__(self, handle):
        self.handle = handle

    def isatty(self):
        super().isatty()
        return True


class _WindowsConsoleReader(_WindowsConsoleRawIOBase):
    def readable(self):
        return True

    def readinto(self, b):
        bytes_to_be_read = len(b)
        if not bytes_to_be_read:
            return 0
        elif bytes_to_be_read % 2:
            raise ValueError(
                "cannot read odd number of bytes from UTF-16-LE encoded console"
            )

        buffer = get_buffer(b, writable=True)

        code_units_to_be_read = bytes_to_be_read // 2