o
    w¨Êh*  ã                   @  s  d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ er.d dlmZ d dlmZ g d¢Ze	eeef eeeeegdf f f Zee ZerZd dlmZ G d	d
„ d
eƒZe	ed
eeg ef df Z	d#d$dd„Zd%dd„ZG dd„ deƒZG dd„ dƒZd&d!d"„ZdS )'é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚCallableÚIterableÚListÚTupleÚUnionÚcast)Ú
MouseEvent)ÚProtocol)ÚNotImplementedOrNone)	ÚOneStyleAndTextTupleÚStyleAndTextTuplesÚMagicFormattedTextÚAnyFormattedTextÚto_formatted_textÚis_formatted_textÚTemplateÚmerge_formatted_textÚFormattedTextr   )Ú	TypeGuardc                   @  s   e Zd ZdZddd„ZdS )r   zi
        Any object that implements ``__pt_formatted_text__`` represents formatted
        text.
        Úreturnr   c                 C  s   d S ©N© ©Úselfr   r   úT/var/www/html/env/lib/python3.10/site-packages/prompt_toolkit/formatted_text/base.pyÚ__pt_formatted_text__)   s    z(MagicFormattedText.__pt_formatted_text__N©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   #   s    r   NÚ FÚvaluer   ÚstyleÚstrÚauto_convertÚboolr   r   c                   s¶   | du rg }n;t | tƒrd| fg}n0t | tƒr| }n(t| dƒr'td| ƒ ¡ }nt| ƒr2t| ƒ ˆ d�S |r;d| › fg}ntd| ›�ƒ‚ˆ rPtt	‡ fdd„|D ƒƒ}t |t
ƒrW|S t
|ƒS )	at  
    Convert the given value (which can be formatted text) into a list of text
    fragments. (Which is the canonical form of formatted text.) The outcome is
    always a `FormattedText` instance, which is a list of (style, text) tuples.

    It can take a plain text string, an `HTML` or `ANSI` object, anything that
    implements `__pt_formatted_text__` or a callable that takes no arguments and
    returns one of those.

    :param style: An additional style string which is applied to all text
        fragments.
    :param auto_convert: If `True`, also accept other types, and convert them
        to a string first.
    Nr$   r   r   ©r&   z[No formatted text. Expecting a unicode object, HTML, ANSI or a FormattedText instance. Got c                   s$   g | ]^}}ˆ d  | g|¢R ‘qS )ú r   )Ú.0Ú
item_styleÚrestr*   r   r   Ú
<listcomp>_   s   $ z%to_formatted_text.<locals>.<listcomp>)Ú
isinstancer'   ÚlistÚhasattrr
   r   Úcallabler   Ú
ValueErrorr   r   )r%   r&   r(   Úresultr   r*   r   r   6   s2   


ÿÿþ
r   ÚobjectúTypeGuard[AnyFormattedText]c                 C  s0   t | ƒrdS t| ttfƒrdS t| dƒrdS dS )zš
    Check whether the input is valid formatted text (for use in assert
    statements).
    In case of a callable, it doesn't check the return type.
    Tr   F)r3   r0   r'   r1   r2   )r%   r   r   r   r   k   s   
r   c                      s,   e Zd ZdZd	dd„Zd
‡ fdd„Z‡  ZS )r   z†
    A list of ``(style, text)`` tuples.

    (In some situations, this can also be ``(style, text, mouse_handler)``
    tuples.)
    r   r   c                 C  s   | S r   r   r   r   r   r   r   ‚   s   z#FormattedText.__pt_formatted_text__r'   c                   s   dt ƒ  ¡ › d�S )NzFormattedText(ú))ÚsuperÚ__repr__r   ©Ú	__class__r   r   r:   …   s   zFormattedText.__repr__r   )r   r'   )r    r!   r"   r#   r   r:   Ú__classcell__r   r   r;   r   r   z   s    
c                   @  s$   e Zd ZdZddd„Zdd
d„ZdS )r   z¡
    Template for string interpolation with formatted text.

    Example::

        Template(' ... {} ... ').format(HTML(...))

    :param text: Plain text.
    Útextr'   r   ÚNonec                 C  s   d|vsJ ‚|| _ d S )Nz{0})r>   )r   r>   r   r   r   Ú__init__”   s   
zTemplate.__init__Úvaluesr   c                   s   d‡ ‡fdd„}|S )Nr   r   c                    sp   ˆ j  d¡} t| ƒd tˆƒksJ ‚tƒ }t| ˆƒD ]\}}| d|f¡ | t|ƒ¡ q| d| d f¡ |S )Nz{}é   r$   éÿÿÿÿ)r>   ÚsplitÚlenr   ÚzipÚappendÚextendr   )Úpartsr5   ÚpartÚval©r   rA   r   r   Ú
get_result™   s   z#Template.format.<locals>.get_result©r   r   r   )r   rA   rM   r   rL   r   Úformat˜   s   zTemplate.formatN)r>   r'   r   r?   )rA   r   r   r   )r    r!   r"   r#   r@   rO   r   r   r   r   r   ‰   s    

r   ÚitemsúIterable[AnyFormattedText]c                   s   d‡ fdd„}|S )zH
    Merge (Concatenate) several pieces of formatted text together.
    r   r   c                    s"   t ƒ } ˆ D ]	}|  t|ƒ¡ q| S r   )r   rH   r   )r5   Úi©rP   r   r   Ú_merge_formatted_text­   s   z3merge_formatted_text.<locals>._merge_formatted_textNrN   r   )rP   rT   r   rS   r   r   ¨   s   r   )r$   F)r%   r   r&   r'   r(   r)   r   r   )r%   r6   r   r7   )rP   rQ   r   r   )Ú
__future__r   Útypingr   r   r   r   r   r   r	   r
   Úprompt_toolkit.mouse_eventsr   Útyping_extensionsr   Ú'prompt_toolkit.key_binding.key_bindingsr   Ú__all__r'   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s8    ("ÿ	
ûÿÿ
5