
    Mh*                    j   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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                      e Zd ZdZddZdS )r   zi
        Any object that implements ``__pt_formatted_text__`` represents formatted
        text.
        returnr   c                    d S N selfs    b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/formatted_text/base.py__pt_formatted_text__z(MagicFormattedText.__pt_formatted_text__)   s          Nr   r   )__name__
__module____qualname____doc__r!   r   r"   r    r   r   #   s)        	 	
 	CBBBBBr"   r   N Fvaluer   stylestrauto_convertboolr   r   c                   | g }nt          | t                    rd| fg}nt          | t                    r| }nvt          | d          r#t	          d|                                           }nCt          |           rt           |                       S |rd|  fg}nt          d|           r!t	          t          fd|D                       }t          |t                    r|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                ,    g | ]^}}d z   |z   g|R S ) r   ).0
item_stylerestr*   s      r    
<listcomp>z%to_formatted_text.<locals>.<listcomp>_   s2    OOO3D:eckJ&...OOOr"   )
isinstancer+   listhasattrr   r!   callabler   
ValueErrorr   r   )r)   r*   r,   results    `  r    r   r   6   s;   & }	E3		 
u+	E4	 	  
	/	0	0 

*E22HHJJ	% 
 6666	 
%z"#E;@E E
 
 	
  
OOOOOOO
 
 &-(( %V$$$r"   objectTypeGuard[AnyFormattedText]c                    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)r8   r5   r+   r6   r7   )r)   s    r    r   r   k   sO      t%#t%% tu-.. t5r"   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.)
    r   r   c                    | S r   r   r   s    r    r!   z#FormattedText.__pt_formatted_text__   s    r"   r+   c                L    dt                                                       dS )NzFormattedText())super__repr__)r   	__class__s    r    rC   zFormattedText.__repr__   s$    5 0 0 2 25555r"   r#   )r   r+   )r$   r%   r&   r'   r!   rC   __classcell__)rD   s   @r    r   r   z   s[            6 6 6 6 6 6 6 6 6 6r"   c                  "    e Zd ZdZddZ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                     d|vsJ || _         d S )Nz{0})rG   )r   rG   s     r    __init__zTemplate.__init__   s    D    			r"   valuesr   c                     d fd}|S )Nr   r   c                 z   j                             d          } t          |           dz
  t                    k    sJ t                      }t	          |           D ]>\  }}|                    d|f           |                    t          |                     ?|                    d| d         f           |S )Nz{}   r(   )rG   splitlenr   zipappendextendr   )partsr:   partvalr   rK   s       r    
get_resultz#Template.format.<locals>.get_result   s    IOOD))Eu::>S[[0000"__F // 6 6	cr4j)))/445555MM2uRy/***Mr"   r   r   r   )r   rK   rX   s   `` r    formatzTemplate.format   s/    
	 
	 
	 
	 
	 
	 
	 r"   N)rG   r+   r   rH   )rK   r   r   r   )r$   r%   r&   r'   rJ   rZ   r   r"   r    r   r      sF                 r"   r   itemsIterable[AnyFormattedText]c                     d fd}|S )zH
    Merge (Concatenate) several pieces of formatted text together.
    r   r   c                 r    t                      } D ]$}|                     t          |                     %| S r   )r   rT   r   )r:   ir[   s     r    _merge_formatted_textz3merge_formatted_text.<locals>._merge_formatted_text   s>     	0 	0AMM+A..////r"   rY   r   )r[   r`   s   ` r    r   r      s)    
      ! r"   )r(   F)r)   r   r*   r+   r,   r-   r   r   )r)   r;   r   r<   )r[   r\   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>rg      s   " " " " " " S S S S S S S S S S S S S S S S S S S S 2 2 2 2 2 2 M******LLLLLL
 
 
 	#s(OU3Xzl<R.R%SSTT 
 ./   	C++++++C C C C CX C C C RW
  DI2% 2% 2% 2% 2%j   6 6 6 6 6& 6 6 6       >! ! ! ! ! !r"   