o
    �õ±j&  ã                
   @  s:  d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZmZmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZ d dlmZ d dlm Z m!Z!m"Z"m#Z#m$Z$ erjd dl%m&Z& g d¢Z'ddddddddddœ	d:d*d+„Z			d;d<d.d/„Z(d=d1d2„Z)d>d3d4„Z*d?d6d7„Z+d>d8d9„Z,dS )@é    )Úannotations)ÚAbstractEventLoop)ÚTYPE_CHECKINGÚAnyÚTextIO)ÚApplication)Úget_app_or_noneÚget_app_session©Úrun_in_terminal)ÚFormattedTextÚStyleAndTextTuplesÚto_formatted_text)Ú
DummyInput)ÚLayout)Ú
ColorDepthÚOutput)Úcreate_output)Úprint_formatted_text)Ú	BaseStyleÚStyleTransformationÚdefault_pygments_styleÚdefault_ui_styleÚmerge_styles)ÚAnyContainer)r   Úprint_containerÚclearÚ	set_titleÚclear_titleú Ú
NFT)	ÚsepÚendÚfileÚflushÚstyleÚoutputÚcolor_depthÚstyle_transformationÚinclude_default_pygments_styleÚvaluesr   r!   Ústrr"   r#   úTextIO | Noner$   Úboolr%   úBaseStyle | Noner&   úOutput | Noner'   úColorDepth | Noner(   úStyleTransformation | Noner)   ÚreturnÚNonec        	           sþ   ˆr|rJ ‚ˆdu r|rt |d�‰ntƒ j‰tˆtƒsJ ‚ˆ p"ˆ ¡ ‰ ddd„}
g ‰t|	ƒD ]\}}ˆ |
|ƒ¡ | rJ|t|	ƒd	 krJˆ |
| ƒ¡ q.ˆ |
|ƒ¡ d‡ ‡‡‡‡‡‡fdd„‰d}t	ƒ }|durk|j
}|durz| ‡fdd„¡ dS ˆƒ  dS )aÝ  
    ::

        print_formatted_text(*values, sep=' ', end='\n', file=None, flush=False, style=None, output=None)

    Print text to stdout. This is supposed to be compatible with Python's print
    function, but supports printing of formatted text. You can pass a
    :class:`~prompt_toolkit.formatted_text.FormattedText`,
    :class:`~prompt_toolkit.formatted_text.HTML` or
    :class:`~prompt_toolkit.formatted_text.ANSI` object to print formatted
    text.

    * Print HTML as follows::

        print_formatted_text(HTML('<i>Some italic text</i> <ansired>This is red!</ansired>'))

        style = Style.from_dict({
            'hello': '#ff0066',
            'world': '#884444 italic',
        })
        print_formatted_text(HTML('<hello>Hello</hello> <world>world</world>!'), style=style)

    * Print a list of (style_str, text) tuples in the given style to the
      output.  E.g.::

        style = Style.from_dict({
            'hello': '#ff0066',
            'world': '#884444 italic',
        })
        fragments = FormattedText([
            ('class:hello', 'Hello'),
            ('class:world', 'World'),
        ])
        print_formatted_text(fragments, style=style)

    If you want to print a list of Pygments tokens, wrap it in
    :class:`~prompt_toolkit.formatted_text.PygmentsTokens` to do the
    conversion.

    If a prompt_toolkit `Application` is currently running, this will always
    print above the application or prompt (similar to `patch_stdout`). So,
    `print_formatted_text` will erase the current application, print the text,
    and render the application again.

    :param values: Any kind of printable object, or formatted string.
    :param sep: String inserted between values, default a space.
    :param end: String appended after the last value, default a newline.
    :param style: :class:`.Style` instance for the color scheme.
    :param include_default_pygments_style: `bool`. Include the default Pygments
        style when set to `True` (the default).
    N©ÚstdoutÚvalr   r2   r   c                 S  s*   t | tƒrt | tƒst| › ƒS t| dd�S )NT)Úauto_convert)Ú
isinstanceÚlistr   r   )r6   © r:   ú‘/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/prompt_toolkit/shortcuts/utils.pyÚto_textw   s   
z%print_formatted_text.<locals>.to_texté   r3   c                     s<   t ˆtƒsJ ‚tˆˆtˆˆd�ˆ ˆd� ˆrˆ ¡  d S d S )N©r)   )r'   r(   )r8   r   Úrenderer_print_formatted_textÚ_create_merged_styler$   r:   )r'   r$   Ú	fragmentsr)   r&   r%   r(   r:   r;   Úrenderˆ   s   ÿùÿz$print_formatted_text.<locals>.renderc                     s   t ˆ ƒS )Nr
   r:   )rB   r:   r;   Ú<lambda>¢   s    z&print_formatted_text.<locals>.<lambda>)r6   r   r2   r   ©r2   r3   )r   r	   r&   r8   r   Úget_default_color_depthÚ	enumerateÚextendÚlenr   ÚloopÚcall_soon_threadsafe)r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r<   ÚiÚvaluerI   Úappr:   )r'   r$   rA   r)   r&   rB   r%   r(   r;   r   )   s.   ?
€
r   Ú	containerr   c                 C  s`   |rt |d�}ntƒ j}tt| d�|tƒ t||d�d�}z	|jdd� W dS  ty/   Y dS w )zÞ
    Print any layout to the output in a non-interactive way.

    Example usage::

        from prompt_toolkit.widgets import Frame, TextArea
        print_container(
            Frame(TextArea(text='Hello world!')))
    r4   )rN   r>   )Úlayoutr&   Úinputr%   T)Ú	in_threadN)	r   r	   r&   r   r   r   r@   ÚrunÚEOFError)rN   r#   r%   r)   r&   rM   r:   r:   r;   r   §   s    ÿû	ÿr   r   c                 C  s.   t ƒ g}|r| tƒ ¡ | r| | ¡ t|ƒS )z7
    Merge user defined style with built-in style.
    )r   Úappendr   r   )r%   r)   Ústylesr:   r:   r;   r@   Ê   s   
r@   c                  C  s(   t ƒ j} |  ¡  |  dd¡ |  ¡  dS )z
    Clear the screen.
    r   N)r	   r&   Úerase_screenÚcursor_gotor$   )r&   r:   r:   r;   r   Ù   s   r   Útextc                 C  s   t ƒ j}| | ¡ dS )z!
    Set the terminal title.
    N)r	   r&   r   )rX   r&   r:   r:   r;   r   ã   s   r   c                   C  s   t dƒ dS )z"
    Erase the current title.
    Ú N)r   r:   r:   r:   r;   r   ë   s   r   )r*   r   r!   r+   r"   r+   r#   r,   r$   r-   r%   r.   r&   r/   r'   r0   r(   r1   r)   r-   r2   r3   )NNT)
rN   r   r#   r,   r%   r.   r)   r-   r2   r3   )r%   r.   r)   r-   r2   r   rD   )rX   r+   r2   r3   )-Ú
__future__r   Úasyncio.eventsr   Útypingr   r   r   Úprompt_toolkit.applicationr   Ú"prompt_toolkit.application.currentr   r	   Ú*prompt_toolkit.application.run_in_terminalr   Úprompt_toolkit.formatted_textr   r   r   Úprompt_toolkit.inputr   Úprompt_toolkit.layoutr   Úprompt_toolkit.outputr   r   Úprompt_toolkit.output.defaultsr   Úprompt_toolkit.rendererr   r?   Úprompt_toolkit.stylesr   r   r   r   r   Ú prompt_toolkit.layout.containersr   Ú__all__r   r@   r   r   r   r:   r:   r:   r;   Ú<module>   sF    ö ü
#


