(links: List[Link], extra: int = 0, **kwargs: Any)
return _wrap_link
Per wrap, except links are rendered without affecting the wrap width.

        In addition to the specification of process_wrap, a sequence of "link" values controls link processing.

        Links are only rendered if the terminal is a known supporting terminal for OSC8 links. If not,
        links are rendered as their anchor text only.

        :param links: Link definitions
        :param extra: Any extra width to apply
        :param kwargs: Styling rules passed to text
Per wrap, except links are rendered without affecting the wrap width.
Per wrap except links are rendered without affecting the wrap width .
def wrap_link(links: List[Link], extra: int = 0, **kwargs: Any) -> Processor:
        """
        Per wrap, except links are rendered without affecting the wrap width.

        In addition to the specification of process_wrap, a sequence of "link" values controls link processing.

        Links are only rendered if the terminal is a known supporting terminal for OSC8 links. If not,
        links are rendered as their anchor text only.

        :param links: Link definitions
        :param extra: Any extra width to apply
        :param kwargs: Styling rules passed to text
        """

        def _wrap_link(text: str) -> str:
            wrapped = bento.util.wrap(text, extra)

            def find_loc(anchor: str) -> Tuple[int, str]:
                """
                Finds the position of the anchor string in the wrapped text

                Note that the anchor string itself may be wrapped, so we return
                both the position, and the value of the (possibly wrapped) anchor string.
                """
                pos = wrapped.find(anchor)
                if pos < 0:
                    # Text was likely wrapped
                    anchor_it = [
                        f"{anchor[:ix].rstrip()}\n{anchor[ix:]}"
                        for ix in range(len(anchor))
                    ]
                    pos_it = ((wrapped.find(a), a) for a in anchor_it)
                    pos, anchor = next(
                        ((p, a) for p, a in pos_it if p > 0), (-1, anchor)
                    )
                    if pos < 0:
                        raise ValueError(f"'{anchor}' does not appear in '{text}'")
                return pos, anchor

            with_locs = sorted(
                [(find_loc(link.anchor), link.href) for link in links],
                key=(lambda t: t[0][0]),
            )
            out = ""
            current = 0
            for loc_anchor, href in with_locs:
                loc, anchor = loc_anchor
                out += style(wrapped[current:loc], **kwargs)
                out += bento.util.render_link(
                    anchor, href, print_alternative=False, pipe=sys.stderr
                )
                current = loc + len(anchor)
            out += style(wrapped[current:], **kwargs)

            return out

        return _wrap_link
def wrap_link ( links : List [ Link ] , extra : int = 0 , * * kwargs : Any ) -> Processor : def _wrap_link ( text : str ) -> str : wrapped = bento . util . wrap ( text , extra ) def find_loc ( anchor : str ) -> Tuple [ int , str ] : """
                Finds the position of the anchor string in the wrapped text

                Note that the anchor string itself may be wrapped, so we return
                both the position, and the value of the (possibly wrapped) anchor string.
                """ pos = wrapped . find ( anchor ) if pos < 0 : # Text was likely wrapped anchor_it = [ f"{anchor[:ix].rstrip()}\n{anchor[ix:]}" for ix in range ( len ( anchor ) ) ] pos_it = ( ( wrapped . find ( a ) , a ) for a in anchor_it ) pos , anchor = next ( ( ( p , a ) for p , a in pos_it if p > 0 ) , ( - 1 , anchor ) ) if pos < 0 : raise ValueError ( f"'{anchor}' does not appear in '{text}'" ) return pos , anchor with_locs = sorted ( [ ( find_loc ( link . anchor ) , link . href ) for link in links ] , key = ( lambda t : t [ 0 ] [ 0 ] ) , ) out = "" current = 0 for loc_anchor , href in with_locs : loc , anchor = loc_anchor out += style ( wrapped [ current : loc ] , * * kwargs ) out += bento . util . render_link ( anchor , href , print_alternative = False , pipe = sys . stderr ) current = loc + len ( anchor ) out += style ( wrapped [ current : ] , * * kwargs ) return out return _wrap_link