a
    õ£Be&  ã                   @  sn  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rÔd dl%m&Z& g d¢Z'ddddddddddœ	ddddddddddddœd d!„Zd2d"ddddd#œd$d%„Z(ddd&d'œd(d)„Z)dd*œd+d,„Z*ddd-œd.d/„Z+dd*œd0d1„Z,dS )3é    )Ú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_styler   ÚstrzTextIO | NoneÚboolzBaseStyle | NonezOutput | NonezColorDepth | NonezStyleTransformation | NoneÚNone)Úvaluesr!   r"   r#   r$   r%   r&   r'   r(   r)   Úreturnc        	           s  ˆr|rJ ‚ˆdu r,|r$t |d�‰ntƒ j‰tˆtƒs:J ‚ˆ pDˆ ¡ ‰ dddœdd„}
g ‰t|	ƒD ]8\}}ˆ |
|ƒ¡ | rb|t|	ƒd krbˆ |
| ƒ¡ qbˆ |
|ƒ¡ d	d
œ‡ ‡‡‡‡‡‡fdd„‰d}t	ƒ }|durà|j
}|durü| ‡fdd„¡ nˆƒ  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©Ústdoutr   r   )Úvalr.   c                 S  s*   t | tƒrt | tƒst| › ƒS t| dd�S )NT)Zauto_convert)Ú
isinstanceÚlistr   r   )r1   © r4   úa/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/prompt_toolkit/shortcuts/utils.pyÚto_textw   s    
z%print_formatted_text.<locals>.to_texté   r,   ©r.   c                     s8   t ˆtƒsJ ‚tˆˆtˆˆd�ˆ ˆd� ˆr4ˆ ¡  d S )N©r)   )r'   r(   )r2   r   Úrenderer_print_formatted_textÚ_create_merged_styler$   r4   )r'   r$   Ú	fragmentsr)   r&   r%   r(   r4   r5   Úrenderˆ   s    ÿùz$print_formatted_text.<locals>.renderc                     s   t ˆ ƒS )Nr
   r4   )r=   r4   r5   Ú<lambda>¢   ó    z&print_formatted_text.<locals>.<lambda>)r   r	   r&   r2   r   Zget_default_color_depthÚ	enumerateÚextendÚlenr   ÚloopÚcall_soon_threadsafe)r!   r"   r#   r$   r%   r&   r'   r(   r)   r-   r6   ÚiÚvaluerC   Úappr4   )r'   r$   r<   r)   r&   r=   r%   r(   r5   r   )   s,    ?r   r   )Ú	containerr#   r%   r)   r.   c                 C  s`   |rt |d�}ntƒ j}tt| d�|tƒ t||d�d�}z|jdd� W n tyZ   Y n0 dS )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!')))
    r/   )rH   r9   )Zlayoutr&   Úinputr%   T)Z	in_threadN)	r   r	   r&   r   r   r   r;   ÚrunÚEOFError)rH   r#   r%   r)   r&   rG   r4   r4   r5   r   §   s    ÿû	r   r   )r%   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)   Ústylesr4   r4   r5   r;   Ê   s    
r;   r8   c                  C  s(   t ƒ j} |  ¡  |  dd¡ |  ¡  dS )z
    Clear the screen.
    r   N)r	   r&   Zerase_screenZcursor_gotor$   )r&   r4   r4   r5   r   Ù   s    r   )Útextr.   c                 C  s   t ƒ j}| | ¡ dS )z!
    Set the terminal title.
    N)r	   r&   r   )rN   r&   r4   r4   r5   r   ã   s    r   c                   C  s   t dƒ dS )z"
    Erase the current title.
    Ú N)r   r4   r4   r4   r5   r   ë   s    r   )NNT)-Ú
__future__r   Zasyncio.eventsr   Útypingr   r   r   Zprompt_toolkit.applicationr   Z"prompt_toolkit.application.currentr   r	   Z*prompt_toolkit.application.run_in_terminalr   Zprompt_toolkit.formatted_textr   r   r   Zprompt_toolkit.inputr   Zprompt_toolkit.layoutr   Zprompt_toolkit.outputr   r   Zprompt_toolkit.output.defaultsr   Zprompt_toolkit.rendererr   r:   Zprompt_toolkit.stylesr   r   r   r   r   Z prompt_toolkit.layout.containersr   Ú__all__r   r;   r   r   r   r4   r4   r4   r5   Ú<module>   sD   ö&    ü#
