o
    Ú­jœ  ã                   @   sÎ   d dl mZmZmZmZmZmZ erd dlmZ ddl	m
Z
 ddlmZ ddlmZ er2d 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 )é    )ÚTYPE_CHECKINGÚAnyÚDictÚIterableÚListÚSequence)ÚConsoleRenderableé   )Ú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   úI/var/www/html/CropPilot/venv/lib/python3.10/site-packages/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                   @   sB   e Zd ZdZdZdd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   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   5   r    z2JupyterMixin._repr_mimebundle_.<locals>.<dictcomp>c                    r!   r   r   r   r"   r   r   r   7   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,   r3   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   Úescape<   s   z _render_segments.<locals>.escapez<span style="z">z</span>z	<a href="z" target="_blank">z</a>Ú )Úcode)
r+   Úappendr   r   ÚsimplifyÚget_html_styleÚlinkÚjoinÚJUPYTER_HTML_FORMATÚformat)r3   r9   Ú	fragmentsÚappend_fragmentÚthemer   ÚstyleÚcontrolÚruler;   r   r   r   r   r0   ;   s"   


r0   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)r0   r   ÚIPython.displayrI   ÚModuleNotFoundError)r3   r   r   Újupyter_renderableÚipython_displayr   r   r   rI   T   s   
ýrI   Úargsr   c                  O   s   t ƒ }|j| i |¤ŽS )zProxy for Console print.)r
   Úprint)rN   r   r2   r   r   r   rO   b   s   rO   )Útypingr   r   r   r   r   r   Úrich.consoler   r:   r
   Úsegmentr   Úterminal_themer   rA   r   r,   r+   r0   rI   rO   r   r   r   r   Ú<module>   s     