o
    Df&                  
   @  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:   W/home/ubuntu/webapp/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     
#


