a
    [fT=                    @   sD  U d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d dl mZ d d	l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mZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z* ej+dkr$d dlm,Z,m-Z-m.Z. nd dl/m,Z,m-Z-m.Z. ddl0m1Z1m2Z2 ddl3m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZE ddlFmGZGmHZH ddlImJZJmKZK ddlLmMZMmNZN ddlOmPZP ddlQmRZR ddlSmTZT dd lUmVZV dd!lWmXZX dd"lYmZZZm[Z[ dd#l\m]Z] dd$l^m_Z_m`Z` dd%lambZbmcZc dd&ldmeZemfZf erdd'lgmhZh dd(limjZj dd)lkmlZl em d*kZnee)eod+f gd+f Zpe,d, Zqe,d- ZrG d.d/ d/Zses Ztd0Zue;jve;jwd1ZxG d2d3 d3e$Zye	G d4d5 d5Zze.G d6d7 d7e-Z{e.G d8d9 d9e-Z|e)e|e{eof Z}e!e)e}eXf  Z~eA ZG d:d; d;eZG d<d= d=ZG d>d? d?ZG d@dA dAZG dBdC dCZG dDdE dEZG dFdG dGZG dHdI dIZdeedKedKef f dLdMdNZedOdPdQZe;jwe;jve;je;jndRZdSdT e D Ze	G dUdV dVejZG dWdX dXeZdae%dY edZ< dYdOd[d\ZedOd]d^Ze rd d_lmZ ed`da G dbdc dcZeddkr@e ZededfdgdJd`ddhdidjdkdldmdn edodpee edg dJdqg drdsdtdud`dvg dwdxdtdyg dzd{dtd|d}d~ ed dS )    N)ABCabstractmethod)	dataclassfield)datetime)wraps)getpass)escape)isclass)islice)RLock)	monotonic)	FrameType
ModuleTypeTracebackType)IOTYPE_CHECKINGAnyCallableDictIterableListMapping
NamedTupleOptionalTextIOTupleTypeUnioncast)      )LiteralProtocolruntime_checkable   )errorsthemes)_emoji_replace)FormatTimeCallable	LogRender)AlignAlignMethod)ColorSystem)Control)EmojiVariant)NullHighlighterReprHighlighterrender)Measurementmeasure_renderables)PagerSystemPager)Prettyis_expandable)	rich_cast)Region)render_scope)Screen)Segment)Style	StyleTypeStyled)DEFAULT_TERMINAL_THEMETerminalTheme)TextTextType)Theme
ThemeStack)WindowsConsoleFeatures)LiveStatusWindowsrE   )defaultleftcenterrightfull)foldcropellipsisignorec                   @   s   e Zd ZdS )NoChangeN)__name__
__module____qualname__ r[   r[   jC:\Users\91910\OneDrive\Desktop\vts_admin_rebuild-master\vts\Lib\site-packages\pip/_vendor/rich/console.pyrW   O   s   rW   a9  <!DOCTYPE html>
<head>
<meta charset="UTF-8">
<style>
{stylesheet}
body {{
    color: {foreground};
    background-color: {background};
}}
</style>
</head>
<html>
<body>
    <code>
        <pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace">{code}</pre>
    </code>
</body>
</html>
)256color16colorc                   @   s"   e Zd ZU dZeed< eed< dS )ConsoleDimensionszSize of the terminal.widthheightN)rX   rY   rZ   __doc__int__annotations__r[   r[   r[   r\   r_   n   s   
r_   c                   @   s  e Zd ZU dZeed< eed< eed< eed< eed< eed< eed< d	Z	e
e ed
< d	Ze
e ed< dZe
e ed< d	Ze
e ed< d	Ze
e ed< d	Ze
e ed< eedddZd dddZeeeeeeeeed	eeef eeef eeef ee
e ef ee
e ef ee
e ef ee
e ef ee
e ef ee
e ef d d
ddZed dddZed dddZeed d d!d"Zd	S )#ConsoleOptionsz$Options for __rich_console__ method.sizelegacy_windows	min_width	max_widthis_terminalencoding
max_heightNjustifyoverflowFno_wrap	highlightmarkupra   returnc                 C   s   | j d S )z+Check if renderables should use ascii only.utf)rk   
startswithselfr[   r[   r\   
ascii_only   s    zConsoleOptions.ascii_onlyc                 C   s   t t }| j |_|S )zdReturn a copy of the options.

        Returns:
            ConsoleOptions: a copy of self.
        )re   __new____dict__copy)rw   optionsr[   r[   r\   r{      s    
zConsoleOptions.copy)	r`   rh   ri   rm   rn   ro   rp   rq   ra   )
r`   rh   ri   rm   rn   ro   rp   rq   ra   rs   c       	         C   s   |   }
t|ts$td| |
_|
_t|ts4||
_t|tsD||
_t|tsT||
_t|tsd||
_t|tst||
_t|ts||
_	t|ts||
_
t|	ts|	dur|	|
_|	du rdntd|	|
_|
S )zUpdate values, return a copy.r   N)r{   
isinstancerW   maxrh   ri   rm   rn   ro   rp   rq   rl   ra   )rw   r`   rh   ri   rm   rn   ro   rp   rq   ra   r|   r[   r[   r\   update   s,    








zConsoleOptions.updater`   rs   c                 C   s   |   }td| |_|_|S )zUpdate just the width, return a copy.

        Args:
            width (int): New width (sets both min_width and max_width)

        Returns:
            ~ConsoleOptions: New console options instance.
        r   )r{   r~   rh   ri   )rw   r`   r|   r[   r[   r\   update_width   s    	zConsoleOptions.update_widthra   rs   c                 C   s   |   }| |_|_|S )zUpdate the height, and return a copy.

        Args:
            height (int): New height

        Returns:
            ~ConsoleOptions: New Console options instance.
        )r{   rl   ra   )rw   ra   r|   r[   r[   r\   update_height   s    	zConsoleOptions.update_height)r`   ra   rs   c                 C   s*   |   }td| |_|_| |_|_|S )a  Update the width and height, and return a copy.

        Args:
            width (int): New width (sets both min_width and max_width).
            height (int): New height.

        Returns:
            ~ConsoleOptions: New console options instance.
        r   )r{   r~   rh   ri   ra   rl   )rw   r`   ra   r|   r[   r[   r\   update_dimensions   s    
z ConsoleOptions.update_dimensions)rX   rY   rZ   rb   r_   rd   boolrc   strrm   r   JustifyMethodrn   OverflowMethodro   rp   rq   ra   propertyrx   r{   	NO_CHANGEr   rW   r   r   r   r   r[   r[   r[   r\   re   w   sR   



%re   c                   @   s&   e Zd ZdZedef dddZdS )RichCastz5An object that may be 'cast' to a console renderable.ConsoleRenderablerr   c                 C   s   d S Nr[   rv   r[   r[   r\   __rich__   s    zRichCast.__rich__N)rX   rY   rZ   rb   r   r   r   r[   r[   r[   r\   r      s   r   c                   @   s"   e Zd ZdZddddddZdS )	r   z-An object that supports the console protocol.Consolere   RenderResultconsoler|   rs   c                 C   s   d S r   r[   rw   r   r|   r[   r[   r\   __rich_console__   s    z"ConsoleRenderable.__rich_console__N)rX   rY   rZ   rb   r   r[   r[   r[   r\   r      s   r   c                   @   s   e Zd ZdZdS )CaptureErrorz(An error in the Capture context manager.N)rX   rY   rZ   rb   r[   r[   r[   r\   r     s   r   c                   @   s8   e Zd ZdZdeddddZddee d	d
dZdS )NewLinez$A renderable to generate new line(s)r%   Ncountrs   c                 C   s
   || _ d S r   )r   rw   r   r[   r[   r\   __init__  s    zNewLine.__init__r   re   r   c                 c   s   t d| j V  d S )N
)r>   r   r   r[   r[   r\   r     s    zNewLine.__rich_console__)r%   )	rX   rY   rZ   rb   rc   r   r   r>   r   r[   r[   r[   r\   r     s
   r   c                   @   s>   e Zd ZdZeee  eeddddZdee	ddd	Z
dS )
ScreenUpdatez)Render a list of lines at a given offset.Nlinesxyrs   c                 C   s   || _ || _|| _d S r   )_linesr   r   )rw   r   r   r   r[   r[   r\   r   #  s    zScreenUpdate.__init__r   r   c                 c   s>   | j }tj}t| j| jD ]\}}|||V  |E d H  qd S r   )r   r.   move_to	enumerater   r   )rw   r   r|   r   r   offsetliner[   r[   r\   r   (  s
    zScreenUpdate.__rich_console__)rX   rY   rZ   rb   r   r>   rc   r   re   r   r   r[   r[   r[   r\   r      s
   r   c                   @   s`   e Zd ZdZdddddZd ddd	Zeee  ee ee	 dd
ddZ
edddZdS )CapturezContext manager to capture the result of printing to the console.
    See :meth:`~rich.console.Console.capture` for how to use.

    Args:
        console (Console): A console instance to capture output.
    r   N)r   rs   c                 C   s   || _ d | _d S r   )_console_result)rw   r   r[   r[   r\   r   :  s    zCapture.__init__rr   c                 C   s   | j   | S r   )r   begin_capturerv   r[   r[   r\   	__enter__>  s    
zCapture.__enter__exc_typeexc_valexc_tbrs   c                 C   s   | j  | _d S r   )r   end_capturer   rw   r   r   r   r[   r[   r\   __exit__B  s    zCapture.__exit__c                 C   s   | j du rtd| j S )zGet the result of the capture.Nz<Capture result is not available until context manager exits.)r   r   rv   r[   r[   r\   getJ  s
    
zCapture.get)rX   rY   rZ   rb   r   r   r   r   BaseExceptionr   r   r   r   r[   r[   r[   r\   r   2  s   
r   c                   @   sX   e Zd ZdZddeeddddZd dd	d
Zee	e
  ee
 ee ddddZdS )ThemeContextzbA context manager to use a temporary theme. See :meth:`~rich.console.Console.use_theme` for usage.Tr   N)r   themeinheritrs   c                 C   s   || _ || _|| _d S r   )r   r   r   )rw   r   r   r   r[   r[   r\   r   V  s    zThemeContext.__init__rr   c                 C   s   | j | j | S r   )r   
push_themer   rv   r[   r[   r\   r   [  s    zThemeContext.__enter__r   c                 C   s   | j   d S r   )r   	pop_themer   r[   r[   r\   r   _  s    zThemeContext.__exit__)T)rX   rY   rZ   rb   rG   r   r   r   r   r   r   r   r   r[   r[   r[   r\   r   S  s   
r   c                   @   s^   e Zd ZdZddee eeddddZd dd	d
Zee	e
  ee
 ee ddddZdS )PagerContextzZA context manager that 'pages' content. See :meth:`~rich.console.Console.pager` for usage.NFr   )r   pagerstyleslinksrs   c                 C   s*   || _ |d u rt n|| _|| _|| _d S r   )r   r7   r   r   r   )rw   r   r   r   r   r[   r[   r\   r   k  s    zPagerContext.__init__rr   c                 C   s   | j   | S r   )r   _enter_bufferrv   r[   r[   r\   r   w  s    
zPagerContext.__enter__r   c                 C   s   |d u r| j j` | j jd d  }| j jd d = |}| jsFt|}n| jsVt|}| j |}W d    n1 sv0    Y  | j	
| | j   d S r   )r   _lock_bufferr   r>   strip_stylesr   strip_links_render_bufferr   show_exit_buffer)rw   r   r   r   buffersegmentscontentr[   r[   r\   r   {  s    

*zPagerContext.__exit__)NFF)rX   rY   rZ   rb   r   r6   r   r   r   r   r   r   r   r[   r[   r[   r\   r   h  s"      
r   c                   @   st   e Zd ZdZddeeddddZddeee dd	d
dZ	d dddZ
eee  ee ee ddddZdS )ScreenContextziA context manager that enables an alternative screen. See :meth:`~rich.console.Console.screen` for usage. r   N)r   hide_cursorstylers   c                 C   s"   || _ || _t|d| _d| _d S )Nr   F)r   r   r=   screen_changed)rw   r   r   r   r[   r[   r\   r     s    zScreenContext.__init__r   )renderablesr   rs   c                G   sJ   |r$t |dkrt| n|d | j_|dur4|| j_| jj| jdd dS )a+  Update the screen.

        Args:
            renderable (RenderableType, optional): Optional renderable to replace current renderable,
                or None for no change. Defaults to None.
            style: (Style, optional): Replacement style, or None for no change. Defaults to None.
        r%   r   Nr   )end)lenGroupr   
renderabler   r   print)rw   r   r   r[   r[   r\   r     s    
zScreenContext.updaterr   c                 C   s*   | j d| _| jr&| jr&| j d | S )NTF)r   set_alt_screenr   r   show_cursorrv   r[   r[   r\   r     s    zScreenContext.__enter__r   c                 C   s(   | j r$| jd | jr$| jd d S )NFT)r   r   r   r   r   r   r[   r[   r\   r     s    zScreenContext.__exit__)r   )rX   rY   rZ   rb   r   r@   r   RenderableTyper   r   r   r   r   r   r   r[   r[   r[   r\   r     s"    	
r   c                   @   sb   e Zd ZdZdddeddddZeed d	d
dZddddddZ	dde
dddZdS )r   a$  Takes a group of renderables and returns a renderable object that renders the group.

    Args:
        renderables (Iterable[RenderableType]): An iterable of renderable objects.
        fit (bool, optional): Fit dimension of group to contents, or fill available space. Defaults to True.
    Tfitr   N)r   r   rs   c                G   s   || _ || _d | _d S r   )_renderablesr   _render)rw   r   r   r[   r[   r\   r     s    zGroup.__init__rr   c                 C   s   | j d u rt| j| _ | j S r   )r   listr   rv   r[   r[   r\   r     s    
zGroup.renderablesr   re   r4   r   c                 C   s&   | j rt||| jS t|j|jS d S r   )r   r5   r   r4   ri   r   r[   r[   r\   __rich_measure__  s    zGroup.__rich_measure__c                 c   s   | j E d H  d S r   )r   r   r[   r[   r\   r     s    zGroup.__rich_console__)rX   rY   rZ   rb   r   r   r   r   r   r   r   r   r[   r[   r[   r\   r     s   	r   T.)r   rs   c                    s,   t dtt f t dtf d fdd}|S )zA decorator that turns an iterable of renderables in to a group.

    Args:
        fit (bool, optional): Fit dimension of group to contents, or fill available space. Defaults to True.
    .)methodrs   c                    s$   t  tttd fdd}|S )zGConvert a method that returns an iterable of renderables in to a Group.)argskwargsrs   c                     s   | i |}t |d iS )Nr   )r   )r   r   r   )r   r   r[   r\   _replace  s    z*group.<locals>.decorator.<locals>._replace)r   r   r   )r   r   r   )r   r\   	decorator  s    zgroup.<locals>.decorator)r   r   r   r   )r   r   r[   r   r\   group  s    
r   rr   c                  C   sZ   zt  W n ty   Y dS 0 t  } | jj}dt| jv sB|dkrFdS |dkrRdS dS dS )z-Check if we're running in a Jupyter notebook.Fzgoogle.colabZMQInteractiveShellTTerminalInteractiveShellN)get_ipython	NameError	__class__rX   r   )ipythonshellr[   r[   r\   _is_jupyter  s    r   )standard256	truecolorwindowsc                 C   s   i | ]\}}||qS r[   r[   ).0namesystemr[   r[   r\   
<dictcomp>      r   c                   @   s<   e Zd ZU dZeed< eedZe	e
 ed< dZeed< dS )ConsoleThreadLocalsz(Thread local values for Console context.theme_stack)default_factoryr   r   buffer_indexN)rX   rY   rZ   rb   rH   rd   r   r   r   r   r>   r   rc   r[   r[   r[   r\   r     s   
r   c                   @   s,   e Zd ZdZeee ee dddZdS )
RenderHookz(Provides hooks in to the render process.)r   rs   c                 C   s   dS )aL  Called with a list of objects to render.

        This method can return a new list of renderables, or modify and return the same list.

        Args:
            renderables (List[ConsoleRenderable]): A number of renderable objects.

        Returns:
            List[ConsoleRenderable]: A replacement list of renderables.
        Nr[   )rw   r   r[   r[   r\   process_renderables  s    zRenderHook.process_renderablesN)rX   rY   rZ   rb   r   r   r   r   r[   r[   r[   r\   r     s
   r   rI   _windows_console_featuresc                  C   s"   t d urt S ddlm}  |  a t S )Nr%   get_windows_console_features)r   _windowsr   r   r[   r[   r\   r   /  s
    r   c                   C   s   t ot j S )zDetect legacy Windows.)WINDOWSr   vtr[   r[   r[   r\   detect_legacy_windows9  s    r  )initF)stripc                    @   s~  e Zd ZU dZejZeeef e	d< dddddddddddddddddddddde
 dddddd	eed
  ee ee ee eee eeee  eee ee ee ee eeeeee eeeeeef ed ee eeeg ef  eeg ef  eeeef  d	ddZedddZeee dddZejee ddddZeee dddZeedddZ e jeddddZ ee!dddZ"ee# dddZ$dddd Z%ddd!d"Z&d#dd$d%d&Z'ddd'd(Z(e)dd)d*d+Z*ddd,d-Z+d dd.d/Z,e-e-e-dd0d1d2Z.ddd3d4Z/edd5d6Z0dd7eedd8d9d:Z1ddd;d<Z2dd7eee3d8d=d>Z4eee dd?d@Z5eeddAdBZ6eeddCdDZ7eeddEdFZ8ee9ddGdHZ:ee;ddIdJZ<e<je=eef ddKdLdJZ<eeddMdNZ>e>jeddOdPdNZ>eeddQdRZ?e?jeddSdTdRZ?dddUdVZ@eAddWdXZBdeeC eeeDdYdZd[ZEdedd]d^d_ZFdedd`dadbZGdcdddedfdgeHeeeedhdidjdkZIdeedldmdnZJdeedodpdqZKeeddrdsZLdeee dtdudvdwZMddxeHee9 eNdydzd{ZOdeHee9 ePe dyd|d}ZQddddd~eHee9 eeR eeeee  dddZSddddddddeeeeRf eeT eeU ee ee ee eeV dd	ddZWddeeeRf eeeRef  eRdddZXdddddePe- eeeeT ee ee ee eeY dddZZddddde[eeeeRf e\ddddZ]e^ddddZ_ddddde-eeeeeeRf  ee ddddZ`ddddddddddddddde-eeeeeeRf  eeT eeU ee ee ee ee ee ee eee eddddZaddddddddddd	ee e-edeef eeeeeeee-ge-f  eddddZbdddeHeec ee9 ddddZddeee  eeddddZeddddddddee eee eeePeeeff  eddddZgeheijjfeeg eek f e=eeelee-f f dddZmddddddddd\d	e-eeeeeeRf  eeT ee ee ee eeddddZnddddZoePe edddÄZpddddddĜe[eeeeeq edŜddǄZrdddȜeeedɜdd˄ZsdddȜeeedd̜dd΄ZtdddddϜeeu eee eedМdd҄ZvddewddϜeeeu eeeddӜddՄZxdS )r   a]  A high level console interface.

    Args:
        color_system (str, optional): The color system supported by your terminal,
            either ``"standard"``, ``"256"`` or ``"truecolor"``. Leave as ``"auto"`` to autodetect.
        force_terminal (Optional[bool], optional): Enable/disable terminal control codes, or None to auto-detect terminal. Defaults to None.
        force_jupyter (Optional[bool], optional): Enable/disable Jupyter rendering, or None to auto-detect Jupyter. Defaults to None.
        force_interactive (Optional[bool], optional): Enable/disable interactive mode, or None to auto detect. Defaults to None.
        soft_wrap (Optional[bool], optional): Set soft wrap default on print method. Defaults to False.
        theme (Theme, optional): An optional style theme object, or ``None`` for default theme.
        stderr (bool, optional): Use stderr rather than stdout if ``file`` is not specified. Defaults to False.
        file (IO, optional): A file object where the console should write to. Defaults to stdout.
        quiet (bool, Optional): Boolean to suppress all output. Defaults to False.
        width (int, optional): The width of the terminal. Leave as default to auto-detect width.
        height (int, optional): The height of the terminal. Leave as default to auto-detect height.
        style (StyleType, optional): Style to apply to all output, or None for no style. Defaults to None.
        no_color (Optional[bool], optional): Enabled no color mode, or None to auto detect. Defaults to None.
        tab_size (int, optional): Number of spaces used to replace a tab character. Defaults to 8.
        record (bool, optional): Boolean to enable recording of terminal output,
            required to call :meth:`export_html` and :meth:`export_text`. Defaults to False.
        markup (bool, optional): Boolean to enable :ref:`console_markup`. Defaults to True.
        emoji (bool, optional): Enable emoji code. Defaults to True.
        emoji_variant (str, optional): Optional emoji variant, either "text" or "emoji". Defaults to None.
        highlight (bool, optional): Enable automatic highlighting. Defaults to True.
        log_time (bool, optional): Boolean to enable logging of time by :meth:`log` methods. Defaults to True.
        log_path (bool, optional): Boolean to enable the logging of the caller by :meth:`log`. Defaults to True.
        log_time_format (Union[str, TimeFormatterCallable], optional): If ``log_time`` is enabled, either string for strftime or callable that formats the time. Defaults to "[%X] ".
        highlighter (HighlighterType, optional): Default highlighter.
        legacy_windows (bool, optional): Enable legacy Windows mode, or ``None`` to auto detect. Defaults to ``None``.
        safe_box (bool, optional): Restrict box options that don't render on legacy Windows.
        get_datetime (Callable[[], datetime], optional): Callable that gets the current time as a datetime.datetime object (used by Console.log),
            or None for datetime.now.
        get_time (Callable[[], time], optional): Callable that gets the current time in seconds, default uses time.monotonic.
    _environautoNFr!   Tz[%X])color_systemforce_terminalforce_jupyterforce_interactive	soft_wrapr   stderrfilequietr`   ra   r   no_colortab_sizerecordrq   emojiemoji_variantrp   log_timelog_pathlog_time_formathighlighterrg   safe_boxget_datetimeget_timer  )r  r   r   r   r   HighlighterTypec                C   s  |d ur|| _ |d u rt n|| _| jr8|
p.d}
|p6d}|| _|
| _|| _|| _|| _|| _|| _	|| _
|| _|d u rt o| j n|| _|
d u r| j d}|d ur| rt|| j }
|d u r| j d}|d ur| rt|}|| _|
| _|| _|  || _|| _|	| _|| _|d u r(d | _n |dkr>|  | _n
t| | _t | _t|||d| _|pjt| _|| _|p~t j!| _"|pt#| _$|| _%|d ur|nd| j v | _&|d u r| j'o| j( n|| _)t | _*t+t,|d u rt-j.n|d| _/g | _0g | _1d | _2d	| _3d S )
N]   d   COLUMNSLINESr  )	show_time	show_pathtime_formatNO_COLOR)r   F)4r  r   
is_jupyterr
  _width_heightr  r  _markup_emoji_emoji_variant
_highlightr  rg   r   isdigitrc   _force_terminal_filer  r  _color_system_detect_color_systemCOLOR_SYSTEMS	threadingr   r   r*   _log_render_null_highlighterr  r  r   nowr  r   r  r   r  rj   is_dumb_terminalis_interactive_record_buffer_lockr   rH   r'   DEFAULT_thread_locals_record_buffer_render_hooks_live_is_alt_screen)rw   r  r  r  r	  r
  r   r  r  r  r`   ra   r   r  r  r  rq   r  r  rp   r  r  r  r  rg   r  r  r  r  columnsr   r[   r[   r\   r   j  s    #




zConsole.__init__rr   c                 C   s   d| j  dt| j dS )Nz<console width= >)r`   r   r-  rv   r[   r[   r\   __repr__  s    zConsole.__repr__c                 C   s(   | j p| jrtjntj}t|d|}|S )z Get the file object to write to.rich_proxied_file)r,  r  sysstdoutgetattr)rw   r  r[   r[   r\   r    s    zConsole.file)new_filers   c                 C   s
   || _ dS )zSet a new file object.N)r,  )rw   rE  r[   r[   r\   r    s    c                 C   s   | j jS zGet a thread local buffer.)r8  r   rv   r[   r[   r\   r     s    zConsole._bufferc                 C   s   | j jS rF  r8  r   rv   r[   r[   r\   _buffer_index  s    zConsole._buffer_index)valuers   c                 C   s   || j _d S r   rG  )rw   rI  r[   r[   r\   rH    s    c                 C   s   | j jS )z!Get the thread local theme stack.)r8  r   rv   r[   r[   r\   _theme_stack  s    zConsole._theme_stackc                 C   s   | j rtjS | jr| jrdS trD| jr,tjS t }|jr>tjS tj	S | j
dd  }|dv rhtjS | j
dd  }|d\}}}t|tj}|S dS )z"Detect color system from env vars.N	COLORTERMr   )r   24bitTERM-)r#  r-   	TRUECOLORrj   r4  r   rg   r   r   	EIGHT_BITr  r   r  lower
rpartition_TERM_COLORSSTANDARD)rw   windows_console_features
color_termterm
_term_name_hyphencolorsr  r[   r[   r\   r.    s&    zConsole._detect_color_systemc                 C   s   |  j d7  _ dS )z4Enter in to a buffer context, and buffer all output.r%   N)rH  rv   r[   r[   r\   r     s    zConsole._enter_bufferc                 C   s   |  j d8  _ |   dS )z5Leave buffer context, and render content if required.r%   N)rH  _check_bufferrv   r[   r[   r\   r     s    zConsole._exit_bufferrJ   )livers   c                 C   sD   | j * | jdurtd|| _W d   n1 s60    Y  dS )zSet Live instance. Used by Live context manager.

        Args:
            live (Live): Live instance using this Console.

        Raises:
            errors.LiveError: If this Console has a Live context currently active.
        Nz+Only one live display may be active at once)r   r;  r&   	LiveError)rw   r\  r[   r[   r\   set_live  s    	

zConsole.set_livec                 C   s0   | j  d| _W d   n1 s"0    Y  dS )zClear the Live instance.N)r   r;  rv   r[   r[   r\   
clear_live+  s    zConsole.clear_live)hookrs   c                 C   s6   | j  | j| W d   n1 s(0    Y  dS )zpAdd a new render hook to the stack.

        Args:
            hook (RenderHook): Render hook instance.
        N)r   r:  append)rw   r`  r[   r[   r\   push_render_hook0  s    zConsole.push_render_hookc                 C   s4   | j  | j  W d   n1 s&0    Y  dS )z'Pop the last renderhook from the stack.N)r   r:  poprv   r[   r[   r\   pop_render_hook9  s    zConsole.pop_render_hookc                 C   s   |    | S )z,Own context manager to enter buffer context.r   rv   r[   r[   r\   r   >  s    zConsole.__enter__)r   	exc_value	tracebackrs   c                 C   s   |    dS )zExit buffer context.N)r   )rw   r   rf  rg  r[   r[   r\   r   C  s    zConsole.__exit__c                 C   s   |    dS )z`Begin capturing console output. Call :meth:`end_capture` to exit capture mode and return output.Nre  rv   r[   r[   r\   r   G  s    zConsole.begin_capturec                 C   s$   |  | j}| jdd= |   |S )zhEnd capture mode and return captured string.

        Returns:
            str: Console output.
        N)r   r   r   )rw   render_resultr[   r[   r\   r   K  s    zConsole.end_capturer   )r   r   rs   c                C   s   | j j||d dS )a  Push a new theme on to the top of the stack, replacing the styles from the previous theme.
        Generally speaking, you should call :meth:`~rich.console.Console.use_theme` to get a context manager, rather
        than calling this method directly.

        Args:
            theme (Theme): A theme instance.
            inherit (bool, optional): Inherit existing styles. Defaults to True.
        ri  N)rJ  r   rw   r   r   r[   r[   r\   r   V  s    	zConsole.push_themec                 C   s   | j   dS )z9Remove theme from top of stack, restoring previous theme.N)rJ  r   rv   r[   r[   r\   r   a  s    zConsole.pop_themec                C   s   t | ||S )a  Use a different theme for the duration of the context manager.

        Args:
            theme (Theme): Theme instance to user.
            inherit (bool, optional): Inherit existing console styles. Defaults to True.

        Returns:
            ThemeContext: [description]
        )r   rj  r[   r[   r\   	use_themee  s    
zConsole.use_themec                 C   s   | j durt| j  S dS dS )zpGet color system string.

        Returns:
            Optional[str]: "standard", "256" or "truecolor".
        N)r-  _COLOR_SYSTEMS_NAMESrv   r[   r[   r\   r  q  s    

zConsole.color_systemc                 C   s   t | jddpd S )zGet the encoding of the console file, e.g. ``"utf-8"``.

        Returns:
            str: A standard encoding string.
        rk   utf-8)rD  r  rQ  rv   r[   r[   r\   rk   ~  s    zConsole.encodingc                 C   sL   | j dur| j S t| jdd}z|du r,dn| W S  tyF   Y dS 0 dS )zCheck if the console is writing to a terminal.

        Returns:
            bool: True if the console writing to a device capable of
            understanding terminal codes, otherwise False.
        NisattyF)r+  rD  r  
ValueError)rw   rn  r[   r[   r\   rj     s    
zConsole.is_terminalc                 C   s$   | j dd}| dv }| jo"|S )zxDetect dumb terminal.

        Returns:
            bool: True if writing to a dumb terminal, otherwise False.

        rM  r   )dumbunknown)r  r   rQ  rj   )rw   _termis_dumbr[   r[   r\   r4    s    zConsole.is_dumb_terminalc              	   C   s$   t | jj| j| jd| j| j| jdS )zGet default console options.r%   )rl   rf   rg   rh   ri   rk   rj   )re   rf   ra   rg   r`   rk   rj   rv   r[   r[   r\   r|     s    zConsole.optionsc                 C   sb  | j dur(| jdur(t| j | j | jS | jr8tddS d}d}trjzt \}}W q tyf   Y q0 ndztt	j
 \}}W nJ tttfy   ztt	j \}}W n tttfy   Y n0 Y n0 | jd}|dur| rt|}| jd}|dur| rt|}|p"d}|p,d}t| j du rF|| j n| j | jdu rZ|n| jS )zGet the size of the console.

        Returns:
            ConsoleDimensions: A named tuple containing the dimensions.
        NP      r  r  )r$  r%  r_   rg   r4  r   osget_terminal_sizeOSErrorrB  	__stdin__filenoAttributeErrorro  
__stdout__r  r   r*  rc   )rw   r`   ra   r=  r   r[   r[   r\   rf     s<    


zConsole.size)new_sizers   c                 C   s   |\}}|| _ || _dS )zvSet a new size for the terminal.

        Args:
            new_size (Tuple[int, int]): New width and height.
        N)r$  r%  )rw   r}  r`   ra   r[   r[   r\   rf     s    c                 C   s   | j jS )zsGet the width of the console.

        Returns:
            int: The width (in characters) of the console.
        )rf   r`   rv   r[   r[   r\   r`     s    zConsole.widthr   c                 C   s
   || _ dS )zFSet width.

        Args:
            width (int): New width.
        N)r$  )rw   r`   r[   r[   r\   r`     s    c                 C   s   | j jS )zpGet the height of the console.

        Returns:
            int: The height (in lines) of the console.
        )rf   ra   rv   r[   r[   r\   ra     s    zConsole.heightr   c                 C   s
   || _ dS )zISet height.

        Args:
            height (int): new height.
        N)r%  )rw   ra   r[   r[   r\   ra     s    c                 C   s   |  t  dS )z3Play a 'bell' sound (if supported by the terminal).N)controlr.   bellrv   r[   r[   r\   r    s    zConsole.bellc                 C   s   t | }|S )a  A context manager to *capture* the result of print() or log() in a string,
        rather than writing it to the console.

        Example:
            >>> from rich.console import Console
            >>> console = Console()
            >>> with console.capture() as capture:
            ...     console.print("[bold magenta]Hello World[/]")
            >>> print(capture.get())

        Returns:
            Capture: Context manager with disables writing to the terminal.
        )r   )rw   capturer[   r[   r\   r    s    zConsole.capture)r   r   r   rs   c                 C   s   t | |||dS )a  A context manager to display anything printed within a "pager". The pager application
        is defined by the system and will typically support at least pressing a key to scroll.

        Args:
            pager (Pager, optional): A pager object, or None to use :class:`~rich.pager.SystemPager`. Defaults to None.
            styles (bool, optional): Show styles in pager. Defaults to False.
            links (bool, optional): Show links in pager. Defaults to False.

        Example:
            >>> from rich.console import Console
            >>> from rich.__main__ import make_test_card
            >>> console = Console()
            >>> with console.pager():
                    console.print(make_test_card())

        Returns:
            PagerContext: A context manager.
        )r   r   r   )r   )rw   r   r   r   r[   r[   r\   r   %  s    zConsole.pagerr%   r   c                 C   s"   |dksJ d|  t| dS )zqWrite new line(s).

        Args:
            count (int, optional): Number of new lines. Defaults to 1.
        r   zcount must be >= 0N)r   r   r   r[   r[   r\   r   <  s    zConsole.line)homers   c                 C   s,   |r|  t t  n|  t  dS )zClear the screen.

        Args:
            home (bool, optional): Also move the cursor to 'home' position. Defaults to True.
        N)r~  r.   clearr  )rw   r  r[   r[   r\   r  F  s    zConsole.cleardotszstatus.spinnerg      ?g      )@)spinnerspinner_stylespeedrefresh_per_secondrL   )statusr  r  r  r  rs   c                C   s$   ddl m} ||| ||||d}|S )at  Display a status and spinner.

        Args:
            status (RenderableType): A status renderable (str or Text typically).
            spinner (str, optional): Name of spinner animation (see python -m rich.spinner). Defaults to "dots".
            spinner_style (StyleType, optional): Style of spinner. Defaults to "status.spinner".
            speed (float, optional): Speed factor for spinner animation. Defaults to 1.0.
            refresh_per_second (float, optional): Number of refreshes per second. Defaults to 12.5.

        Returns:
            Status: A Status object that may be used as a context manager.
        r%   rK   )r   r  r  r  r  )r  rL   )rw   r  r  r  r  r  rL   status_renderabler[   r[   r\   r  Q  s    zConsole.status)r   rs   c                 C   s$   | j r | js | t| dS dS )zqShow or hide the cursor.

        Args:
            show (bool, optional): Set visibility of the cursor.
        TF)rj   rg   r~  r.   r   )rw   r   r[   r[   r\   r   r  s    zConsole.show_cursor)enablers   c                 C   s.   d}| j r*| js*| t| d}|| _|S )a  Enables alternative screen mode.

        Note, if you enable this mode, you should ensure that is disabled before
        the application exits. See :meth:`~rich.Console.screen` for a context manager
        that handles this for you.

        Args:
            enable (bool, optional): Enable (True) or disable (False) alternate screen. Defaults to True.

        Returns:
            bool: True if the control codes were written.

        FT)rj   rg   r~  r.   
alt_screenr<  )rw   r  changedr[   r[   r\   r   }  s    zConsole.set_alt_screenc                 C   s   | j S )zCheck if the alt screen was enabled.

        Returns:
            bool: True if the alt screen was enabled, otherwise False.
        )r<  rv   r[   r[   r\   is_alt_screen  s    zConsole.is_alt_screenr   )r   r   rs   c                 C   s   t | ||pddS )au  Context manager to enable and disable 'alternative screen' mode.

        Args:
            hide_cursor (bool, optional): Also hide the cursor. Defaults to False.
            style (Style, optional): Optional style for screen. Defaults to None.

        Returns:
            ~ScreenContext: Context which enables alternate screen on enter, and disables it on exit.
        r   )r   r   )r   )rw   r   r   r[   r[   r\   r     s    zConsole.screenr|   )r   r|   rs   c                C   s   t | |p| j|}|S )a  Measure a renderable. Returns a :class:`~rich.measure.Measurement` object which contains
        information regarding the number of characters required to print the renderable.

        Args:
            renderable (RenderableType): Any renderable or string.
            options (Optional[ConsoleOptions], optional): Options to use when measuring, or None
                to use default options. Defaults to None.

        Returns:
            Measurement: A measurement of the renderable.
        )r4   r   r|   )rw   r   r|   measurementr[   r[   r\   measure  s    zConsole.measurec           	      c   s   |p| j }|jdk rdS t|}t|dr@t|s@|| |}n>t|trl| j||j	|j
d}|| |}ntd|dzt|}W n$ ty   td|dY n0 t}|D ](}t||r|V  q| ||E dH  qdS )	ak  Render an object in to an iterable of `Segment` instances.

        This method contains the logic for rendering objects with the console protocol.
        You are unlikely to need to use it directly, unless you are extending the library.

        Args:
            renderable (RenderableType): An object supporting the console protocol, or
                an object that may be converted to a string.
            options (ConsoleOptions, optional): An options object, or None to use self.options. Defaults to None.

        Returns:
            Iterable[Segment]: An iterable of segments that may be rendered.
        r%   Nr   )rp   rq   zUnable to render zC; A str, Segment or object with __rich_console__ method is requiredzobject z is not renderable)r|   ri   r:   hasattrr
   r   r}   r   
render_strrp   rq   r&   NotRenderableErroriter	TypeErrorr>   r3   )	rw   r   r|   _optionsrender_iterabletext_renderableiter_render_Segmentrender_outputr[   r[   r\   r3     s2    







zConsole.render)r   pad	new_lines)r   r|   r   r  r  rs   c             	   C   s   | j  |p| j}| ||}|r.t||}tttj||j||dd|j	}|j	dur|j	t
| }	|	dkr|rtd|j |tdgntd|j |gg}
||
|	  |W  d   S 1 s0    Y  dS )aG  Render objects in to a list of lines.

        The output of render_lines is useful when further formatting of rendered console text
        is required, such as the Panel class which draws a border around any renderable object.

        Args:
            renderable (RenderableType): Any object renderable in the console.
            options (Optional[ConsoleOptions], optional): Console options, or None to use self.options. Default to ``None``.
            style (Style, optional): Optional style to apply to renderables. Defaults to ``None``.
            pad (bool, optional): Pad lines shorter than render width. Defaults to ``True``.
            new_lines (bool, optional): Include "
" characters at end of lines.

        Returns:
            List[List[Segment]]: A list of lines, where a line is a list of Segment objects.
        )include_new_linesr  Nr   r>  r   )r   r|   r3   r>   apply_styler   r   split_and_crop_linesri   ra   r   extend)rw   r   r|   r   r  r  render_options	_renderedr   extra_linespad_liner[   r[   r\   render_lines  s4    

zConsole.render_linesr   )r   rm   rn   r  rq   rp   r  rE   )	textr   rm   rn   r  rq   rp   r  rs   c                C   s   |p|du o| j }	|p"|du o"| j}
|p4|du o4| j}|
rZt|||	| jd}||_||_n"t|	rnt|| jdn||||d}|r|p| j	nd}|dur|t
|}|| |S |S )a  Convert a string to a Text instance. This is is called automatically if
        you print or log a string.

        Args:
            text (str): Text to render.
            style (Union[str, Style], optional): Style to apply to rendered text.
            justify (str, optional): Justify method: "default", "left", "center", "full", or "right". Defaults to ``None``.
            overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to ``None``.
            emoji (Optional[bool], optional): Enable emoji, or ``None`` to use Console default.
            markup (Optional[bool], optional): Enable markup, or ``None`` to use Console default.
            highlight (Optional[bool], optional): Enable highlighting, or ``None`` to use Console default.
            highlighter (HighlighterType, optional): Optional highlighter to apply.
        Returns:
            ConsoleRenderable: Renderable object.

        N)r   r  r  )default_variant)rm   rn   r   )r'  r&  r)  render_markupr(  rm   rn   rE   r(   r  r   copy_styles)rw   r  r   rm   rn   r  rq   rp   r  emoji_enabledmarkup_enabledhighlight_enabled	rich_text_highlighterhighlight_textr[   r[   r\   r  !  s4    	
zConsole.render_str)rN   )r   rN   rs   c             
   C   s   t |tr|S z2| j|}|du r.t|}|jr<| n|W S  tjy } zB|durp| 	|W  Y d}~S t
d|d| dW Y d}~n
d}~0 0 dS )a!  Get a Style instance by it's theme name or parse a definition.

        Args:
            name (str): The name of a style or a style definition.

        Returns:
            Style: A Style object.

        Raises:
            MissingStyle: If no style could be parsed from name.

        NzFailed to get style z; )r}   r?   rJ  r   parselinkr{   r&   StyleSyntaxError	get_styleMissingStyle)rw   r   rN   r   errorr[   r[   r\   r  \  s    

zConsole.get_stylerm   r  rq   rp   )objectssepr   rm   r  rq   rp   rs   c                   s6  g }|j  g j }	 dv r:tdd fdd}
|
t}|sP|du rV| jrV| j}ddfdd}|D ]}t|}t|tr|	| j||||d	 qtt|t	r|	| qtt|t
r|  | qtt|r|  t||d
 qt|	|t| qt|  | jdur2| | jfdd|D }|S )a  Combine a number of renderables and text into one renderable.

        Args:
            objects (Iterable[Any]): Anything that Rich can render.
            sep (str): String to write between print data.
            end (str): String to write at end of print data.
            justify (str, optional): One of "left", "right", "center", or "full". Defaults to ``None``.
            emoji (Optional[bool], optional): Enable emoji code, or ``None`` to use console default.
            markup (Optional[bool], optional): Enable markup, or ``None`` to use console default.
            highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use console default.

        Returns:
            List[ConsoleRenderable]: A list of things to render.
        )rO   rP   rQ   N)r   rs   c                    s    t | tt d S r   )r+   r   r,   )r   )_appendrm   r[   r\   align_append  s    z2Console._collect_renderables.<locals>.align_appendrr   c                     s.   r*t d}  |  d d = d S )N)rm   r   )rE   join)sep_text)ra  r   rm   r  r  r[   r\   
check_text  s    z0Console._collect_renderables.<locals>.check_text)r  rq   r  )r  c                    s   g | ]}t | qS r[   rA   r   r   r   r[   r\   
<listcomp>  r   z0Console._collect_renderables.<locals>.<listcomp>)ra  r   r2  r)  r  r:   r}   r   r  rE   r   r9   r8   r   r  )rw   r  r  r   rm   r  rq   rp   r   append_textr  r  r  r   r[   )r  ra  r   rm   r  r   r  r\   _collect_renderablesz  sD    




zConsole._collect_renderablesu   ─z	rule.linerP   )
charactersr   align)titler  r   r  rs   c                C   s*   ddl m} |||||d}| | dS )u  Draw a line with optional centered title.

        Args:
            title (str, optional): Text to render over the rule. Defaults to "".
            characters (str, optional): Character(s) to form the line. Defaults to "─".
            style (str, optional): Style of line. Defaults to "rule.line".
            align (str, optional): How to align the title, one of "left", "center", or "right". Defaults to "center".
        r%   )Rule)r  r  r   r  N)ruler  r   )rw   r  r  r   r  r  r  r[   r[   r\   r    s    zConsole.rule)r~  rs   c                 G   sD   | j s@| & | jdd |D  W d   n1 s60    Y  dS )zInsert non-printing control codes.

        Args:
            control_codes (str): Control codes, such as those that may move the cursor.
        c                 s   s   | ]}|j V  qd S r   )segment)r   _controlr[   r[   r\   	<genexpr>  r   z"Console.control.<locals>.<genexpr>N)r4  r   r  )rw   r~  r[   r[   r\   r~    s    zConsole.controlr>  r   )r  r   r   rp   )r  r  r   r   rp   rs   c                G   s4   | dd |D }| j|||ddddd|d	 dS )a  Output to the terminal. This is a low-level way of writing to the terminal which unlike
        :meth:`~rich.console.Console.print` won't pretty print, wrap text, or apply markup, but will
        optionally apply highlighting and a basic style.

        Args:
            sep (str, optional): String to write between print data. Defaults to " ".
            end (str, optional): String to write at end of print data. Defaults to "\\n".
            style (Union[str, Style], optional): A style to apply to output. Defaults to None.
            highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use
                console default. Defaults to ``None``.
        c                 s   s   | ]}t |V  qd S r   )r   )r   _objectr[   r[   r\   r    r   zConsole.out.<locals>.<genexpr>FTrV   )r   rp   r  rq   ro   rn   rT   r   N)r  r   )rw   r  r   r   rp   r  
raw_outputr[   r[   r\   out  s    zConsole.out)r  r   r   rm   rn   ro   r  rq   rp   r`   ra   rT   r
  new_line_start)r  r  r   r   rm   rn   ro   r  rq   rp   r`   ra   rT   r
  r  rs   c             
   G   s  |st  f}|du r| j}|r:|du r*d}|du r6d}d}| jdd }| 8 | j|||||||	d}|D ]}||}ql| jj|||
durt|
| jnt	||||	d}g }|j
}| j}|du r|D ]}|||| qn&|D ] }|t|||| | q|r:tddd	 |D  d
kr:|dt  |rl| jj
}tj|| jddD ]}|| qZn| j
| W d   n1 s0    Y  dS )a[  Print to the console.

        Args:
            objects (positional args): Objects to log to the terminal.
            sep (str, optional): String to write between print data. Defaults to " ".
            end (str, optional): String to write at end of print data. Defaults to "\\n".
            style (Union[str, Style], optional): A style to apply to output. Defaults to None.
            justify (str, optional): Justify method: "default", "left", "right", "center", or "full". Defaults to ``None``.
            overflow (str, optional): Overflow method: "ignore", "crop", "fold", or "ellipsis". Defaults to None.
            no_wrap (Optional[bool], optional): Disable word wrapping. Defaults to None.
            emoji (Optional[bool], optional): Enable emoji code, or ``None`` to use console default. Defaults to ``None``.
            markup (Optional[bool], optional): Enable markup, or ``None`` to use console default. Defaults to ``None``.
            highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use console default. Defaults to ``None``.
            width (Optional[int], optional): Width of output, or ``None`` to auto-detect. Defaults to ``None``.
            crop (Optional[bool], optional): Crop output to width of terminal. Defaults to True.
            soft_wrap (bool, optional): Enable soft wrap mode which disables word wrapping and cropping of text or ``None`` for
                Console default. Defaults to ``None``.
            new_line_start (bool, False): Insert a new line at the start if the output contains more than one line. Defaults to ``False``.
        NTrV   Fr  )rm   rn   r`   ra   ro   rq   rp   r   c                 s   s   | ]}|j V  qd S r   )r  r   r  r[   r[   r\   r  Z  r   z Console.print.<locals>.<genexpr>r%   r   r  )r   r
  r:  r  r   r|   r   minr`   r   r  r3   r>   r  r  r   r  
splitlinesinsertr   r   r  )rw   r  r   r   rm   rn   ro   r  rq   rp   r`   ra   rT   r
  r  r  render_hooksr   r`  r  new_segmentsr  r3   r   buffer_extendr   r[   r[   r\   r     sr    %	

zConsole.print   )	dataindentrp   	skip_keysensure_asciicheck_circular	allow_nanrN   	sort_keys)jsonr  r  rp   r  r  r  r  rN   r  rs   c       	         C   sx   ddl m} |du r2|j||||||||	|
d	}n4t|tsLtd|d|||||||||	|
d	}| j|dd dS )	a  Pretty prints JSON. Output will be valid JSON.

        Args:
            json (Optional[str]): A string containing JSON.
            data (Any): If json is not supplied, then encode this data.
            indent (Union[None, int, str], optional): Number of spaces to indent. Defaults to 2.
            highlight (bool, optional): Enable highlighting of output: Defaults to True.
            skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
            ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
            check_circular (bool, optional): Check for circular references. Defaults to True.
            allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
            default (Callable, optional): A callable that converts values that can not be encoded
                in to something that can be JSON encoded. Defaults to None.
            sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
        r   )JSONN)r  rp   r  r  r  r  rN   r  z/json must be str. Did you mean print_json(data=z) ?T)r
  )pip._vendor.rich.jsonr  	from_datar}   r   r  r   )rw   r  r  r  rp   r  r  r  r  rN   r  r  json_renderabler[   r[   r\   
print_jsong  s:    

zConsole.print_json)regionr|   )r   r  r|   rs   c          
      C   sz   | j std|p| j}|du rBd }}||j|jp<| j}n|\}}}}|||}| j||d}	| |	|| dS )a  Update the screen at a given offset.

        Args:
            renderable (RenderableType): A Rich renderable.
            region (Region, optional): Region of screen to update, or None for entire screen. Defaults to None.
            x (int, optional): x offset. Defaults to 0.
            y (int, optional): y offset. Defaults to 0.

        Raises:
            errors.NoAltScreen: If the Console isn't in alt screen mode.

        0Alt screen must be enabled to call update_screenNr   r  )	r  r&   NoAltScreenr|   r   ri   ra   r  update_screen_lines)
rw   r   r  r|   r  r   r   r`   ra   r   r[   r[   r\   update_screen  s    

zConsole.update_screenr   r   c                 C   s>   | j stdt|||}| |}| j| |   dS )a  Update lines of the screen at a given offset.

        Args:
            lines (List[List[Segment]]): Rendered lines (as produced by :meth:`~rich.Console.render_lines`).
            x (int, optional): x offset (column no). Defaults to 0.
            y (int, optional): y offset (column no). Defaults to 0.

        Raises:
            errors.NoAltScreen: If the Console isn't in alt screen mode.
        r  N)r  r&   r  r   r3   r   r  r[  )rw   r   r   r   screen_updater   r[   r[   r\   r    s    

zConsole.update_screen_linesr  r    r[   r`   r  r   	word_wrapshow_localssuppress
max_frames)r`   r  r   r  r  r  r  rs   c          
   	   C   s0   ddl m} ||||||||d}	| |	 dS )a  Prints a rich render of the last exception and traceback.

        Args:
            width (Optional[int], optional): Number of characters used to render code. Defaults to 88.
            extra_lines (int, optional): Additional lines of code to render. Defaults to 3.
            theme (str, optional): Override pygments theme used in traceback
            word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.
            show_locals (bool, optional): Enable display of local variables. Defaults to False.
            suppress (Iterable[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
            max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.
        r%   )	Tracebackr  N)rg  r  r   )
rw   r`   r  r   r  r  r  r  r  rg  r[   r[   r\   print_exception  s    	zConsole.print_exception)r   currentframers   c                 C   sn   | d7 } | }|durL| r.|r.|j }| d8 } q|dus:J |jj|j|jfS t |  }|j|j|j	jfS dS )aE  Get caller frame information.

        Args:
            offset (int): the caller offset within the current frame stack.
            currentframe (Callable[[], Optional[FrameType]], optional): the callable to use to
                retrieve the current frame. Defaults to ``inspect.currentframe``.

        Returns:
            Tuple[str, int, Dict[str, Any]]: A tuple containing the filename, the line number and
                the dictionary of local variables associated with the caller frame.

        Raises:
            RuntimeError: If the stack offset is invalid.
        r%   N)
f_backf_codeco_filenamef_linenof_localsinspectstackfilenamelinenoframe)r   r  r  
frame_infor[   r[   r\   _caller_frame_info  s    
zConsole._caller_frame_info)	r  r   r   rm   r  rq   rp   
log_locals_stack_offset)r  r  r   r   rm   r  rq   rp   r  r   rs   c       	      
      sd  |
st  f}
| jdd }| . | j|
||||||d} durT fdd|D }| |	\}}}|drrdn
tj|}|tj	d }|rdd |
 D }|t|d	d
 | j| ||  |||dg}|D ]}||}qg }|j}| j}| j}|D ]}|||| q | jj}tj|| jddD ]}|| q0W d   n1 sV0    Y  dS )a  Log rich content to the terminal.

        Args:
            objects (positional args): Objects to log to the terminal.
            sep (str, optional): String to write between print data. Defaults to " ".
            end (str, optional): String to write at end of print data. Defaults to "\\n".
            style (Union[str, Style], optional): A style to apply to output. Defaults to None.
            justify (str, optional): One of "left", "right", "center", or "full". Defaults to ``None``.
            overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None.
            emoji (Optional[bool], optional): Enable emoji code, or ``None`` to use console default. Defaults to None.
            markup (Optional[bool], optional): Enable markup, or ``None`` to use console default. Defaults to None.
            highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use console default. Defaults to None.
            log_locals (bool, optional): Boolean to enable logging of locals where ``log()``
                was called. Defaults to False.
            _stack_offset (int, optional): Offset of caller from end of call stack. Defaults to 1.
        Nr  c                    s   g | ]}t | qS r[   rA   r  r   r[   r\   r  M  r   zConsole.log.<locals>.<listcomp><c                 S   s    i | ]\}}| d s||qS )__)ru   )r   keyrI  r[   r[   r\   r   S  s   
zConsole.log.<locals>.<dictcomp>z	[i]locals)r  )r  pathline_no	link_pathFr  )r   r:  r  r  ru   rv  r  abspathrR  r  itemsra  r<   r1  r  r   r  r3   r|   r   r>   r  r`   )rw   r  r   r   rm   r  rq   rp   r  r   r  r  r   r  r  localsr  r  
locals_mapr`  r  r  r3   r  r   r  r   r[   r   r\   log   sZ    	

zConsole.logc                 C   s"  | j r| jdd= dS | j | jdkr| jrdddlm} || j| | jdd  | jdd= n| | jdd }| jdd= |rz@tr| j	j
}|dD ]}|| qn| j	
| | j	  W n4 ty } z|j d|_ W Y d}~n
d}~0 0 W d   n1 s0    Y  dS )z$Check if the buffer may be rendered.Nr   r%   )displayTzG
*** You may need to add PYTHONIOENCODING=utf-8 to your environment ***)r  r   r   rH  r#  jupyterr  r   r   r  writer  flushUnicodeEncodeErrorreason)rw   r  r  r  r   r  r[   r[   r\   r[  r  s,    
zConsole._check_buffer)r   rs   c                 C   s   g }|j }| j}| j}| jrN| j | j| W d   n1 sD0    Y  | j }| jrj|rjt	
|}|D ]4\}}}	|r||j|||d qn|r|	sn|| qnd|}
|
S )z)Render buffered output, and clear buffer.N)r  rg   r   )ra  r-  rg   r  r6  r9  r  rj   r  r>   remove_colorr3   r  )rw   r   outputra  r  rg   not_terminalr  r   r~  renderedr[   r[   r\   r     s.    *



zConsole._render_buffer)rq   r  passwordstream)promptrq   r  r  r  rs   c          	      C   s   d}|rJ|   "}| j|||dd W d   n1 s80    Y  | }| jr`| j| d}|rrt||d}n"|r| j| | }nt|}|S )a5  Displays a prompt and waits for input from the user. The prompt may contain color / style.

        It works in the same way as Python's builtin :func:`input` function and provides elaborate line editing and history features if Python's builtin :mod:`readline` module is previously loaded.

        Args:
            prompt (Union[str, Text]): Text to render in the prompt.
            markup (bool, optional): Enable console markup (requires a str prompt). Defaults to True.
            emoji (bool, optional): Enable emoji (requires a str prompt). Defaults to True.
            password: (bool, optional): Hide typed text. Defaults to False.
            stream: (TextIO, optional): Optional file to read input from (rather than stdin). Defaults to None.

        Returns:
            str: Text read from stdin.
        r   )rq   r  r   N)r  )	r  r   r   rg   r  r  r   readlineinput)	rw   r  rq   r  r  r  
prompt_strr  resultr[   r[   r\   r    s    
0
zConsole.inputr  r   )r  r   rs   c                C   sz   | j sJ d| jR |r2ddd | jD }nddd | jD }|rX| jdd= W d   n1 sl0    Y  |S )a  Generate text from console contents (requires record=True argument in constructor).

        Args:
            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
            styles (bool, optional): If ``True``, ansi escape codes will be included. ``False`` for plain text.
                Defaults to ``False``.

        Returns:
            str: String containing console contents.

        ITo export console contents set record=True in the constructor or instancer   c                 s   s&   | ]\}}}|r| |n|V  qd S r   r2   )r   r  r   _r[   r[   r\   r    s   z&Console.export_text.<locals>.<genexpr>c                 s   s   | ]}|j s|jV  qd S r   )r~  r  r  r[   r[   r\   r    s   N)r  r6  r  r9  )rw   r  r   r  r[   r[   r\   export_text  s    


*zConsole.export_text)r  r  r   rs   c                C   sJ   | j ||d}t|ddd}|| W d   n1 s<0    Y  dS )a  Generate text from console and save to a given location (requires record=True argument in constructor).

        Args:
            path (str): Path to write text files.
            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
            styles (bool, optional): If ``True``, ansi style codes will be included. ``False`` for plain text.
                Defaults to ``False``.

        r  wtrm  rk   N)r!  openr  )rw   r  r  r   r  
write_filer[   r[   r\   	save_text  s    
zConsole.save_textr   r  code_formatinline_styles)r   r  r(  r)  rs   c             	   C   s  | j sJ dg }|j}|pt}d}|du r0tn|}	| j |rtt| jD ]\\}
}}t	|
}
|r|
|}|jrd|j d|
 d}
|rd| d|
 dn|
}
||
 qTni }tt| jD ]t\}
}}t	|
}
|r6|
|}||t|d	 }|jr$d
| d|j d|
 d}
nd| d|
 d}
||
 qg }|j}| D ]&\}}|rR|d| d| d qRd|}|	jd|||jj|jjd}|r| jdd= W d   n1 s0    Y  |S )a  Generate HTML from console contents (requires record=True argument in constructor).

        Args:
            theme (TerminalTheme, optional): TerminalTheme object containing console colors.
            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
            code_format (str, optional): Format string to render HTML, should contain {foreground}
                {background} and {code}.
            inline_styles (bool, optional): If ``True`` styles will be inlined in to spans, which makes files
                larger but easier to cut and paste markup. If ``False``, styles will be embedded in a style tag.
                Defaults to False.

        Returns:
            str: String containing console contents as HTML.
        r  r   Nz	<a href="z">z</a>z<span style="z</span>r%   z<a class="rz" href="z<span class="rz.rz {}r   )code
stylesheet
foreground
background)r  ra  rC   CONSOLE_HTML_FORMATr6  r>   filter_controlsimplifyr9  r	   get_html_styler  
setdefaultr   r	  r  formatforeground_colorhexbackground_color)rw   r   r  r(  r)  	fragmentsra  _themer,  render_code_formatr  r   r   r  r   style_numberstylesheet_rulesstylesheet_append
style_rulerendered_coder[   r[   r\   export_html  s`    






,zConsole.export_html)r  r   r  r(  r)  rs   c                C   sN   | j ||||d}t|ddd}|| W d   n1 s@0    Y  dS )a  Generate HTML from console contents and write to a file (requires record=True argument in constructor).

        Args:
            path (str): Path to write html file.
            theme (TerminalTheme, optional): TerminalTheme object containing console colors.
            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.
            code_format (str, optional): Format string to render HTML, should contain {foreground}
                {background} and {code}.
            inline_styles (bool, optional): If ``True`` styles will be inlined in to spans, which makes files
                larger but easier to cut and paste markup. If ``False``, styles will be embedded in a style tag.
                Defaults to False.

        r'  r"  rm  r#  N)r@  r$  r  )rw   r  r   r  r(  r)  htmlr%  r[   r[   r\   	save_htmlM  s    zConsole.save_html)NFF)r%   )T)T)T)TN)N)N)r   )N)r   r   )r   )yrX   rY   rZ   rb   rv  environr  r   r   rd   r1   r   r"   r   rG   r   rc   r@   r/   r   r)   r   r   floatr   r@  r   r  setterr   r>   r   rH  rH   rJ  r-   r.  r   r   r^  r_  r   rb  rd  r   r   r   r   r   r   r   r   rk  r  rk   rj   r4  re   r|   r_   rf   r   r`   ra   r  r   r  r6   r   r   r   r  r   r  r   r   r  r   r4   r  r   r3   r?   r  r   r   r  r  r  r   r  rF   r,   r  r.   r~  r  r   r  r;   r  r  r   r  staticmethodr  r  r   r   r  r  r[  r   r   r  r!  r&  rD   r@  r/  rB  r[   r[   r[   r\   r   D  s  
#

p	-
 

!	  5 
9
<$M 
#e A# #%R * Or   __main__zJSONRPC [i]request[/i]   g?z2.0subtract*      )minuend
subtrahendr    )Zjsonrpcr   paramsidzHello, World!z{'a': 1}z&Which one is correct team name in NBA?)zNew York BullszLos Angeles KingszGolden State WarriorsHuston RocketrP  )questionr|   Zanswer)answeredq1z	5 + 7 = ?)
            rV  z
12 - 8 = ?)r%   r  r       rX  )rR  rS  q2)ZsportZmaths)r   emptyZquizZfoo)T)r  rv  platformrB  r0  abcr   r   dataclassesr   r   r   	functoolsr   r   rA  r	   r
   	itertoolsr   r   timer   typesr   r   r   typingr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   version_infor"   r#   r$   Zpip._vendor.typing_extensionsr   r&   r'   r(   r1  r)   r*   r  r+   r,   colorr-   r~  r.   r  r/   r  r0   r1   rq   r3   r  r  r4   r5   r   r6   r7   prettyr8   r9   protocolr:   r  r;   scoper<   r   r=   r  r>   r   r?   r@   styledrB   terminal_themerC   rD   r  rE   rF   r   rG   rH   r   rI   r\  rJ   r  rL   r   r   r   r  r   r   rW   r   r/  rP  rT  rS  r_   re   r   r   r   r   r2  	Exceptionr   r   r   r   r   r   r   r   r   r   r   rO  r/  r	  rl  localr   r   r   rd   r   r  pip._vendor.coloramar  r   rX   r   r  reprr   r[   r[   r[   r\   <module>   s  
D	{
!'/!"

            5
"