# Path: src/click/_compat.py
# def term_len(x: str) -> int:
#     return len(strip_ansi(x))
# 
# Path: src/click/parser.py
# def split_opt(opt: str) -> t.Tuple[str, str]:
#     first = opt[:1]
#     if first.isalnum():
#         return "", opt
#     if opt[1:2] == first:
#         return opt[:2], opt[2:]
#     return first, opt[1:]


import typing as t
        import shutil
from contextlib import contextmanager
from gettext import gettext as _
from ._compat import term_len
from .parser import split_opt
    from ._textwrap import TextWrapper

    text = text.expandtabs()
    wrapper = TextWrapper(
        width,
        initial_indent=initial_indent,
        subsequent_indent=subsequent_indent,
        replace_whitespace=False,
    )
    if not preserve_paragraphs:
        return wrapper.fill(text)

    p: t.List[t.Tuple[int, bool, str]] = []
    buf: t.List[str] = []
    indent = None

    def _flush_par() -> None:
        if not buf:
            return
        if buf[0].strip() == "\b":
            p.append((indent or 0, True, "\n".join(buf[1:])))
        else:
            p.append((indent or 0, False, " ".join(buf)))
        del buf[:]

    for line in text.splitlines():
        if not line:
            _flush_par()
            indent = None
        else:
            if indent is None:

# Path: src/click/_compat.py
# def term_len(x: str) -> int:
#     return len(strip_ansi(x))
# 
# Path: src/click/parser.py
# def split_opt(opt: str) -> t.Tuple[str, str]:
#     first = opt[:1]
#     if first.isalnum():
#         return "", opt
#     if opt[1:2] == first:
#         return opt[:2], opt[2:]
#     return first, opt[1:]


# Path: src/click/formatting.py
import typing as t
        import shutil
from contextlib import contextmanager
from gettext import gettext as _
from ._compat import term_len
from .parser import split_opt
    from ._textwrap import TextWrapper


    text = text.expandtabs()
    wrapper = TextWrapper(
        width,
        initial_indent=initial_indent,
        subsequent_indent=subsequent_indent,
        replace_whitespace=False,
    )
    if not preserve_paragraphs:
        return wrapper.fill(text)

    p: t.List[t.Tuple[int, bool, str]] = []
    buf: t.List[str] = []
    indent = None

    def _flush_par() -> None:
        if not buf:
            return
        if buf[0].strip() == "\b":
            p.append((indent or 0, True, "\n".join(buf[1:])))
        else:
            p.append((indent or 0, False, " ".join(buf)))
        del buf[:]

    for line in text.splitlines():
        if not line:
            _flush_par()
            indent = None
        else:
            if indent is None:

                orig_len = term_len(line)