# 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
        return getattr(self._text_stream, name)

    def isatty(self) -> bool:
        return self.buffer.isatty()

    def __repr__(self):
        return f"<ConsoleStream name={self.name!r} encoding={self.encoding!r}>"


def _get_text_stdin(buffer_stream: t.BinaryIO) -> t.TextIO:
    text_stream = _NonClosingTextIOWrapper(
        io.BufferedReader(_WindowsConsoleReader(STDIN_HANDLE)),
        "utf-16-le",
        "strict",
        line_buffering=True,
    )
    return t.cast(t.TextIO, ConsoleStream(text_stream, buffer_stream))


def _get_text_stdout(buffer_stream: t.BinaryIO) -> t.TextIO:
    text_stream = _NonClosingTextIOWrapper(
        io.BufferedWriter(_WindowsConsoleWriter(STDOUT_HANDLE)),
        "utf-16-le",
        "strict",
        line_buffering=True,
    )
    return t.cast(t.TextIO, ConsoleStream(text_stream, buffer_stream))


def _get_text_stderr(buffer_stream: t.BinaryIO) -> t.TextIO:

# 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

        return getattr(self._text_stream, name)

    def isatty(self) -> bool:
        return self.buffer.isatty()

    def __repr__(self):
        return f"<ConsoleStream name={self.name!r} encoding={self.encoding!r}>"


def _get_text_stdin(buffer_stream: t.BinaryIO) -> t.TextIO:
    text_stream = _NonClosingTextIOWrapper(
        io.BufferedReader(_WindowsConsoleReader(STDIN_HANDLE)),
        "utf-16-le",
        "strict",
        line_buffering=True,
    )
    return t.cast(t.TextIO, ConsoleStream(text_stream, buffer_stream))


def _get_text_stdout(buffer_stream: t.BinaryIO) -> t.TextIO:
    text_stream = _NonClosingTextIOWrapper(
        io.BufferedWriter(_WindowsConsoleWriter(STDOUT_HANDLE)),
        "utf-16-le",
        "strict",
        line_buffering=True,
    )
    return t.cast(t.TextIO, ConsoleStream(text_stream, buffer_stream))


def _get_text_stderr(buffer_stream: t.BinaryIO) -> t.TextIO:

    text_stream = _NonClosingTextIOWrapper(