o
    Zh8                     @  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   Y/var/www/html/lang_env/lib/python3.10/site-packages/prompt_toolkit/formatted_text/base.py__pt_formatted_text__)      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   ).0Z
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   7   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   l   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      r   z#FormattedText.__pt_formatted_text__r(   c                   s   dt    S )NzFormattedText(%s))super__repr__r   	__class__r   r   r9      s   zFormattedText.__repr__r    )r   r(   )r!   r"   r#   r$   r   r9   __classcell__r   r   r:   r   r   {   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   r@   r   r   
get_result   s   z#Template.format.<locals>.get_resultr   r   r   )r   r@   rL   r   rK   r   format   s   zTemplate.formatN)r=   r(   r   r>   )r@   r   r   r   )r!   r"   r#   r$   r?   rN   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   rG   r   )r5   irO   r   r   _merge_formatted_text   s   z3merge_formatted_text.<locals>._merge_formatted_textNrM   r   )rO   rS   r   rR   r   r      s   r   )r%   F)r&   r   r'   r(   r)   r*   r   r   )r&   r6   r   r7   )rO   rP   r   r   )
__future__r   typingr   r   r   r   r   r   r	   r
   Zprompt_toolkit.mouse_eventsr   typing_extensionsr   Z'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