HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/pip/_vendor/rich/__pycache__/console.cpython-310.pyc
o

@%NeT=�
@sDUddlZddlZddlZddlZddlZddlmZmZddlm	Z	m
Z
ddlmZddlm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZmZmZdd
lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*ej+dkr�ddlm,Z,m-Z-m.Z.n
ddl/m,Z,m-Z-m.Z.ddl0m1Z1m2Z2ddl3m3Z3ddl4m5Z5m6Z6ddl7m8Z8m9Z9ddl:m;Z;ddl<m=Z=ddl>m?Z?ddl@mAZAmBZBddlCmDZEddlFmGZGmHZHddlImJZJmKZKddlLmMZMmNZNddlOmPZPddlQmRZRddlSmTZTdd lUmVZVdd!lWmXZXdd"lYmZZZm[Z[dd#l\m]Z]dd$l^m_Z_m`Z`dd%lambZbmcZcdd&ldmeZemfZfe�rJdd'lgmhZhdd(limjZjdd)lkmlZle�m�d*kZnee)eod+fgd+fZpe,d,Zqe,d-ZrGd.d/�d/�Zses�Ztd0Zue;jve;jwd1�ZxGd2d3�d3e$�Zye	Gd4d5�d5��Zze.Gd6d7�d7e-��Z{e.Gd8d9�d9e-��Z|e)e|e{eofZ}e!e)e}eXfZ~eA�ZGd:d;�d;e��Z�Gd<d=�d=�Z�Gd>d?�d?�Z�Gd@dA�dA�Z�GdBdC�dC�Z�GdDdE�dE�Z�GdFdG�dG�Z�GdHdI�dI�Z�d�dKe�dLedMedMe�fffdNdO�Z�dLe�fdPdQ�Z�e;jwe;jve;j�e;jndR�Z�dSdT�e����D�Z�e	GdUdV�dVej���Z�GdWdX�dXe�Z�da�e%dYe�dZ<d�d[d\�Z�dLe�fd]d^�Z�e���rIdd_l�m�Z�e�d`da�Gdbdc�dc�Z�e�ddk�r�e��Z�e���dedfdgdJd`ddhdidjdkdl�dmdn��e���dodpe�e���e���dgdJdqgdr�dsdt�du�d`dvgdw�dxdt�dygdz�d{dt�d|�d}�d~��e���d�dSdS)��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eZdZdS)�NoChangeN)�__name__�
__module__�__qualname__�r[r[�:/usr/lib/python3/dist-packages/pip/_vendor/rich/console.pyrWOsrWa9<!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$eZdZUdZeed<	eed<dS)�ConsoleDimensionszSize of the terminal.�width�heightN)rXrYrZ�__doc__�int�__annotations__r[r[r[r\r_ns
r_c@s�eZdZUdZeed<	eed<	eed<	eed<	eed<	eed<	eed<	d	Z	e
eed
<	d	Ze
e
ed<	dZe
eed
<	d	Ze
eed<	d	Ze
eed<	d	Ze
eed<edefdd��Zd dd�Zeeeeeeeeed�	deeefdeeefdeeefd
ee
eefdee
e
efd
ee
eefdee
eefdee
eefdee
eefddfdd�Zdeddfdd�Zdeddfdd�Zdededdfdd�Zd	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�returncCs|j�d�S)z+Check if renderables should use ascii only.�utf)rk�
startswith��selfr[r[r\�
ascii_only�szConsoleOptions.ascii_onlycCst�t�}|j��|_|S)zdReturn a copy of the options.

        Returns:
            ConsoleOptions: a copy of self.
        )re�__new__�__dict__�copy)rv�optionsr[r[r\rz�s
zConsoleOptions.copy)	r`rhrirmrnrorprqrar`c	Cs�|��}
t|t�std|�|
_|
_t|t�s||
_t|t�s"||
_t|t�s*||
_t|t�s2||
_t|t�s:||
_t|t�sB||
_	t|t�sJ||
_
t|	t�sb|	durV|	|
_|	dur\dntd|	�|
_|
S)zUpdate values, return a copy.rN)
rz�
isinstancerW�maxrhrirmrnrorprqrlra)rvr`rhrirmrnrorprqrar{r[r[r\�update�s,








zConsoleOptions.updatecCs|��}td|�|_|_|S)z�Update 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)rzr}rhri)rvr`r{r[r[r\�update_width�s	zConsoleOptions.update_widthcCs|��}||_|_|S)z�Update the height, and return a copy.

        Args:
            height (int): New height

        Returns:
            ~ConsoleOptions: New Console options instance.
        )rzrlra)rvrar{r[r[r\�
update_height�s	zConsoleOptions.update_heightcCs*|��}td|�|_|_||_|_|S)aUpdate 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)rzr}rhrirarl)rvr`rar{r[r[r\�update_dimensions�s
z ConsoleOptions.update_dimensions)rrre)rXrYrZrbr_rd�boolrc�strrmr�
JustifyMethodrn�OverflowMethodrorprqra�propertyrwrz�	NO_CHANGErrWr~rr�r�r[r[r[r\rews~


�
�
�
����	�
��
�%

rec@s&eZdZdZdedeffdd�ZdS)�RichCastz5An object that may be 'cast' to a console renderable.rr�ConsoleRenderablecC�dS�Nr[rur[r[r\�__rich__�szRichCast.__rich__N)rXrYrZrbrr�r�r[r[r[r\r��sr�c@s&eZdZdZ						ddd	�Zd
S)r�z-An object that supports the console protocol.�console�Consoler{rerr�RenderResultcCr�r�r[�rvr�r{r[r[r\�__rich_console__�sz"ConsoleRenderable.__rich_console__N)r�r�r{rerrr�)rXrYrZrbr�r[r[r[r\r��s���r�c@seZdZdZdS)�CaptureErrorz(An error in the Capture context manager.N)rXrYrZrbr[r[r[r\r�sr�c@s>eZdZdZddeddfdd�Zdd	d
ddeefdd
�ZdS)�NewLinez$A renderable to generate new line(s)r%�countrrNcCs
||_dSr�)r��rvr�r[r[r\�__init__s
zNewLine.__init__r�r�r{reccs�td|j�VdS)N�
)r>r�r�r[r[r\r�s�zNewLine.__rich_console__�r%)	rXrYrZrbrcr�rr>r�r[r[r[r\r�s���r�c@sHeZdZdZdeeedededdfdd�Zd	d
dede	fdd
�Z
dS)�ScreenUpdatez)Render a list of lines at a given offset.�lines�x�yrrNcC�||_||_||_dSr�)�_linesr�r�)rvr�r�r�r[r[r\r�#�
zScreenUpdate.__init__r�r�r{ccs@�|j}tj}t|j|j�D]\}}|||�V|EdHqdSr�)r�r.�move_to�	enumerater�r�)rvr�r{r�r��offset�liner[r[r\r�(s��zScreenUpdate.__rich_console__)rXrYrZrbrr>rcr�rer�r�r[r[r[r\r� s"���r�c@s\eZdZdZddd�Zddd	�Zd
eeedeedee	ddfd
d�Z
defdd�ZdS)�Capturez�Context 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�r�rrNcCs||_d|_dSr�)�_console�_result)rvr�r[r[r\r�:s
zCapture.__init__cC�|j��|Sr�)r��
begin_capturerur[r[r\�	__enter__>�
zCapture.__enter__�exc_type�exc_val�exc_tbcCs|j��|_dSr�)r��end_capturer��rvr�r�r�r[r[r\�__exit__BszCapture.__exit__cCs|jdur	td��|jS)zGet the result of the capture.Nz<Capture result is not available until context manager exits.)r�r�rur[r[r\�getJs

�zCapture.get)r�r�rrN)rrr�)
rXrYrZrbr�r�rr�
BaseExceptionrr�r�r�r[r[r[r\r�2s


���
�r�c	@s`eZdZdZddddededdfd	d
�Zddd�Zd
ee	e
dee
deeddfdd�ZdS)�ThemeContextzbA context manager to use a temporary theme. See :meth:`~rich.console.Console.use_theme` for usage.Tr�r��theme�inheritrrNcCr�r�)r�r�r�)rvr�r�r�r[r[r\r�Vr�zThemeContext.__init__cCs|j�|j�|Sr�)r��
push_themer�rur[r[r\r�[szThemeContext.__enter__r�r�r�cCs|j��dSr�)r��	pop_themer�r[r[r\r�_szThemeContext.__exit__�T)rrr�)
rXrYrZrbrGr�r�r�rrr�rr�r[r[r[r\r�Ss

����r�c@sneZdZdZ			ddddeededed	df
d
d�Zddd
�Zdee	e
dee
deed	dfdd�ZdS)�PagerContextzZA context manager that 'pages' content. See :meth:`~rich.console.Console.pager` for usage.NFr�r��pager�styles�linksrrcCs*||_|dur
t�n||_||_||_dSr�)r�r7r�r�r�)rvr�r�r�r�r[r[r\r�ks
zPagerContext.__init__cCr�r�)r��
_enter_bufferrur[r[r\r�wr�zPagerContext.__enter__r�r�r�cCs�|durF|jj�0|jjdd�}|jjdd�=|}|js#t�|�}n|js+t�|�}|j�|�}Wd�n1s;wY|j	�
|�|j��dSr�)r��_lock�_bufferr�r>�strip_stylesr��strip_links�_render_bufferr��show�_exit_buffer)rvr�r�r��buffer�segments�contentr[r[r\r�{s

�	zPagerContext.__exit__�NFF)rrr�)
rXrYrZrbrr6r�r�r�rr�rr�r[r[r[r\r�hs4�����
�

����r�c	@s�eZdZdZ	ddddededdfd	d
�Zdd�dedeeddfd
d�Z	ddd�Z
deeedeedee
ddfdd�ZdS)�
ScreenContextziA context manager that enables an alternative screen. See :meth:`~rich.console.Console.screen` for usage.�r�r��hide_cursor�stylerrNcCs"||_||_t|d�|_d|_dS)N�r�F)r�r�r=�screen�_changed)rvr�r�r�r[r[r\r��s
zScreenContext.__init__r��renderablescGsJ|rt|�dkrt|�n|d|j_|dur||j_|jj|jdd�dS)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%rNr�)�end)�len�Groupr��
renderabler�r��print)rvr�r�r[r[r\r~�s
�zScreenContext.updatecCs*|j�d�|_|jr|jr|j�d�|S)NTF)r��set_alt_screenr�r��show_cursorrur[r[r\r��szScreenContext.__enter__r�r�r�cCs0|jr|j�d�|jr|j�d�dSdSdS)NFT)r�r�r�r�r�r�r[r[r\r��s�zScreenContext.__exit__�r�)rrr�)rXrYrZrbr�r@r��RenderableTyperr~r�rr�rr�r[r[r[r\r��s<����
�	���
�

����r�c@sneZdZdZdd�dddeddfd	d
�Zededfdd��Z	
					ddd�Z	d
dddde
fdd�ZdS)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�r�r�rrNcGs||_||_d|_dSr�)�_renderablesr��_render)rvr�r�r[r[r\r��r�zGroup.__init__cCs|jdurt|j�|_|jSr�)r��listr�rur[r[r\r��s
zGroup.renderablesr�r�r{rer4cCs"|jr
t|||j�St|j|j�Sr�)r�r5r�r4rir�r[r[r\�__rich_measure__�szGroup.__rich_measure__ccs�|jEdHdSr�)r�r�r[r[r\r��s�zGroup.__rich_console__)r�r�r{rerrr4)rXrYrZrbr�r�r�rr�r�r�r�r[r[r[r\r��s&��
����r�Tr�rr.cs.dtdttfdtdtff�fdd�}|S)z�A 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.
    �method.rrcs(t��dtdtdtf��fdd��}|S)zGConvert a method that returns an iterable of renderables in to a Group.�args�kwargsrrcs�|i|��}t|d�i�S)Nr�)r�)r�r�r�)r�r�r[r\�_replace�sz*group.<locals>.decorator.<locals>._replace)rrr�)r�r�r�)r�r\�	decorator�szgroup.<locals>.decorator)rrr�r�)r�r�r[r�r\�group�s�
�r�cCsVztWn
tyYdSwt�}|jj}dt|j�vs!|dkr#dS|dkr)dSdS)z-Check if we're running in a Jupyter notebook.Fzgoogle.colab�ZMQInteractiveShellT�TerminalInteractiveShell)�get_ipython�	NameError�	__class__rXr�)�ipython�shellr[r[r\�_is_jupyter�s�r�)�standard�256�	truecolor�windowscCsi|]\}}||�qSr[r[)�.0�name�systemr[r[r\�
<dictcomp>
�r�c@s<eZdZUdZeed<eed�Ze	e
ed<dZeed<dS)�ConsoleThreadLocalsz(Thread local values for Console context.�theme_stack)�default_factoryr�r�buffer_indexN)
rXrYrZrbrHrdrr�r�rr>r�rcr[r[r[r\r�s

r�c@s.eZdZdZedeedeefdd��ZdS)�
RenderHookz(Provides hooks in to the render process.r�rrcCsdS)aLCalled 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[)rvr�r[r[r\�process_renderablesszRenderHook.process_renderablesN)rXrYrZrbrrr�r�r[r[r[r\r�s��r�rI�_windows_console_featurescCs"tdurtSddlm}|�atS)Nr%��get_windows_console_features)r��_windowsr�r�r[r[r\r�/s
r�cCstot�jS)zDetect legacy Windows.)�WINDOWSr��vtr[r[r[r\�detect_legacy_windows9�r)�initF)�stripc<@s
eZdZUdZejZeeefe	d<dddddddddddddddddddddde
�dddddd	�d
eeddee
d
ee
dee
de
deede
deeede
deedeedeedee
dede
de
de
deede
de
de
d eeefd!ed"d#ee
d$e
d%eegefd&eegefdeeeeff8d'd(�Zd)efd*d+�Zed)eefd,d-��Zejd.eed)dfd/d-��Zed)eefd0d1��Zed)efd2d3��Z e jd4ed)dfd5d3��Z ed)e!fd6d7��Z"d)ee#fd8d9�Z$�dd:d;�Z%�dd<d=�Z&�dd@dA�Z'�ddBdC�Z(dDe)d)dfdEdF�Z*�ddGdH�Z+�ddIdJ�Z,dKe-dLe-dMe-d)dfdNdO�Z.�ddPdQ�Z/d)efdRdS�Z0ddT�dedUe
d)dfdVdW�Z1�ddXdY�Z2ddT�dedUe
d)e3fdZd[�Z4ed)eefd\d]��Z5ed)efd^d_��Z6ed)e
fd`da��Z7ed)e
fdbdc��Z8ed)e9fddde��Z:ed)e;fdfdg��Z<e<jdhe=eefd)dfdidg��Z<ed)efdjdk��Z>e>jded)dfdldk��Z>ed)efdmdn��Z?e?jded)dfdodn��Z?�ddpdq�Z@d)eAfdrds�ZB	�ddteeCdue
dve
d)eDfdwdx�ZE�ddzed)dfd{d|�ZF�dd}e
d)dfd~d�ZGd�d�d�d�d��d�eHd�ed�ed�ed�ed)d�fd�d��ZI�dd�e
d)e
fd�d��ZJ�dd�e
d)e
fd�d��ZKed)e
fd�d���ZL	�dd�e
deed)d�fd�d��ZMdd��d�eHd�ee9d)eNfd�d��ZO	�dd�eHd�ee9d)ePefd�d��ZQ	�ddddd��d�eHd�ee9deeRd�e
d�e
d)eeefd�d��ZSd�ddddddd��d�edeeeRfd�eeTd�eeUdee
dee
dee
d!eeVd)d�fd�d��ZWdd��d�eeeRfd�eeeRefd)eRfd�d��ZXddddd��d�ePe-d�ed�ed�eeTdee
dee
dee
d)eeYfd�d��ZZ	��dd�d�d�d��d�e[d�edeeeRfd�e\d)df
d�d��Z]d�e^d)dfd�dÄZ_d�d�dddƜd�e-d�ed�edeeeeRfdee
d)dfd�dȄZ`d�d�dddddddddddddɜd�e-d�ed�edeeeeRfd�eeTd�eeUd�ee
dee
dee
dee
deedeed�e
dee
d�e
d)df d�d΄Za	�ddd�ddddddddМ	d�eed�e-d�edeefde
d�e
d�e
d�e
d�e
d�eee-ge-fd�e
d)dfd�dڄZbdddۜd�eHd�eecd�ee9d)dfd�dބZd	ߐdd�eeed�ed�ed)dfd�d�Zed�d�dddd�d�d�deed�edeed�e
d�e
d�ePeeeffd�ed)dfd�d�Zgeheijjfd�ed�egeekfd)e=eeelee-fffd�d��Zmd�d�dddddddyd�	d�e-d�ed�edeeeeRfd�eeTdee
dee
dee
d�e
d�ed)dfd�d��Zn�dd�d��Zod�ePed)efd�d��Zp	��dddddd��d�e[de
de
�de
�deeqd)ef�d�d�Zrdd�d��de
due
d)ef�d�d�Zsdd�d��de�de
due
d)df�d	�d
�Ztdddd�d�deeu�de
�dee�d
e
d)ef
�d�d�Zvddewd�d��dedeeu�de
�de�d
e
d)df�d�d�ZxdS(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`rar��no_color�tab_size�recordrq�emoji�
emoji_variantrp�log_time�log_path�log_time_format�highlighterrg�safe_box�get_datetime�get_timerr	)rr�r�r�r�r
rrr
r�rrrr`rar�rrrrqrrrprrrr�HighlighterTypergrrrcCs|dur||_|durt�n||_|jr|
pd}
|pd}||_|
|_||_||_||_||_||_	||_
||_|durBt�oA|jn||_
|
dur^|j�d�}|dur^|��r^t|�|j
}
|durt|j�d�}|durt|��rtt|�}||_|
|_||_|||_||_|	|_||_|dur�d|_n|dkr�|��|_nt||_t��|_t|||d�|_|p�t|_||_|p�t j!|_"|p�t#|_$||_%|
dur�|
nd|jv|_&|dur�|j'o�|j(n||_)t��|_*t+t,|dur�t-j.n|�d�|_/g|_0g|_1d|_2d	|_3dS)
N�]�d�COLUMNS�LINESr)�	show_time�	show_path�time_format�NO_COLOR)r�F)4rr��
is_jupyterr
�_width�_heightrr�_markup�_emoji�_emoji_variant�
_highlightrrgr��isdigitrc�_force_terminal�_filerr�
_color_system�_detect_color_system�
COLOR_SYSTEMS�	threadingrr�r*�_log_render�_null_highlighterrrr�nowrr
rr�rrj�is_dumb_terminal�is_interactive�_record_buffer_lockr�rHr'�DEFAULT�_thread_locals�_record_buffer�
_render_hooks�_live�_is_alt_screen)rvr	r
rrr
r�rrrr`rar�rrrrqrrrprrrrrgrrrr�columnsr�r[r[r\r�js�#���

�

����
�
zConsole.__init__rrcCsd|j�dt|j��d�S)Nz<console width=� �>)r`r�r0rur[r[r\�__repr__�szConsole.__repr__cCs(|jp|jr	tjntj}t|d|�}|S)z Get the file object to write to.�rich_proxied_file)r/r�sys�stdout�getattr)rvrr[r[r\r�szConsole.file�new_filecC�
||_dS)zSet a new file object.N)r/)rvrHr[r[r\r�s
cC�|jjS�zGet a thread local buffer.)r;r�rur[r[r\r���zConsole._buffercCrJrK�r;r�rur[r[r\�
_buffer_index�rLzConsole._buffer_index�valuecCs||j_dSr�rM)rvrOr[r[r\rN��cCrJ)z!Get the thread local theme stack.)r;r�rur[r[r\�_theme_stack�rLzConsole._theme_stackcCs�|jrtjS|jr|jrdStr"|jrtjSt�}|jrtjStj	S|j
�dd����
�}|dvr4tjS|j
�dd����
�}|�d�\}}}t�|tj�}|S)z"Detect color system from env vars.N�	COLORTERMr�)r��24bit�TERM�-)r&r-�	TRUECOLORrjr7rrgr�r��	EIGHT_BITrr�r�lower�
rpartition�_TERM_COLORS�STANDARD)rv�windows_console_features�
color_term�term�
_term_name�_hyphen�colorsr	r[r[r\r1�s(���zConsole._detect_color_systemcCs|jd7_dS)z4Enter in to a buffer context, and buffer all output.r%N)rNrur[r[r\r��zConsole._enter_buffercCs|jd8_|��dS)z5Leave buffer context, and render content if required.r%N)rN�
_check_bufferrur[r[r\r�szConsole._exit_buffer�liverJcCsF|j�|jdurt�d��||_Wd�dS1swYdS)z�Set 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)rvrdr[r[r\�set_lives
	

"�zConsole.set_livecCs2|j�d|_Wd�dS1swYdS)zClear the Live instance.N)r�r>rur[r[r\�
clear_live+s"�zConsole.clear_live�hookcCs8|j�|j�|�Wd�dS1swYdS)zpAdd a new render hook to the stack.

        Args:
            hook (RenderHook): Render hook instance.
        N)r�r=�append)rvrhr[r[r\�push_render_hook0s"�zConsole.push_render_hookcCs6|j�|j��Wd�dS1swYdS)z'Pop the last renderhook from the stack.N)r�r=�poprur[r[r\�pop_render_hook9s"�zConsole.pop_render_hookcCs|��|S)z,Own context manager to enter buffer context.�r�rur[r[r\r�>szConsole.__enter__r��	exc_value�	tracebackcC�|��dS)zExit buffer context.N)r�)rvr�rnror[r[r\r�CrPzConsole.__exit__cCrp)z`Begin capturing console output. Call :meth:`end_capture` to exit capture mode and return output.Nrmrur[r[r\r�GrPzConsole.begin_capturecCs$|�|j�}|jdd�=|��|S)zhEnd capture mode and return captured string.

        Returns:
            str: Console output.
        N)r�r�r�)rv�
render_resultr[r[r\r�KszConsole.end_capture�r�r�cCs|jj||d�dS)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.
        rrN)rQr��rvr�r�r[r[r\r�Vs	zConsole.push_themecCs|j��dS)z9Remove theme from top of stack, restoring previous theme.N)rQr�rur[r[r\r�arzConsole.pop_themecCst|||�S)aUse 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�rsr[r[r\�	use_themees
zConsole.use_themecCs|jdur
t|jSdS)zpGet color system string.

        Returns:
            Optional[str]: "standard", "256" or "truecolor".
        N)r0�_COLOR_SYSTEMS_NAMESrur[r[r\r	qs

zConsole.color_systemcCst|jdd�pd��S)zGet the encoding of the console file, e.g. ``"utf-8"``.

        Returns:
            str: A standard encoding string.
        rk�utf-8)rGrrXrur[r[r\rk~szConsole.encodingcCsJ|jdur|jSt|jdd�}z|durdWS|�WSty$YdSw)z�Check 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.rGr�
ValueError)rvrwr[r[r\rj�s
�zConsole.is_terminalcCs$|j�dd�}|��dv}|jo|S)zxDetect dumb terminal.

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

        rTr�)�dumb�unknown)rr�rXrj)rv�_term�is_dumbr[r[r\r7�s
zConsole.is_dumb_terminalc	Cs$t|jj|j|jd|j|j|jd�S)zGet default console options.r%)rlrfrgrhrirkrj)rerfrargr`rkrjrur[r[r\r{�s�zConsole.optionsc
CsV|jdur|jdurt|j|j|j�S|jrtdd�Sd}d}tr4zt��\}}Wn;ty3Yn3wzt�t	j
���\}}Wn%tt
tfyezt�t	j���\}}Wntt
tfybYnwYnw|j�d�}|durx|��rxt|�}|j�d�}|dur�|��r�t|�}|p�d}|p�d}t|jdur�||jn|j|jdur�|�S|j�S)zGet the size of the console.

        Returns:
            ConsoleDimensions: A named tuple containing the dimensions.
        N�P�r r!)r'r(r_rgr7r�os�get_terminal_size�OSErrorrE�	__stdin__�fileno�AttributeErrorrx�
__stdout__rr�r-rc)rvr`rar@r�r[r[r\rf�sH
������zConsole.size�new_sizecCs|\}}||_||_dS)zvSet a new size for the terminal.

        Args:
            new_size (Tuple[int, int]): New width and height.
        N)r'r()rvr�r`rar[r[r\rf�s
cCrJ)zsGet the width of the console.

        Returns:
            int: The width (in characters) of the console.
        )rfr`rur[r[r\r`��z
Console.widthcCrI)zFSet width.

        Args:
            width (int): New width.
        N)r')rvr`r[r[r\r`��
cCrJ)zpGet the height of the console.

        Returns:
            int: The height (in lines) of the console.
        )rfrarur[r[r\ra�r�zConsole.heightcCrI)zISet height.

        Args:
            height (int): new height.
        N)r()rvrar[r[r\rar�cCs|�t���dS)z3Play a 'bell' sound (if supported by the terminal).N)�controlr.�bellrur[r[r\r�rbzConsole.bellcCs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�)rv�capturer[r[r\r�szConsole.capturer�r�r�cCst||||d�S)aA 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�)rvr�r�r�r[r[r\r�%sz
Console.pagerr%r�cCs"|dksJd��|�t|��dS)zqWrite new line(s).

        Args:
            count (int, optional): Number of new lines. Defaults to 1.
        rzcount must be >= 0N)r�r�r�r[r[r\r�<szConsole.line�homecCs.|r|�t��t���dS|�t���dS)z�Clear the screen.

        Args:
            home (bool, optional): Also move the cursor to 'home' position. Defaults to True.
        N)r�r.�clearr�)rvr�r[r[r\r�Fsz
Console.clear�dotszstatus.spinnerg�?g)@)�spinner�
spinner_style�speed�refresh_per_second�statusr�r�r�r�rLcCs$ddlm}|||||||d�}|S)atDisplay 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)rvr�r�r�r�r�rL�status_renderabler[r[r\r�Qs�zConsole.statusr�cCs$|jr|js|�t�|��dSdS)zqShow or hide the cursor.

        Args:
            show (bool, optional): Set visibility of the cursor.
        TF)rjrgr�r.r�)rvr�r[r[r\r�rszConsole.show_cursor�enablecCs.d}|jr|js|�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)rjrgr�r.�
alt_screenr?)rvr��changedr[r[r\r�}szConsole.set_alt_screencCs|jS)z�Check if the alt screen was enabled.

        Returns:
            bool: True if the alt screen was enabled, otherwise False.
        )r?rur[r[r\�
is_alt_screen�szConsole.is_alt_screenr�r�cCst|||pdd�S)auContext 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�)rvr�r�r[r[r\r��szConsole.screen�r{r�r{cCst�||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.
        )r4r�r{)rvr�r{�measurementr[r[r\�measure�szConsole.measurec	cs��|p|j}|jdkr
dSt|�}t|d�r!t|�s!|�||�}nt|t�r7|j||j	|j
d�}|�||�}n	t�d|�d���zt
|�}WntyVt�d|�d���wt}|D]}t||�rf|Vq[|�||�EdHq[dS)	akRender 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�)rprqzUnable to render zC; A str, Segment or object with __rich_console__ method is requiredzobject z is not renderable)r{rir:�hasattrr
r�r|r��
render_strrprqr&�NotRenderableError�iter�	TypeErrorr>r3)	rvr�r{�_options�render_iterable�text_renderable�iter_render�_Segment�
render_outputr[r[r\r3�s8�



�
�
��
�zConsole.render)r��pad�	new_linesr�r�c	Cs�|j�]|p|j}|�||�}|rt�||�}tttj||j||d�d|j	��}|j	durW|j	t
|�}	|	dkrW|rFtd|j|�td�gntd|j|�gg}
|�|
|	�|Wd�S1scwYdS)aGRender 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�NrrAr�)r�r{r3r>�apply_styler�r�split_and_crop_linesrirar��extend)rvr�r{r�r�r��render_options�	_renderedr��extra_lines�pad_liner[r[r\�render_lines�s6
���
��$�zConsole.render_linesr�)r�rmrnrrqrpr�textrmrnrEcCs�|p|duo|j}	|p|duo|j}
|p|duo|j}|
r-t|||	|jd�}||_||_nt|	r7t||jd�n||||d�}|rE|pD|j	nd}
|
durX|
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�rr)�default_variant)rmrnr�)r*r)r,�
render_markupr+rmrnrEr(rr��copy_styles)rvr�r�rmrnrrqrpr�
emoji_enabled�markup_enabled�highlight_enabled�	rich_text�_highlighter�highlight_textr[r[r\r�!s8���	�
zConsole.render_str)rNr�rNc
Cs�t|t�r|Sz|j�|�}|durt�|�}|jr|��WS|WStjyI}z|dur9|�	|�WYd}~St�
d|�d|���d�d}~ww)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.

        NzFailed to get style z; )r|r?rQr��parse�linkrzr&�StyleSyntaxError�	get_style�MissingStyle)rvr�rNr��errorr[r[r\r�\s"

����zConsole.get_style�rmrrqrp�objects�sepr�cs2g}|j�g��j}	���dvrdtddf��fdd�}
|
�t}|s)|dur,|jr,|j}d
�����fdd�}|D]F}
t|
�}
t|
t�rP|	|j|
|||d	��q9t|
t	�rZ|	|
�q9t|
t
�rg|��|
�q9t|
�rw|��t|
|d
��q9|	|t|
���q9|�|j
dur�|�|j
���fdd�|D�}|S)aCombine 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.
        )rOrPrQr�rrNcs�t|tt����dSr�)r+rr,)r�)�_appendrmr[r\�align_append�sz2Console._collect_renderables.<locals>.align_appendcs2�rt���d�}�|�����dd�=dSdS)N)rmr�)rE�join)�sep_text)rir�rmr�r�r[r\�
check_text�s
�z0Console._collect_renderables.<locals>.check_text)rrqr)rc�g|]}t|���qSr[rA�r�r�r�r[r\�
<listcomp>�r�z0Console._collect_renderables.<locals>.<listcomp>�rrN)rir�r5r,rr:r|r�r�rEr�r9r8r�r�)rvr�r�r�rmrrqrpr��append_textr�r�r�r�r[)r�rir�rmr�r�r�r\�_collect_renderableszsD
��




zConsole._collect_renderablesu─z	rule.linerP)�
charactersr��align�titler�r�cCs*ddlm}|||||d�}|�|�dS)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�)rvr�r�r�r�r�r�r[r[r\r��szConsole.ruler�cGsJ|js#|�|j�dd�|D��Wd�dS1swYdSdS)z�Insert non-printing control codes.

        Args:
            control_codes (str): Control codes, such as those that may move the cursor.
        cs��|]}|jVqdSr�)�segment)r��_controlr[r[r\�	<genexpr>���z"Console.control.<locals>.<genexpr>N)r7r�r�)rvr�r[r[r\r��s
"��zConsole.controlrAr�)r�r�r�rpcGs4|�dd�|D��}|j|||ddddd|d�	dS)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``.
        css�|]}t|�VqdSr�)r�)r��_objectr[r[r\r��s�zConsole.out.<locals>.<genexpr>FTrV)r�rprrqrornrTr�N)r�r�)rvr�r�r�rpr��
raw_outputr[r[r\�out�s
�zConsole.out)r�r�r�rmrnrorrqrpr`rarTr
�new_line_startrorTr�c
Gs�|st�f}|
dur
|j}
|
r|durd}|durd}d}|jdd�}|��|j|||||||	d�}|D]}|�|�}q5|jj|||
durLt|
|j�nt	||||	d�}g}|j
}|j}|durm|D]	}||||��qbn|D]}|t�
|||�|�|���qo|r�td�dd	�|D�����d
kr�|�dt���|r�|jj
}tj||jdd�D]}||�q�n|j�
|�Wd�dSWd�dS1s�wYdS)
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``.
        NTrVFr�)rmrnr`rarorqrpr�csr�r�)r��r�r�r[r[r\r�Zr�z Console.print.<locals>.<genexpr>r%r�r�)r�r
r=r�r�r{r~�minr`r�r�r3r>r�r�r�r��
splitlines�insertr�r�r�)rvr�r�r�rmrnrorrqrpr`rarTr
r�r��render_hooksr�rhr��new_segmentsr�r3r��
buffer_extendr�r[r[r\r�sz%�	�
����
�
��+"�z
Console.print�)	�data�indentrp�	skip_keys�ensure_ascii�check_circular�	allow_nanrN�	sort_keys�jsonr�r�r�r�r�r�r�c	
Csxddlm}|dur|j||||||||	|
d�	}nt|t�s&td|�d���|||||||||	|
d�	}|j|dd�dS)	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�rpr�r�r�r�rNr�z/json must be str. Did you mean print_json(data=z) ?T)r
)�pip._vendor.rich.jsonr��	from_datar|r�r�r�)
rvr�r�r�rpr�r�r�r�rNr�r��json_renderabler[r[r\�
print_jsongs:�

��zConsole.print_json)�regionr{r�c
Csz|jst�d��|p|j}|dur!d}}|�|j|jp|j�}n|\}}}}|�||�}|j||d�}	|�|	||�dS)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_screenNrr�)	r�r&�NoAltScreenr{r�rirar��update_screen_lines)
rvr�r�r{r�r�r�r`rar�r[r[r\�
update_screen�s

�zConsole.update_screenrr�r�r�cCs>|jst�d��t|||�}|�|�}|j�|�|��dS)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�r3r�r�rc)rvr�r�r��
screen_updater�r[r[r\r��s

zConsole.update_screen_linesrr r[�r`r�r��	word_wrap�show_locals�suppress�
max_framesr�r�r�r�r�c
	Cs0ddlm}||||||||d�}	|�|	�dS)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)ror�r�)
rvr`r�r�r�r�r�r�r�ror[r[r\�print_exception�s�	zConsole.print_exceptionr��currentframecCsp|d7}|�}|dur)|r|r|j}|d8}|r|s|dus J�|jj|j|jfSt��|}|j|j|j	jfS)aEGet 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�rr�
frame_infor[r[r\�_caller_frame_info�s�zConsole._caller_frame_info)	r�r�r�rmrrqrp�
log_locals�
_stack_offsetrrc	
s^|
st�f}
|jdd�}|��|j|
||||||d�}�dur)�fdd�|D�}|�|	�\}
}}|
�d�r8dntj�|
�}|
�tj	�d}|rZdd�|�
�D�}|�t|d	d
��|j
|||��|||d�g}|D]}|�|�}qjg}|j}|j}|j}|D]	}||||��q|jj}tj||jdd
�D]}||�q�Wd�dS1s�wYdS)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�cr�r[rAr�r�r[r\r�Mr�zConsole.log.<locals>.<listcomp>�<���cSs i|]\}}|�d�s||�qS)�__)rt)r��keyrOr[r[r\r�Ss��zConsole.log.<locals>.<dictcomp>z	[i]locals)r�)r�path�line_no�	link_pathFr�)r�r=r�r
rtrr�abspathrYr��itemsrir<r4rr�r�r3r{r�r>r�r`)rvr�r�r�rmrrqrprrr�r�r�r	r�localsrr�
locals_maprhr�r�r3r�r�r�r�r[r�r\�log s^�	���

�
�"�zConsole.logcCsF|jr|jdd�=dS|j��|jdkry|jr2ddlm}||j|�|jdd���|jdd�=nW|�|jdd��}|jdd�=|r�z trX|j	j
}|�d�D]}||�qPn|j	�
|�|j	��Wn,t
yx}z|j�d�|_�d}~wwWd�dSWd�dSWd�dSWd�dS1s�wYdS)z$Check if the buffer may be rendered.Nrr%)�displayTzG
*** You may need to add PYTHONIOENCODING=utf-8 to your environment ***)rr�r�rNr&�jupyterrr�rr�writer��flush�UnicodeEncodeError�reason)rvrr�rr�r�r[r[r\rcrsB

�����
��"�zConsole._check_bufferr�cCs�g}|j}|j}|j}|jr'|j�|j�|�Wd�n1s"wY|j}|jr5|r5t	�
|�}|D]\}}}	|rI||j|||d��q7|rM|	sQ||�q7d�|�}
|
S)z)Render buffered output, and clear buffer.N)r	rgr�)
rir0rgrr9r<r�rjrr>�remove_colorr3r�)rvr��outputrir	rg�not_terminalr�r�r��renderedr[r[r\r��s2�

���
zConsole._render_buffer)rqr�password�stream�promptr&r'c	Cs�d}|r%|���}|j|||dd�Wd�n1swY|��}|jr0|j�|�d}|r:t||d�}|S|rH|j�|�|��}|St|�}|S)a5Displays 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�)rqrr�N)r')	r�r�r�rgrrr�readline�input)	rvr(rqrr&r'�
prompt_strr��resultr[r[r\r*�s$
���z
Console.input�r�r�r�cCs�|jsJd��|j�2|rd�dd�|jD��}nd�dd�|jD��}|r4|jdd�=Wd�|SWd�|S1s?wY|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�css(�|]\}}}|r|�|�n|VqdSr�r2)r�r�r��_r[r[r\r��s
��
�z&Console.export_text.<locals>.<genexpr>css�|]	}|js|jVqdSr�)r�r�r�r[r[r\r��s��
�N)rr9r�r<)rvr�r�r�r[r[r\�export_text�s*
��

�
�
��
��zConsole.export_textrcCsL|j||d�}t|ddd��}|�|�Wd�dS1swYdS)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-�wtrv�rkN)r0�openr)rvrr�r�r��
write_filer[r[r\�	save_text�s
"�zConsole.save_text�r�r��code_format�
inline_stylesr7r8c	Cs�|jsJd��g}|j}|pt}d}|durtn|}	|j��|rYt�t�|j��D].\}
}}t	|
�}
|rS|�
|�}
|jrFd|j�d|
�d�}
|
rQd|
�d|
�d�n|
}
||
�q)ndi}t�t�|j��D]8\}
}}t	|
�}
|r�|�
|�}
|�|
t
|�d	�}|jr�d
|�d|j�d|
�d�}
n	d|�d|
�d�}
||
�qdg}|j}|��D]\}}|r�|d
|�d|�d��q�d�|�}|	jd�|�||jj|jjd�}|r�|jdd�=Wd�|SWd�|S1s�wY|S)aGenerate 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)rrirC�CONSOLE_HTML_FORMATr9r>�filter_control�simplifyr<r	�get_html_styler��
setdefaultr�rr��format�foreground_color�hex�background_color)rvr�r�r7r8�	fragmentsri�_themer;�render_code_formatr�r�r/r�r��style_number�stylesheet_rules�stylesheet_append�
style_rule�
rendered_coder[r[r\�export_htmlsp��
�

�
�

�
�
�)�
�)�)zConsole.export_htmlcCsP|j||||d�}t|ddd��}|�|�Wd�dS1s!wYdS)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.

        r6r1rvr2N)rOr3r)rvrr�r�r7r8�htmlr4r[r[r\�	save_htmlMs�"�zConsole.save_htmlr�)rdrJrrN)rrr�r�r�r�)TNr�r�)rr)yrXrYrZrbr�environrrr�rdr1rr"r�rGrrcr@r/rr)rr�floatr�rCr�r�setterrr>r�rNrHrQr-r1r�r�rfrgr�rjrlr�rr�r�r�r�r�r�rtr	rkrjr7rer{r_rfrr`rar�r�r�r6r�r�r�r�r�r�r�r�r�r�r4r�rr3r?r�r�r�rr�r�r�r�rFr,r�r.r�r�r�r�r;r�r�rr�staticmethodrrrrr
rrcr�rr*r0r5rDrOr>rQr[r[r[r\r�Ds
#������	�
��
�
�������������
������ 
�p	-
����
�
������
�!	���
����
����
�5�������

�9��
�����	�
�
�<�
��
�$�������	�

�M����
��
�
������
�#��������	�
���
����
�e��������	�
���
�A����
�#�
���
��������	�

�#����%��������	�
��
�R��������&*, ������O
�������r��__main__zJSONRPC [i]request[/i]�g�������?z2.0�subtract�*�)�minuend�
subtrahendr )�jsonrpcr��params�idz
Hello, World!z{'a': 1}z&Which one is correct team name in NBA?)zNew York BullszLos Angeles KingszGolden State Warriors�
Huston Rocketr`)�questionr{�answer)�answered�q1z	5 + 7 = ?)�
���
rgz
12 - 8 = ?)r%r�r �ri)rcrd�q2)�sport�maths)r��empty�quiz�foor�)rrrI)�rr�platformrEr3�abcrr�dataclassesrrr�	functoolsrrrPr	r
�	itertoolsrr�timer
�typesrrr�typingrrrrrrrrrrrrrrr�version_infor"r#r$�pip._vendor.typing_extensionsr�r&r'r(r4r)r*r�r+r,�colorr-r�r.rr/rr0r1rqr3r�r�r4r5r�r6r7�prettyr8r9�protocolr:r�r;�scoper<r�r=r�r>r�r?r@�styledrB�terminal_themerCrDr�rErFr�rGrHrrIrdrJr�rLr�rr�rr�r�rWr�r>rWr[rZr_rer�r�r�r�r5�	Exceptionr�r�r�r�r�r�r�r�r�r�r�rVr2rru�localr�r�r�rdr�r�pip._vendor.coloramarr�rXr�r�reprr�r[r[r[r\�<module>s
D
	{
!'/$!�



5����������"�