U
    -e&                     @  st  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rd dl%m&Z& dddddg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d1d%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,d0dZ,dS )2    )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)AnyContainerr   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t dkr,|r$t|dnt jtts:t  pD  ddddd}
g t|	D ]8\}}|
| | rb|t	|	d krb|
|  qb|
| d	d
 fddd}t
 }|dk	r|j}|dk	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   _/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/prompt_toolkit/shortcuts/utils.pyto_textw   s    
z%print_formatted_text.<locals>.to_text   r,   r.   c                     s8   t tstttd d r4  d S )Nr)   )r'   r(   )r2   r   AssertionError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	   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valuerD   appr4   )r'   r$   r=   r)   r&   r>   r%   r(   r5   r   )   s,    ?r   )	containerr#   r%   r)   r.   c                 C  sb   |rt |d}nt j}tt| d|t t||dd}z|jdd W n tk
r\   Y nX 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/   )rI   r9   )Zlayoutr&   inputr%   T)Z	in_threadN)	r   r	   r&   r   r   r   r<   runEOFError)rI   r#   r%   r)   r&   rH   r4   r4   r5   r      s      	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    )textr.   c                 C  s   t  j}||  dS )z!
    Set the terminal title.
    N)r	   r&   r   )rO   r&   r4   r4   r5   r      s    c                   C  s   t d dS )z"
    Erase the current title.
     N)r   r4   r4   r4   r5   r      s    )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>   sN   &    #
