
    f*                    :   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rd dlmZ  G d	 d
e      Ze	ed
eeg ef   df   Z	 d	 	 	 	 	 	 	 ddZddZ G d de      Z G d d      ZddZy)    )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                      e Zd ZdZddZy)r   zi
        Any object that implements ``__pt_formatted_text__`` represents formatted
        text.
        c                     y N selfs    ]/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/formatted_text/base.py__pt_formatted_text__z(MagicFormattedText.__pt_formatted_text__)   s        Nreturnr   )__name__
__module____qualname____doc__r    r   r!   r   r   r   #   s    	
 	Cr!   r   Nr   c           	        | g }nt        | t              rd| fg}nnt        | t              r| }n[t        | d      rt	        d|       j                         }n4t        |       rt         |        |      S |rd|  fg}nt        d|       |r,t	        t        |D cg c]  ^}}|dz   |z   g| c}}      }t        |t              r|S t        |      S c c}}w )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.
     r    r   )stylez[No formatted text. Expecting a unicode object, HTML, ANSI or a FormattedText instance. Got  )
isinstancestrlisthasattrr   r    callabler   
ValueErrorr   r   )valuer*   auto_convertresult
item_stylerests         r   r   r   6   s    & }	E3	u+	E4	 	/	0*E2HHJ	% 66	%"#;;@)E
 	
 HNO3D:eckJ&..O
 &-(V$$ Ps   Cc                d    t        |       ryt        | t        t        f      ryt	        | d      ryy)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)r0   r,   r-   r.   r/   )r2   s    r   r   r   k   s0     %#t%u-.r!   c                  ,     e Zd ZdZddZd fdZ xZS )r   z
    A list of ``(style, text)`` tuples.

    (In some situations, this can also be ``(style, text, mouse_handler)``
    tuples.)
    c                    | S r   r   r   s    r   r    z#FormattedText.__pt_formatted_text__   s    r!   c                (    dt         |           dS )NzFormattedText())super__repr__)r   	__class__s    r   r=   zFormattedText.__repr__   s     0 23155r!   r"   )r#   r-   )r$   r%   r&   r'   r    r=   __classcell__)r>   s   @r   r   r   z   s    6 6r!   c                       e Zd ZdZddZddZy)r   z
    Template for string interpolation with formatted text.

    Example::

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

    :param text: Plain text.
    c                    d|vsJ || _         y )Nz{0})text)r   rB   s     r   __init__zTemplate.__init__   s    D   	r!   c                     d fd}|S )Nc                 8   j                   j                  d      } t        |       dz
  t              k(  sJ t               }t	        |       D ]2  \  }}|j                  d|f       |j                  t        |             4 |j                  d| d   f       |S )Nz{}   r)   )rB   splitlenr   zipappendextendr   )partsr4   partvalr   valuess       r   
get_resultz#Template.format.<locals>.get_result   s    IIOOD)Eu:>S[000"_F / 6	cr4j)/456 MM2uRy/*Mr!   r#   r   r   )r   rP   rQ   s   `` r   formatzTemplate.format   s    
	 r!   N)rB   r-   r#   None)rP   r   r#   r   )r$   r%   r&   r'   rC   rS   r   r!   r   r   r      s    r!   r   c                     d fd}|S )zH
    Merge (Concatenate) several pieces of formatted text together.
    c                 ^    t               } D ]  }| j                  t        |              | S r   )r   rL   r   )r4   iitemss     r   _merge_formatted_textz3merge_formatted_text.<locals>._merge_formatted_text   s0     	0AMM+A./	0r!   rR   r   )rX   rY   s   ` r   r   r      s    
 ! r!   )r)   F)r2   r   r*   r-   r3   boolr#   r   )r2   objectr#   zTypeGuard[AnyFormattedText])rX   zIterable[AnyFormattedText]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   <module>rb      s    " S S S 2*L
 	#s(OU3Xzl<R.R%SSTT 
 ./  +CX C RW
  DI2%2%$'2%<@2%2%j6& 6 >!r!   