o
    Ëý°jÑ  ã                   @   s¦   d dl mZmZmZmZ ddlmZ ddlmZ ddl	m
Z
 dZG dd„ dƒZG d	d
„ d
ƒZdee defdd„Zdee deddfdd„Zdededdfdd„ZdS )é    )ÚAnyÚDictÚIterableÚListé   )Úget_console)ÚSegment)ÚDEFAULT_TERMINAL_THEMEz“<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace">{code}</pre>
c                
   @   sP   e Zd ZdZdededdfdd„Zdee d	ee d
edeeef fdd„Z	dS )ÚJupyterRenderablez)A shim to write html to Jupyter notebook.ÚhtmlÚtextÚreturnNc                 C   s   || _ || _d S )N)r   r   )Úselfr   r   © r   ú‹/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_vendor/rich/jupyter.pyÚ__init__   s   
zJupyterRenderable.__init__ÚincludeÚexcludeÚkwargsc                    sF   | j | jdœ}ˆr‡fdd„| ¡ D ƒ}ˆ r!‡ fdd„| ¡ D ƒ}|S )N©z
text/plainz	text/htmlc                    ó   i | ]\}}|ˆ v r||“qS r   r   ©Ú.0ÚkÚv©r   r   r   Ú
<dictcomp>   ó    z7JupyterRenderable._repr_mimebundle_.<locals>.<dictcomp>c                    ó   i | ]\}}|ˆ vr||“qS r   r   r   ©r   r   r   r      r   )r   r   Úitems)r   r   r   r   Údatar   ©r   r   r   Ú_repr_mimebundle_   s   z#JupyterRenderable._repr_mimebundle_)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r   r   r#   r   r   r   r   r
      s    ÿÿÿ
þr
   c                
   @   s>   e Zd ZdZdZdee dee dedeeef fdd„Z	d	S )
ÚJupyterMixinz@Add to an Rich renderable to make it render in Jupyter notebook.r   r   r   r   r   c           	         sl   t ƒ }t| | |j¡ƒ}t|ƒ}| |¡}||dœ}ˆr'‡fdd„| ¡ D ƒ}ˆ r4‡ fdd„| ¡ D ƒ}|S )Nr   c                    r   r   r   r   r   r   r   r   ,   r   z2JupyterMixin._repr_mimebundle_.<locals>.<dictcomp>c                    r   r   r   r   r   r   r   r   .   r   )r   ÚlistÚrenderÚoptionsÚ_render_segmentsÚ_render_bufferr    )	r   r   r   r   ÚconsoleÚsegmentsr   r   r!   r   r"   r   r#   #   s   

zJupyterMixin._repr_mimebundle_N)
r$   r%   r&   r'   Ú	__slots__r   r(   r   r   r#   r   r   r   r   r)      s    ÿÿÿ
þr)   r0   r   c                 C   s¨   dt dt fdd„}g }|j}t}t | ¡D ]1\}}}|rq||ƒ}|rB| |¡}|r3d|› d|› d�n|}|jrBd|j› d|› d	�}||ƒ qd
 |¡}	tj	|	d�}
|
S )Nr   r   c                 S   s   |   dd¡  dd¡  dd¡S )zEscape html.ú&z&amp;ú<z&lt;ú>z&gt;)Úreplace)r   r   r   r   Úescape3   s   z _render_segments.<locals>.escapez<span style="z">z</span>z	<a href="z</a>Ú )Úcode)
r(   Úappendr	   r   ÚsimplifyÚget_html_styleÚlinkÚjoinÚJUPYTER_HTML_FORMATÚformat)r0   r6   Ú	fragmentsÚappend_fragmentÚthemer   ÚstyleÚcontrolÚruler8   r   r   r   r   r-   2   s"   


r-   r   Nc                 C   sB   t | ƒ}t||ƒ}zddlm} ||ƒ W dS  ty    Y dS w )zRender segments to Jupyter.r   )ÚdisplayN)r-   r
   ÚIPython.displayrF   ÚModuleNotFoundError)r0   r   r   Újupyter_renderableÚipython_displayr   r   r   rF   K   s   
ýrF   Úargsr   c                  O   s   t ƒ }|j| i |¤ŽS )zProxy for Console print.)r   Úprint)rK   r   r/   r   r   r   rL   Y   s   rL   )Útypingr   r   r   r   r7   r   Úsegmentr   Úterminal_themer	   r>   r
   r)   r(   r-   rF   rL   r   r   r   r   Ú<module>   s    