o
    ˷e]                     @   s  d dl mZ d dlmZ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 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rld dl&m'Z' g dZ(dddddddddd	dede)de)dee de*dee! dee dee dee" de*d dfd!d"Z			d0d#d$dee dee! de*d df
d%d&Z+dee! de*d e!fd'd(Z,d1d)d*Z-d+e)d dfd,d-Z.d1d.d/Z/dS )2    )AbstractEventLoop)TYPE_CHECKINGAnyOptionalTextIO)Application)get_app_or_noneget_app_sessionrun_in_terminal)get_event_loop)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#   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  p"  dtdtfdd}
g t|	D ]\}}	|
| | rN|t
|	d krN	|
|  q2	|
| d fdd	d}t }|duro|j}|dur~|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,   c                 S   s*   t | trt | tst|  S t| ddS )NT)auto_convert)
isinstancelistr   r   )r/    r3   U/var/www/ideatree/venv/lib/python3.10/site-packages/prompt_toolkit/shortcuts/utils.pyto_textv   s   
z%print_formatted_text.<locals>.to_text   c                      s<   t tsJ ttd d r  d S d S )Nr*   )r(   r)   )r1   r   renderer_print_formatted_text_create_merged_styler%   r3   )r(   r%   	fragmentsr*   r'   r&   r)   r3   r4   render   s   z$print_formatted_text.<locals>.renderc                      s   t  S )Nr
   r3   )r;   r3   r4   <lambda>   s    z&print_formatted_text.<locals>.<lambda>r,   N)r   r	   r'   r1   r   get_default_color_depthr   r   	enumerateextendlenr   loopcall_soon_threadsafe)r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r5   ivaluerB   appr3   )r(   r%   r:   r*   r'   r;   r&   r)   r4   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!')))
    r-   )rG   r7   )layoutr'   inputr&   T)	in_threadN)	r   r	   r'   r   r   r   r9   runEOFError)rG   r$   r&   r*   r'   rF   r3   r3   r4   r      s    	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*   stylesr3   r3   r4   r9      s   
r9   c                  C   s(   t  j} |   | dd |   dS )z
    Clear the screen.
    r   N)r	   r'   erase_screencursor_gotor%   )r'   r3   r3   r4   r      s   r   textc                 C   s   t  j}||  dS )z!
    Set the terminal title.
    N)r	   r'   r   )rQ   r'   r3   r3   r4   r      s   r   c                   C   s   t d dS )z"
    Erase the current title.
     N)r   r3   r3   r3   r4   r      s   r   )NNTr=   )0asyncio.eventsr   typingr   r   r   r   prompt_toolkit.applicationr   "prompt_toolkit.application.currentr   r	   *prompt_toolkit.application.run_in_terminalr   prompt_toolkit.eventloopr   prompt_toolkit.formatted_textr   r   r   prompt_toolkit.inputr   prompt_toolkit.layoutr   prompt_toolkit.outputr   r   prompt_toolkit.output.defaultsr   prompt_toolkit.rendererr   r8   prompt_toolkit.stylesr   r   r   r   r    prompt_toolkit.layout.containersr   __all__strboolr   r9   r   r   r   r3   r3   r3   r4   <module>   s    	

 
#


