CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
console.cpython-310.pyc1005 linesDownload Raw Back to __pycache__
1o

2��Yi��
@s�UddlZddlZddlZddlZddlZddlmZmZddlm	Z	m3Z4ddlmZddlm
Z
ddlmZddlmZddlmZdd	lmZdd5lmZddlmZddlmZmZmZdd
lmZmZmZm 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.ddl/m0Z0ddl1m2Z2m3Z3ddl4m4Z4ddl5m6Z6m7Z7ddl8m9Z9ddl:m;Z;m<Z<ddl=m>Z>m?Z?ddl@mAZAmBZBddlCmDZDddlEmFZFddlGmHZHmIZIddlJmKZLddlMmNZNmOZOddlPmQZQmRZRddlSmTZTmUZUddlVmWZWddlXmYZYdd lZm[Z[dd!l\m]Z]dd"l^m_Z_dd#l`maZambZbdd$lcmdZddd%lemfZfmgZgmhZhdd&limjZjmkZkdd'llmmZmmnZne�rNdd(lompZpdd)lqmrZrdd*lsmtZtd+Zud,Zvejwd-kZxe e,eyd.fgd.fZze$d/Z{e$d0Z|Gd1d2�d2�Z}e}�Z~zej���Z�Wne��y�dZ�Ynwzej����Z�Wne��y�dZ�Ynwzej����Z�Wne��y�d3Z�Ynwe�e�e�fZ�e�e�fZ�eAj�eAj�eAj�d4�Z�Gd5d6�d6e&�Z�e	Gd7d8�d8��Z�e.Gd9d:�d:e(��Z�e.Gd;d<�d<e(��Z�e,e�e�eyfZ�	e"e,e�e_fZ�eH�Z�Gd=d>�d>e��Z�Gd?d@�d@�Z�GdAdB�dB�Z�GdCdD�dD�Z�GdEdF�dF�Z�GdGdH�dH�Z�GdIdJ�dJ�Z�GdKdL�dL�Z�d�dNe�dOe dPe dPe�fffdQdR�Z�dOe�fdSdT�Z�eAj�eAj�eAj�eAjxdU�Z�dVdW�e����D�Z�e	GdXdY�dYej���Z�GdZd[�d[e�Z�da�e'd\e�d]<d�d^d_�Z�dOe�fd`da�Z�Gdbdc�dc�Z�ddeydOeyfdedf�Z�e�dgk�r�e�dMdh�Z�e���didjdkdMdlddmdndodpdq�drds��e���dtdue�e���e���dgdMdvgdw�dxdy�dz�dld{gd|�d}dy�d~gd�d�dy�d��d��d���dSdS)��N)�ABC�abstractmethod)�	dataclass�field)�datetime)�wraps)�getpass)�escape)�isclass)�islice)�ceil)�	monotonic)�	FrameType�6ModuleType�
TracebackType)�IO�
TYPE_CHECKING�Any�Callable�Dict�Iterable�List�Literal�Mapping�7NamedTuple�Optional�Protocol�TextIO�Tuple�Type�Union�cast�runtime_checkable)�	NULL_FILE�)�errors�themes)�_emoji_replace)�CONSOLE_HTML_FORMAT�CONSOLE_SVG_FORMAT)�8get_fileno)�FormatTimeCallable�	LogRender)�Align�AlignMethod)�ColorSystem�	blend_rgb)�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�SVG_EXPORT_THEME�
TerminalTheme)�Text�TextType)�Theme�9ThemeStack)�WindowsConsoleFeatures)�Live��Status�s�d�win32rI)�default�left�center�right�full)�fold�crop�ellipsis�ignorec@seZdZdS)�NoChangeN)�__name__�10__module__�__qualname__�rara��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\pip/_vendor/rich/console.pyr]Osr]�)�kitty�256color�16colorc@s$eZdZUdZeed<	eed<dS)�ConsoleDimensionszSize of the terminal.�width�heightN)r^r_r`�__doc__�int�__annotations__rarararbrgms11rgc@s�eZdZUdZeed<	eed<	eed<	eed<	eed<	eed<	eed<	d	Z	e12eed13<	d	Ze14e
ed<	dZe15eed
<	d	Ze16eed<	d	Ze17eed<	d	Ze18eed<edefdd��Zd"dd�Zeeeeeeeeed�	deeefdeeefdeeefd19ee20eefdee21e
efd
ee22eefdee23eefdee24eefdee25eefddfdd�Zdeddfdd�Zdeddfdd�Zd"dd�Zdededdfd d!�Zd	S)#�ConsoleOptionsz$Options for __rich_console__ method.�size�legacy_windows�	min_width�	max_width�is_terminal�encoding�26max_heightN�justify�overflowF�no_wrap�	highlight�markupri�returncCs|j�d�S)z+Check if renderables should use ascii only.�utf)rs�27startswith��selfrararb�28ascii_only�szConsoleOptions.ascii_onlycCst�t�}|j��|_|S)zdReturn a copy of the options.29 30        Returns:31            ConsoleOptions: a copy of self.32        )rm�__new__�__dict__�copy�r~�optionsrararbr��s33zConsoleOptions.copy)	rhrprqrurvrwrxryrirhc	Cs�|��}34t|t�std|�|35_|36_t|t�s||37_t|t�s"||38_t|t�s*||39_t|t�s2||40_t|t�s:||41_t|t�sB||42_	t|t�sJ||43_44t|	t�sb|	durV|	|45_|	dur\dntd|	�|46_|47S)zUpdate values, return a copy.rN)
r��48isinstancer]�maxrprqrurvrwrxryrtri)r~rhrprqrurvrwrxryrir�rararb�update�s,495051525354555657zConsoleOptions.updatecCs|��}td|�|_|_|S)z�Update just the width, return a copy.58 59        Args:60            width (int): New width (sets both min_width and max_width)61 62        Returns:63            ~ConsoleOptions: New console options instance.64        r)r�r�rprq)r~rhr�rararb�update_width�s	zConsoleOptions.update_widthcCs|��}||_|_|S)z�Update the height, and return a copy.65 66        Args:67            height (int): New height68 69        Returns:70            ~ConsoleOptions: New Console options instance.71        )r�rtri)r~rir�rararb�
update_height�s	zConsoleOptions.update_heightcCs|��}d|_|S)z�Return a copy of the options with height set to ``None``.72 73        Returns:74            ~ConsoleOptions: New console options instance.75        N)r�rir�rararb�reset_height�szConsoleOptions.reset_heightcCs*|��}td|�|_|_||_|_|S)aUpdate the width and height, and return a copy.76 77        Args:78            width (int): New width (sets both min_width and max_width).79            height (int): New height.80 81        Returns:82            ~ConsoleOptions: New console options instance.83        r)r�r�rprqrirt)r~rhrir�rararb�update_dimensions�s84z ConsoleOptions.update_dimensions)rzrm)r^r_r`rjrgrl�boolrk�strrur�
JustifyMethodrv�OverflowMethodrwrxryri�propertyrr��	NO_CHANGEr r]r�r�r�r�r�rarararbrmvs�8586
�87�88�89����	�90��91�%
92
93rmc@s(eZdZdZdeddeffdd�ZdS)�RichCastz5An object that may be 'cast' to a console renderable.rz�ConsoleRenderablecC�dS�Nrar}rararb�__rich__�zRichCast.__rich__N)r^r_r`rjr r�r�rarararbr��s94�r�c@s&eZdZdZ						ddd	�Zd95S)r�z-An object that supports the console protocol.�console�Consoler�rmrz�RenderResultcCr�r�ra�r~r�r�rararb�__rich_console__96r�z"ConsoleRenderable.__rich_console__N)r�r�r�rmrzr�)r^r_r`rjr�rarararbr�s���r�c@seZdZdZdS)�CaptureErrorz(An error in the Capture context manager.N)r^r_r`rjrarararbr�sr�c@s>eZdZdZddeddfdd�Zdd	d97ddeefdd
�ZdS)�NewLinez$A renderable to generate new line(s)r$�countrzNcCs98||_dSr�)r��r~r�rararb�__init__!s99zNewLine.__init__r�r�r�rmccs�td|j�VdS)N�100)rAr�r�rararbr�$s�zNewLine.__rich_console__�r$)	r^r_r`rjrkr�rrAr�rarararbr�s���r�c@sHeZdZdZdeeedededdfdd�Zd	d101dede	fdd
�Z102dS)�ScreenUpdatez)Render a list of lines at a given offset.�lines�x�yrzNcC�||_||_||_dSr�)�_linesr�r�)r~r�r�r�rararbr�-�103zScreenUpdate.__init__r�r�r�ccs@�|j}tj}t|j|j�D]\}}|||�V|EdHqdSr�)r�r1�move_to�	enumerater�r�)r~r�r�r�r��offset�linerararbr�2s��zScreenUpdate.__rich_console__)r^r_r`rjrrArkr�rmr�r�rarararbr�*s"���r�c@s\eZdZdZddd�Zddd	�Zd104eeedeedee	ddfd
d�Z105defdd�ZdS)�Capturez�Context manager to capture the result of printing to the console.106    See :meth:`~rich.console.Console.capture` for how to use.107 108    Args:109        console (Console): A console instance to capture output.110    r�r�rzNcCs||_d|_dSr�)�_console�_result)r~r�rararbr�Ds111zCapture.__init__cC�|j��|Sr�)r��
begin_capturer}rararb�	__enter__H�112zCapture.__enter__�exc_type�exc_val�exc_tbcCs|j��|_dSr�)r��end_capturer��r~r�r�r�rararb�__exit__LszCapture.__exit__cCs|jdur	td��|jS)zGet the result of the capture.Nz<Capture result is not available until context manager exits.)r�r�r}rararb�getTs113114�zCapture.get)r�r�rzN)rzr�)
r^r_r`rjr�r�rr�
BaseExceptionrr�r�r�rarararbr�<s115116117���118�r�c	@s`eZdZdZddddededdfd	d119�Zddd�Zd
ee	e120dee121deeddfdd�ZdS)�ThemeContextzbA context manager to use a temporary theme. See :meth:`~rich.console.Console.use_theme` for usage.Tr�r��theme�inheritrzNcCr�r�)r�r�r�)r~r�r�r�rararbr�`r�zThemeContext.__init__cCs|j�|j�|Sr�)r��122push_themer�r}rararbr�eszThemeContext.__enter__r�r�r�cCs|j��dSr�)r��	pop_themer�rararbr�iszThemeContext.__exit__�T)rzr�)
r^r_r`rjrKr�r�r�rrr�rr�rarararbr�]s123124����r�c@sneZdZdZ			ddddeededed	df125d126d�Zddd
�Zdee	e127dee128deed	dfdd�ZdS)�PagerContextzZA context manager that 'pages' content. See :meth:`~rich.console.Console.pager` for usage.NFr�r��pager�styles�linksrzcCs*||_|dur129t�n||_||_||_dSr�)r�r:r�r�r�)r~r�r�r�r�rararbr�us130zPagerContext.__init__cCr�r�)r��
_enter_bufferr}rararbr��r�zPagerContext.__enter__r�r�r�cCs�|durF|jj�0|jjdd�}|jjdd�=|}|js#t�|�}n|js+t�|�}|j�|�}Wd�n1s;wY|j	�131|�|j��dSr�)r��_lock�_bufferr�rA�strip_stylesr��strip_links�_render_bufferr��show�_exit_buffer)r~r�r�r��buffer�segments�contentrararbr��s132133�	zPagerContext.__exit__�NFF)rzr�)
r^r_r`rjrr9r�r�r�rr�rr�rarararbr�rs4�����134135136����r�c	@s�eZdZdZ	ddddededdfd	d137�Zdd�dedeeddfd
d�Z	ddd�Z138deeedeedee
ddfdd�ZdS)�
ScreenContextziA context manager that enables an alternative screen. See :meth:`~rich.console.Console.screen` for usage.�r�r��hide_cursor�stylerzNcCs"||_||_t|d�|_d|_dS)N�r�F)r�r�r@�screen�_changed)r~r�r�r�rararbr��s139zScreenContext.__init__r��renderablescGsJ|rt|�dkrt|�n|d|j_|dur||j_|jj|jdd�dS)a+Update the screen.140 141        Args:142            renderable (RenderableType, optional): Optional renderable to replace current renderable,143                or None for no change. Defaults to None.144            style: (Style, optional): Replacement style, or None for no change. Defaults to None.145        r$rNr�)�end)�len�Groupr��146renderabler�r��print)r~r�r�rararbr��s147�zScreenContext.updatecCs*|j�d�|_|jr|jr|j�d�|S)NTF)r��set_alt_screenr�r��show_cursorr}rararbr��szScreenContext.__enter__r�r�r�cCs0|jr|j�d�|jr|j�d�dSdSdS)NFT)r�r�r�r�r�r�rararbr��s�zScreenContext.__exit__�r�)rzr�)r^r_r`rjr�rCr��RenderableTyperr�r�rr�rr�rarararbr��s<����148�	���149150151����r�c@sneZdZdZdd�dddeddfd	d152�Zededfdd��Z	
					ddd�Z	d
dddde153fdd�ZdS)r�a$Takes a group of renderables and returns a renderable object that renders the group.154 155    Args:156        renderables (Iterable[RenderableType]): An iterable of renderable objects.157        fit (bool, optional): Fit dimension of group to contents, or fill available space. Defaults to True.158    T��fitr�r�r�rzNcGs||_||_d|_dSr�)�_renderablesr��_render)r~r�r�rararbr��r�zGroup.__init__cCs|jdurt|j�|_|jSr�)r��listr�r}rararbr��s159zGroup.renderablesr�r�r�rmr7cCs"|jr160t|||j�St|j|j�Sr�)r�r8r�r7rqr�rararb�__rich_measure__�szGroup.__rich_measure__ccs�|jEdHdSr�)r�r�rararbr��s�zGroup.__rich_console__)r�r�r�rmrzr7)r^r_r`rjr�r�r�rr�r�r�r�rarararbr��s&��161����r�Tr�rz.cs.dtdttfdtdtff�fdd�}|S)z�A decorator that turns an iterable of renderables in to a group.162 163    Args:164        fit (bool, optional): Fit dimension of group to contents, or fill available space. Defaults to True.165    �method.rzcs(t��dtdtdtf��fdd��}|S)zGConvert a method that returns an iterable of renderables in to a Group.�args�kwargsrzcs�|i|��}t|d�i�S)Nr�)r�)r�r�r�)r�r�rarb�_replace�sz*group.<locals>.decorator.<locals>._replace)rrr�)r�r�r�)r�rb�	decorator�szgroup.<locals>.decorator)rrr�r�)r�r�rar�rb�group�s�166�r�cCs`ztWn167tyYdSwt�}|jj}dt|j�vs&t�d�s&|dkr(dS|dkr.dSdS)z-Check if we're running in a Jupyter notebook.Fzgoogle.colab�DATABRICKS_RUNTIME_VERSION�ZMQInteractiveShellT�TerminalInteractiveShell)�get_ipython�	NameError�	__class__r^r��os�getenv)�ipython�shellrararb�_is_jupyter�s��r�)�standard�256�	truecolor�windowscCsi|]\}}||�qSrara)�.0�name�systemrararb�168<dictcomp>�rc@s<eZdZUdZeed<eed�Ze	e169ed<dZeed<dS)�ConsoleThreadLocalsz(Thread local values for Console context.�theme_stack)�default_factoryr�r�buffer_indexN)
r^r_r`rjrLrlrr�r�rrArrkrarararbrs170171rc@s.eZdZdZedeedeefdd��ZdS)�172RenderHookz(Provides hooks in to the render process.r�rzcCsdS)aLCalled with a list of objects to render.173 174        This method can return a new list of renderables, or modify and return the same list.175 176        Args:177            renderables (List[ConsoleRenderable]): A number of renderable objects.178 179        Returns:180            List[ConsoleRenderable]: A replacement list of renderables.181        Nra)r~r�rararb�process_renderables)szRenderHook.process_renderablesN)r^r_r`rjrrr�r182rarararbr	&s��r	rM�_windows_console_featurescCs"tdurtSddlm}|�atS)Nr$��get_windows_console_features)r�_windowsr
rrararbr
<s183r
cCstot�jS)zDetect legacy Windows.)�WINDOWSr
�vtrarararb�detect_legacy_windowsF�rc<@s�184eZdZUdZejZeeefe	d<dddddddddddddddddddddde185�dddddd	�d186ee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$�d!d:d;�Z%�d!d<d=�Z&d>d?d)e
fd@dA�Z'�d!dBdC�Z(dDe)d)dfdEdF�Z*�d!dGdH�Z+�d"dIdJ�Z,dKe-dLe-dMe-d)dfdNdO�Z.�d!dPdQ�Z/d)efdRdS�Z0ddT�dedUe
d)dfdVdW�Z1�d!dXdY�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?�d!dpdq�Z@d)eAfdrds�ZB	�d#dteeCdue
dve
d)eDfdwdx�ZE�d$dzed)dfd{d|�ZF�d%d}e
d)dfd~d�ZGd�d�d�d�d��d�eHd�ed�ed�ed�ed)d�fd�d��ZI�d%d�e
d)e
fd�d��ZJ�d%d�e
d)e
fd�d��ZKed)e
fd�d���ZLd�ed)e
fd�d��ZM	�d&d�e
deed)d�fd�d��ZNdd��d�eHd�ee9d)eOfd�d��ZP	�d'd�eHd�ee9d)eQefd�d��ZR	�d'dddd��d�eHd�ee9deeSd�e
d�e
d)eeefd�d��ZTd�ddddddd��d�edeeeSfd�eeUd�eeVdee
dee
dee
d!eeWd)d�fd�d��ZXdd��d�eeeSfd�eeeSefd)eSfd�d��ZYddddd��d�eQe-d�ed�ed�eeUdee
dee
dee
d)eeZfd�d��Z[	��d(d�d�d�d��d�e\d�edeeeSfd�e]d)df187d�d„Z^d�e_d)dfd�dńZ`d�d�dddȜd�e-d�ed�edeeeeSfdee
d)dfd�dʄZad�d�ddddddddddddd˜d�e-d�ed�edeeeeSfd�eeUd�eeVd�ee
dee
dee
dee
deedeed�e
dee
d�e
d)df d�dЄZb	�d'dd�ddddddddҜ	d�eed�e-d�edeefde
d�e
d�e
d�e
d�e
d�eee-ge-fd�e
d)dfd�d܄Zcdddݜd�eHd�eedd�ee9d)dfd�d��Ze	�d)d�eeed�ed�ed)dfd�d�Zfd�d�dddd�d�d�deed�edeed�e
d�e
d�eQeeegfd�ed)dfd�d�Zheiejjkfd�ed�egeelfd)e=eeemee-fffd�d���Znd�d�dddddddyd��	d�e-d�ed�edeeeeSfd�eeUdee
dee
dee
d�e
d�ed)dfd�d��Zo�d!d�d��Zp�d!d�d��Zq�d!d��d�Zr�deQed)ef�d�d�Zs	��d(dddd�d��de\de
de
�de
�deetd)ef�d�d	�Zudd�d188��de
due
d)ef�d�d
�Zvdd�d189��de�de
due
d)df�d�d�Zwdddd�d�deex�de
�dee�de
d)ef190�d�d�Zyddezd�d��dedeex�de
�de�de
d)df�d�d�Z{�ddde|�dd�d�d�edeex�de
�de�de�deed)ef�d�d�Z}�ddde|�dd�d��ded�edeex�de
�de�de�deed)df�d�d �Z~dS(*r�arA high level console interface.191 192    Args:193        color_system (str, optional): The color system supported by your terminal,194            either ``"standard"``, ``"256"`` or ``"truecolor"``. Leave as ``"auto"`` to autodetect.195        force_terminal (Optional[bool], optional): Enable/disable terminal control codes, or None to auto-detect terminal. Defaults to None.196        force_jupyter (Optional[bool], optional): Enable/disable Jupyter rendering, or None to auto-detect Jupyter. Defaults to None.197        force_interactive (Optional[bool], optional): Enable/disable interactive mode, or None to auto detect. Defaults to None.198        soft_wrap (Optional[bool], optional): Set soft wrap default on print method. Defaults to False.199        theme (Theme, optional): An optional style theme object, or ``None`` for default theme.200        stderr (bool, optional): Use stderr rather than stdout if ``file`` is not specified. Defaults to False.201        file (IO, optional): A file object where the console should write to. Defaults to stdout.202        quiet (bool, Optional): Boolean to suppress all output. Defaults to False.203        width (int, optional): The width of the terminal. Leave as default to auto-detect width.204        height (int, optional): The height of the terminal. Leave as default to auto-detect height.205        style (StyleType, optional): Style to apply to all output, or None for no style. Defaults to None.206        no_color (Optional[bool], optional): Enabled no color mode, or None to auto detect. Defaults to None.207        tab_size (int, optional): Number of spaces used to replace a tab character. Defaults to 8.208        record (bool, optional): Boolean to enable recording of terminal output,209            required to call :meth:`export_html`, :meth:`export_svg`, and :meth:`export_text`. Defaults to False.210        markup (bool, optional): Boolean to enable :ref:`console_markup`. Defaults to True.211        emoji (bool, optional): Enable emoji code. Defaults to True.212        emoji_variant (str, optional): Optional emoji variant, either "text" or "emoji". Defaults to None.213        highlight (bool, optional): Enable automatic highlighting. Defaults to True.214        log_time (bool, optional): Boolean to enable logging of time by :meth:`log` methods. Defaults to True.215        log_path (bool, optional): Boolean to enable the logging of the caller by :meth:`log`. Defaults to True.216        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] ".217        highlighter (HighlighterType, optional): Default highlighter.218        legacy_windows (bool, optional): Enable legacy Windows mode, or ``None`` to auto detect. Defaults to ``None``.219        safe_box (bool, optional): Restrict box options that don't render on legacy Windows.220        get_datetime (Callable[[], datetime], optional): Callable that gets the current time as a datetime.datetime object (used by Console.log),221            or None for datetime.now.222        get_time (Callable[[], time], optional): Callable that gets the current time in seconds, default uses time.monotonic.223    �_environ�autoNF�Tz[%X])�color_system�force_terminal�
force_jupyter�force_interactive�	soft_wrapr��stderr�file�quietrhrir��no_color�tab_size�recordry�emoji�
emoji_variantrx�log_time�log_path�log_time_format�highlighterro�safe_box�get_datetime�get_timerr)rr�r�r�r�rrrrr�rrrrhrir�rrr ryr!r"rxr#r$r%r&�HighlighterTyperor'r(r)c"Cs�|dur||_|durt�n||_|jrF|224dur-|j�d�}|dur+|��r+t|�}225nt}226|durF|j�d�}|durD|��rDt|�}nt}||_||_	||_227||_||_||_
|durct�ob|jn||_|228dur|j�d�}|dur|��rt|�|j}229|dur�|j�d�} | dur�| ��r�t| �}||_|230|_||_|d|_|dur�||_||_|	|_||_|dur�d|_n|dkr�|��|_nt||_t��|_t|||d�|_|p�t|_ ||_!|p�t"j#|_$|p�t%|_&||_'|
dur�|
n|j�dd�dk|_(|du�r|j�d	d�}!|!du�r|!d231k�rd}n|!dk�rd
}|du�r*|j)�o)|j*n||_+t��|_,t-t.|du�r<t/j0n|�d�|_1g|_2g|_3g|_4d|_5dS)N�JUPYTER_COLUMNS�
JUPYTER_LINES�COLUMNS�LINESr)�	show_time�	show_path�time_format�NO_COLORr��TTY_INTERACTIVE�0F�1T)r)6rr��232is_jupyterr��isdigitrk�JUPYTER_DEFAULT_COLUMNS�JUPYTER_DEFAULT_LINESrr �_markup�_emoji�_emoji_variant�233_highlightrror�_width�_height�_force_terminal�_filerr�
_color_system�_detect_color_system�
COLOR_SYSTEMS�	threading�RLockr�r,�_log_render�_null_highlighterr&r'r�nowr(r
r)r�rrr�is_dumb_terminal�is_interactive�_record_buffer_lockrrLr&�DEFAULT�_thread_locals�_record_buffer�
_render_hooks�_live_stack�_is_alt_screen)"r~rrrrrr�rrrrhrir�rrr ryr!r"rxr#r$r%r&ror'r(r)r�jupyter_columns�
jupyter_lines�columnsr��tty_interactiverararbr�qs�#234235���236237�238239��240241242243244���245�246zConsole.__init__rzcCsd|j�d|j�d�S)Nz<console width=� �>)rhrBr}rararb�__repr__�szConsole.__repr__cCs4|jp|jr	tjntj}t|d|�}|durt}|S)z Get the file object to write to.�rich_proxied_fileN)rAr�sys�stdout�getattrr#)r~rrararbr�s247zConsole.file�new_filecC�248||_dS)zSet a new file object.N)rA)r~r^rararbrs249cC�|jjS�zGet a thread local buffer.)rNr�r}rararbr��zConsole._buffercCr`ra�rNrr}rararb�
_buffer_index
rbzConsole._buffer_index�valuecCs||j_dSr�rc)r~rerararbrd�cCr`)z!Get the thread local theme stack.)rNrr}rararb�_theme_stackrbzConsole._theme_stackcCs�|jrtjS|jr|jrdStr"|jrtjSt�}|jrtjStj	S|j250�dd����
�}|dvr4tjS|j251�dd����
�}|�d�\}}}t�|tj�}|S)z"Detect color system from env vars.N�	COLORTERMr�)r��24bit�TERM�-)r6r/�	TRUECOLORrrrJrror
r��	EIGHT_BITrr��strip�lower�252rpartition�_TERM_COLORS�STANDARD)r~�windows_console_features�253color_term�term�254_term_name�_hyphen�colorsrrararbrCs(���zConsole._detect_color_systemcCs|jd7_dS)z4Enter in to a buffer context, and buffer all output.r$N)rdr}rararbr�3�zConsole._enter_buffercCs|jd8_|��dS)z5Leave buffer context, and render content if required.r$N)rd�
_check_bufferr}rararbr�7szConsole._exit_buffer�liverNcCsD|j�|j�|�t|j�dkWd�S1swYdS)a`Set Live instance. Used by Live context manager (no need to call directly).255 256        Args:257            live (Live): Live instance using this Console.258 259        Returns:260            Boolean that indicates if the live is the topmost of the stack.261 262        Raises:263            errors.LiveError: If this Console has a Live context currently active.264        r$N)r�rQ�appendr�)r~r{rararb�set_live<s$�zConsole.set_livecC�6|j�|j��Wd�dS1swYdS)zUClear the Live instance. Used by the Live context manager (no need to call directly).N)r�rQ�popr}rararb�265clear_liveL�"�zConsole.clear_live�hookcCs8|j�|j�|�Wd�dS1swYdS)zpAdd a new render hook to the stack.266 267        Args:268            hook (RenderHook): Render hook instance.269        N)r�rPr|)r~r�rararb�push_render_hookQs"�zConsole.push_render_hookcCr~)z'Pop the last renderhook from the stack.N)r�rPrr}rararb�pop_render_hookZr�zConsole.pop_render_hookcCs|��|S)z,Own context manager to enter buffer context.�r�r}rararbr�_szConsole.__enter__r��	exc_value�	tracebackcC�|��dS)zExit buffer context.N)r�)r~r�r�r�rararbr�drfzConsole.__exit__cCr�)z`Begin capturing console output. Call :meth:`end_capture` to exit capture mode and return output.Nr�r}rararbr�hrfzConsole.begin_capturecCs$|�|j�}|jdd�=|��|S)zhEnd capture mode and return captured string.270 271        Returns:272            str: Console output.273        N)r�r�r�)r~�
render_resultrararbr�ls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.274        Generally speaking, you should call :meth:`~rich.console.Console.use_theme` to get a context manager, rather275        than calling this method directly.276 277        Args:278            theme (Theme): A theme instance.279            inherit (bool, optional): Inherit existing styles. Defaults to True.280        r�N)rgr��r~r�r�rararbr�ws	zConsole.push_themecCs|j��dS)z9Remove theme from top of stack, restoring previous theme.N)rgr�r}rararbr��rzConsole.pop_themecCst|||�S)aUse a different theme for the duration of the context manager.281 282        Args:283            theme (Theme): Theme instance to user.284            inherit (bool, optional): Inherit existing console styles. Defaults to True.285 286        Returns:287            ThemeContext: [description]288        )r�r�rararb�	use_theme�s289zConsole.use_themecCs|jdur290t|jSdS)zpGet color system string.291 292        Returns:293            Optional[str]: "standard", "256" or "truecolor".294        N)rB�_COLOR_SYSTEMS_NAMESr}rararbr�s295296zConsole.color_systemcCst|jdd�pd��S)zGet the encoding of the console file, e.g. ``"utf-8"``.297 298        Returns:299            str: A standard encoding string.300        rs�utf-8)r]rror}rararbrs�szConsole.encodingcCs�|jdur|jSttjd�rtjj�d�rdS|jrdS|j}|�dd�}|dkr+dS|dkr1d	S|�d301�}|dur>|dkSt	|j302dd�}z|durMdWS|�WStyZYdSw)z�Check if the console is writing to a terminal.303 304        Returns:305            bool: True if the console writing to a device capable of306                understanding escape sequences, otherwise False.307        Nr_�idlelibF�TTY_COMPATIBLEr�r4r5T�FORCE_COLOR�isatty)r@�hasattrr[�stdinr_r|r6rr�r]r�308ValueError)r~�environ�tty_compatible�force_colorr�rararbrr�s.309	�310�zConsole.is_terminalcCs$|j�dd�}|��dv}|jo|S)zxDetect dumb terminal.311 312        Returns:313            bool: True if writing to a dumb terminal, otherwise False.314 315        rjr�)�dumb�unknown)rr�rorr)r~�_term�is_dumbrararbrJ�s316zConsole.is_dumb_terminalc	Cs&|j}t|j||jd|j|j|jd�S)zGet default console options.r$)rtrnrorprqrsrr)rnrmrirorhrsrr)r~rnrararbr��s�zConsole.optionscCs|jdur|jdurt|j|j|j�S|jrtdd�Sd}d}tr$tnt}|D]}z	t�	|�\}}Wnt317ttfy?Yq(w|j
�d�}|durS|��rSt|�}|j
�d�}|dure|��ret|�}|phd}|pld}t|jdurx||jn|j|jdur�|�S|j�S)zGet the size of the console.318 319        Returns:320            ConsoleDimensions: A named tuple containing the dimensions.321        N�P�r-r.)r>r?rgrorJr�_STD_STREAMS_OUTPUT�_STD_STREAMSr��get_terminal_size�AttributeErrorr��OSErrorrr�r7rk)r~rhri�streams�file_descriptorrUr�rararbrn�s8322���zConsole.size�new_sizecCs|\}}||_||_dS)zvSet a new size for the terminal.323 324        Args:325            new_size (Tuple[int, int]): New width and height.326        N)r>r?)r~r�rhrirararbrns327cCr`)zsGet the width of the console.328 329        Returns:330            int: The width (in characters) of the console.331        )rnrhr}rararbrh&�z
Console.widthcCr_)zFSet width.332 333        Args:334            width (int): New width.335        N)r>)r~rhrararbrh/�336cCr`)zpGet the height of the console.337 338        Returns:339            int: The height (in lines) of the console.340        )rnrir}rararbri8r�zConsole.heightcCr_)zISet height.341 342        Args:343            height (int): new height.344        N)r?)r~rirararbriAr�cCs|�t���dS)z3Play a 'bell' sound (if supported by the terminal).N)�controlr1�bellr}rararbr�JryzConsole.bellcCst|�}|S)a�A context manager to *capture* the result of print() or log() in a string,345        rather than writing it to the console.346 347        Example:348            >>> from rich.console import Console349            >>> console = Console()350            >>> with console.capture() as capture:351            ...     console.print("[bold magenta]Hello World[/]")352            >>> print(capture.get())353 354        Returns:355            Capture: Context manager with disables writing to the terminal.356        )r�)r~�capturerararbr�NszConsole.capturer�r�r�cCst||||d�S)aA context manager to display anything printed within a "pager". The pager application357        is defined by the system and will typically support at least pressing a key to scroll.358 359        Args:360            pager (Pager, optional): A pager object, or None to use :class:`~rich.pager.SystemPager`. Defaults to None.361            styles (bool, optional): Show styles in pager. Defaults to False.362            links (bool, optional): Show links in pager. Defaults to False.363 364        Example:365            >>> from rich.console import Console366            >>> from rich.__main__ import make_test_card367            >>> console = Console()368            >>> with console.pager():369                    console.print(make_test_card())370 371        Returns:372            PagerContext: A context manager.373        )r�r�r�)r�)r~r�r�r�rararbr�_sz
Console.pagerr$r�cCs"|dksJd��|�t|��dS)zqWrite new line(s).374 375        Args:376            count (int, optional): Number of new lines. Defaults to 1.377        rzcount must be >= 0N)r�r�r�rararbr�vszConsole.line�homecCs.|r|�t��t���dS|�t���dS)z�Clear the screen.378 379        Args:380            home (bool, optional): Also move the cursor to 'home' position. Defaults to True.381        N)r�r1�clearr�)r~r�rararbr��sz
Console.clear�dotszstatus.spinnerg�?g)@)�spinner�
spinner_style�speed�refresh_per_second�statusr�r�r�r�rPcCs$ddlm}|||||||d�}|S)atDisplay a status and spinner.382 383        Args:384            status (RenderableType): A status renderable (str or Text typically).385            spinner (str, optional): Name of spinner animation (see python -m rich.spinner). Defaults to "dots".386            spinner_style (StyleType, optional): Style of spinner. Defaults to "status.spinner".387            speed (float, optional): Speed factor for spinner animation. Defaults to 1.0.388            refresh_per_second (float, optional): Number of refreshes per second. Defaults to 12.5.389 390        Returns:391            Status: A Status object that may be used as a context manager.392        r$rO)r�r�r�r�r�)r�rP)r~r�r�r�r�r�rP�status_renderablerararbr��s�zConsole.statusr�cC�|jr
|�t�|��dSdS)zqShow or hide the cursor.393 394        Args:395            show (bool, optional): Set visibility of the cursor.396        TF)rrr�r1r�)r~r�rararbr��szConsole.show_cursor�enablecCs.d}|jr|js|�t�|��d}||_|S)a�Enables alternative screen mode.397 398        Note, if you enable this mode, you should ensure that is disabled before399        the application exits. See :meth:`~rich.Console.screen` for a context manager400        that handles this for you.401 402        Args:403            enable (bool, optional): Enable (True) or disable (False) alternate screen. Defaults to True.404 405        Returns:406            bool: True if the control codes were written.407 408        FT)rrror�r1�409alt_screenrR)r~r��changedrararbr��szConsole.set_alt_screencCs|jS)z�Check if the alt screen was enabled.410 411        Returns:412            bool: True if the alt screen was enabled, otherwise False.413        )rRr}rararb�
is_alt_screen�szConsole.is_alt_screen�titlecCr�)aSet the title of the console terminal window.414 415        Warning: There is no means within Rich of "resetting" the window title to its416        previous value, meaning the title you set will persist even after your application417        exits.418 419        ``fish`` shell resets the window title before and after each command by default,420        negating this issue. Windows Terminal and command prompt will also reset the title for you.421        Most other shells and terminals, however, do not do this.422 423        Some terminals may require configuration changes before you can set the title.424        Some terminals may not support setting the title at all.425 426        Other software (including the terminal itself, the shell, custom prompts, plugins, etc.)427        may also set the terminal window title. This could result in whatever value you write428        using this method being overwritten.429 430        Args:431            title (str): The new title of the terminal window.432 433        Returns:434            bool: True if the control code to change the terminal title was435                written, otherwise False. Note that a return value of True436                does not guarantee that the window title has actually changed,437                since the feature may be unsupported/disabled in some terminals.438        TF)rrr�r1r�)r~r�rararb�set_window_title�szConsole.set_window_titler�r�cCst|||pdd�S)auContext manager to enable and disable 'alternative screen' mode.439 440        Args:441            hide_cursor (bool, optional): Also hide the cursor. Defaults to False.442            style (Style, optional): Optional style for screen. Defaults to None.443 444        Returns:445            ~ScreenContext: Context which enables alternate screen on enter, and disables it on exit.446        r�)r�r�)r�)r~r�r�rararbr��szConsole.screen�r�r�r�cCst�||p|j|�}|S)a�Measure a renderable. Returns a :class:`~rich.measure.Measurement` object which contains447        information regarding the number of characters required to print the renderable.448 449        Args:450            renderable (RenderableType): Any renderable or string.451            options (Optional[ConsoleOptions], optional): Options to use when measuring, or None452                to use default options. Defaults to None.453 454        Returns:455            Measurement: A measurement of the renderable.456        )r7r�r�)r~r�r��measurementrararb�measureszConsole.measurec	cs��|p|j}|jdkr
dSt|�}t|d�r!t|�s!|�||�}nt|t�r7|j||j	|j457d�}|�||�}n	t�d|�d���zt
|�}WntyVt�d|�d���wt}|��}|D]}t||�rj|Vq_|�||�EdHq_dS)	akRender an object in to an iterable of `Segment` instances.458 459        This method contains the logic for rendering objects with the console protocol.460        You are unlikely to need to use it directly, unless you are extending the library.461 462        Args:463            renderable (RenderableType): An object supporting the console protocol, or464                an object that may be converted to a string.465            options (ConsoleOptions, optional): An options object, or None to use self.options. Defaults to None.466 467        Returns:468            Iterable[Segment]: An iterable of segments that may be rendered.469        r$Nr�)rxryzUnable to render zC; A str, Segment or object with __rich_console__ method is requiredzobject z is not renderable)r�rqr=r�r470r�r�r��471render_strrxryr%�NotRenderableError�iter�	TypeErrorrAr�r6)	r~r�r��_options�render_iterable�text_renderable�iter_render�_Segment�
render_outputrararbr6s:�472473474475�476�477��478�zConsole.render)r��pad�	new_linesr�r�c479Cs�|j�i|p|j}|�||�}|rt�||�}|j}|dur#td|�}tttj	||j480|||d�d|��}	|jdurc|jt|	�}481|482dkrc|rRtd|j483|�td�gntd|j484|�gg}|	�||485�|	Wd�S1sowYdS)aGRender objects in to a list of lines.486 487        The output of render_lines is useful when further formatting of rendered console text488        is required, such as the Panel class which draws a border around any renderable object.489 490        Args:491            renderable (RenderableType): Any object renderable in the console.492            options (Optional[ConsoleOptions], optional): Console options, or None to use self.options. Default to ``None``.493            style (Style, optional): Optional style to apply to renderables. Defaults to ``None``.494            pad (bool, optional): Pad lines shorter than render width. Defaults to ``True``.495            new_lines (bool, optional): Include "496" characters at end of lines.497 498        Returns:499            List[List[Segment]]: A list of lines, where a line is a list of Segment objects.500        Nr)�include_new_linesr�r�rWr�)
r�r�r6rA�apply_stylerir�r�r�split_and_crop_linesrqr��extend)r~r�r�r�r�r��render_options�	_rendered�
render_heightr��extra_lines�pad_linerararb�render_linesGsD501502���503
���504$�zConsole.render_linesr�)r�rurvr!ryrxr&�textrurvrIcCs�|p|duo|j}	|p|duo|j}505|p|duo|j}|506r-t|||	|jd�}||_||_nt|	r7t||jd�n||||d�}|rE|pD|j	nd}
|
durX|
t507|��}|�|�|S|S)a�Convert a string to a Text instance. This is called automatically if508        you print or log a string.509 510        Args:511            text (str): Text to render.512            style (Union[str, Style], optional): Style to apply to rendered text.513            justify (str, optional): Justify method: "default", "left", "center", "full", or "right". Defaults to ``None``.514            overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to ``None``.515            emoji (Optional[bool], optional): Enable emoji, or ``None`` to use Console default.516            markup (Optional[bool], optional): Enable markup, or ``None`` to use Console default.517            highlight (Optional[bool], optional): Enable highlighting, or ``None`` to use Console default.518            highlighter (HighlighterType, optional): Optional highlighter to apply.519        Returns:520            ConsoleRenderable: Renderable object.521 522        N)r�r!r")�default_variant)rurvr�)r;r:r=�
render_markupr<rurvrIr'r&r��copy_styles)r~r�r�rurvr!ryrxr&�
emoji_enabled�markup_enabled�highlight_enabled�	rich_text�_highlighter�highlight_textrararbr��s8����523zConsole.render_str)rTrrTc524Cs�t|t�r|Sz|j�|�}|durt�|�}|jr|��WS|WStjyI}z|dur9|�	|�WYd}~St�525d|�d|���d�d}~ww)a Get a Style instance by its theme name or parse a definition.526 527        Args:528            name (str): The name of a style or a style definition.529 530        Returns:531            Style: A Style object.532 533        Raises:534            MissingStyle: If no style could be parsed from name.535 536        NzFailed to get style z; )r�rBrgr��parse�linkr�r%�StyleSyntaxError�	get_style�MissingStyle)r~rrTr��errorrararbr��s"537538����zConsole.get_style�rur!ryrx�objects�sepr�c	s4g}|j�g��j}	���dvrdtddf��fdd�}539|540�t}|s)|dur,|jr,|j}d
�����fdd�}|D]G}
t|
�}
t|
t�rQ|	|j|
||||d	��q9t|
t	�r[|	|
�q9t|
t541�rh|��|
�q9t|
�rx|��t|
|d542��q9|	|t|
���q9|�|j
dur�|�|j
���fdd�|D�}|S)aCombine a number of renderables and text into one renderable.543 544        Args:545            objects (Iterable[Any]): Anything that Rich can render.546            sep (str): String to write between print data.547            end (str): String to write at end of print data.548            justify (str, optional): One of "left", "right", "center", or "full". Defaults to ``None``.549            emoji (Optional[bool], optional): Enable emoji code, or ``None`` to use console default.550            markup (Optional[bool], optional): Enable markup, or ``None`` to use console default.551            highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use console default.552 553        Returns:554            List[ConsoleRenderable]: A list of things to render.555        )rUrVrWr�rzNcs�t|tt����dSr�)r-r!r.)r�)�_appendrurarb�align_appendsz2Console._collect_renderables.<locals>.align_appendcs0�rt���d�}�|�������dSdS)N)rur�)rI�joinr�)�sep_text)r|r�rur�r�rarb�556check_texts557�z0Console._collect_renderables.<locals>.check_text)r!ryrxr&)r&c�g|]}t|���qSrarD�rr�r�rarb�558<listcomp>-rz0Console._collect_renderables.<locals>.<listcomp>�rzN)r|r�rHr=r&r=r�r�r�rIr�r<r;r�r�)r~r�r�r�rur!ryrxr��append_textr�r�r�r�ra)r�r|r�rur�r�r�rb�_collect_renderables�sL559��560	561562563564zConsole._collect_renderablesu─z	rule.linerV)�565charactersr��alignr�r�cCs*ddlm}|||||d�}|�|�dS)u�Draw a line with optional centered title.566 567        Args:568            title (str, optional): Text to render over the rule. Defaults to "".569            characters (str, optional): Character(s) to form the line. Defaults to "─".570            style (str, optional): Style of line. Defaults to "rule.line".571            align (str, optional): How to align the title, one of "left", "center", or "right". Defaults to "center".572        r$)�Rule)r�r�r�r�N)�ruler�r�)r~r�r�r�r�r�r�rararbr�1szConsole.ruler�cGsJ|js#|�|j�dd�|D��Wd�dS1swYdSdS)z�Insert non-printing control codes.573 574        Args:575            control_codes (str): Control codes, such as those that may move the cursor.576        cs��|]}|jVqdSr�)�segment)r�_controlrararb�	<genexpr>N��z"Console.control.<locals>.<genexpr>N)rJr�r�)r~r�rararbr�Fs577"��zConsole.controlrWr�)r�r�r�rxcGs4|�dd�|D��}|j|||ddddd|d�	dS)a�Output to the terminal. This is a low-level way of writing to the terminal which unlike578        :meth:`~rich.console.Console.print` won't pretty print, wrap text, or apply markup, but will579        optionally apply highlighting and a basic style.580 581        Args:582            sep (str, optional): String to write between print data. Defaults to " ".583            end (str, optional): String to write at end of print data. Defaults to "\\n".584            style (Union[str, Style], optional): A style to apply to output. Defaults to None.585            highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use586                console default. Defaults to ``None``.587        cs��|]}t|�VqdSr�)r�)r�_objectrararbr�c��zConsole.out.<locals>.<genexpr>FTr\)r�rxr!ryrwrvrZr�N)r�r�)r~r�r�r�rxr��588raw_outputrararb�outPs589�zConsole.out)r�r�r�rurvrwr!ryrxrhrirZr�new_line_startrwrZrc590Gs�|st�f}|
dur
|j}
|
r|durd}|durd}d}|jdd�}|��|j|||||||	d�}|D]}|�|�}q5|jj|||591durLt|592|j�nt	||||	d�}g}|j593}|j}|durm|D]	}||||��qbn|D]}|t�
|||�|�|���qo|r�td�dd	�|D�����d594kr�|�dt���|r�|jj595}tj||jdd�D]}||�q�n|j�596|�Wd�dSWd�dS1s�wYdS)
a[Print to the console.597 598        Args:599            objects (positional args): Objects to log to the terminal.600            sep (str, optional): String to write between print data. Defaults to " ".601            end (str, optional): String to write at end of print data. Defaults to "\\n".602            style (Union[str, Style], optional): A style to apply to output. Defaults to None.603            justify (str, optional): Justify method: "default", "left", "right", "center", or "full". Defaults to ``None``.604            overflow (str, optional): Overflow method: "ignore", "crop", "fold", or "ellipsis". Defaults to None.605            no_wrap (Optional[bool], optional): Disable word wrapping. Defaults to None.606            emoji (Optional[bool], optional): Enable emoji code, or ``None`` to use console default. Defaults to ``None``.607            markup (Optional[bool], optional): Enable markup, or ``None`` to use console default. Defaults to ``None``.608            highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use console default. Defaults to ``None``.609            width (Optional[int], optional): Width of output, or ``None`` to auto-detect. Defaults to ``None``.610            crop (Optional[bool], optional): Crop output to width of terminal. Defaults to True.611            soft_wrap (bool, optional): Enable soft wrap mode which disables word wrapping and cropping of text or ``None`` for612                Console default. Defaults to ``None``.613            new_line_start (bool, False): Insert a new line at the start if the output contains more than one line. Defaults to ``False``.614        NTr\Fr�)rurvrhrirwryrxr�csr�r��r��rr�rararbr��r�z Console.print.<locals>.<genexpr>r$r�r�)r�rrPr�r615r�r��minrhr�r�r6rAr�r�r�r��616splitlines�insertr�r�r�)r~r�r�r�rurvrwr!ryrxrhrirZrrr��render_hooksr�r�r��new_segmentsr�r6r��
buffer_extendr�rararbr�psz%�	�617����618619��+"�z
Console.printrc)	�data�indentrx�	skip_keys�ensure_ascii�check_circular�	allow_nanrT�	sort_keys�jsonrrr
rrrrc	
Csxddlm}|dur|j||||||||	|620d�	}nt|t�s&td|�d���|||||||||	|621d�	}|j|dd�dS)	a�Pretty prints JSON. Output will be valid JSON.622 623        Args:624            json (Optional[str]): A string containing JSON.625            data (Any): If json is not supplied, then encode this data.626            indent (Union[None, int, str], optional): Number of spaces to indent. Defaults to 2.627            highlight (bool, optional): Enable highlighting of output: Defaults to True.628            skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.629            ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.630            check_circular (bool, optional): Check for circular references. Defaults to True.631            allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.632            default (Callable, optional): A callable that converts values that can not be encoded633                in to something that can be JSON encoded. Defaults to None.634            sort_keys (bool, optional): Sort dictionary keys. Defaults to False.635        r)�JSONN)rrxr
rrrrTrz/json must be str. Did you mean print_json(data=z) ?T)r)�pip._vendor.rich.jsonr�	from_datar�r�r�r�)
r~rrrrxr
rrrrTrr�json_renderablerararb�636print_json�s:�637638��zConsole.print_json)�regionr�rc639Csz|jst�d��|p|j}|dur!d}}|�|j|jp|j�}n|\}}}}|�||�}|j||d�}	|�|	||�dS)a�Update the screen at a given offset.640 641        Args:642            renderable (RenderableType): A Rich renderable.643            region (Region, optional): Region of screen to update, or None for entire screen. Defaults to None.644            x (int, optional): x offset. Defaults to 0.645            y (int, optional): y offset. Defaults to 0.646 647        Raises:648            errors.NoAltScreen: If the Console isn't in alt screen mode.649 650        �0Alt screen must be enabled to call update_screenNrr�)	r�r%�NoAltScreenr�r�rqrir��update_screen_lines)651r~r�rr�r�r�r�rhrir�rararb�
update_screens652653�zConsole.update_screenrr�r�r�cCs>|jst�d��t|||�}|�|�}|j�|�|��dS)a�Update lines of the screen at a given offset.654 655        Args:656            lines (List[List[Segment]]): Rendered lines (as produced by :meth:`~rich.Console.render_lines`).657            x (int, optional): x offset (column no). Defaults to 0.658            y (int, optional): y offset (column no). Defaults to 0.659 660        Raises:661            errors.NoAltScreen: If the Console isn't in alt screen mode.662        rN)r�r%rr�r6r�r�rz)r~r�r�r��
screen_updater�rararbr2s
663664zConsole.update_screen_linesrR�ra�rhr�r��	word_wrap�show_locals�suppress�665max_framesr�r r!r"r#c666	Cs0ddlm}||||||||d�}	|�|	�dS)a
Prints a rich render of the last exception and traceback.667 668        Args:669            width (Optional[int], optional): Number of characters used to render code. Defaults to 100.670            extra_lines (int, optional): Additional lines of code to render. Defaults to 3.671            theme (str, optional): Override pygments theme used in traceback672            word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.673            show_locals (bool, optional): Enable display of local variables. Defaults to False.674            suppress (Iterable[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.675            max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.676        r$)�	TracebackrN)r�r$r�)677r~rhr�r�r r!r"r#r$r�rararb�print_exceptionFs�	zConsole.print_exceptionr��currentframecCsx|d7}|�}|dur-|r|dur|j}|d8}|r|dus|dus$J�|jj|j|jfSt��|}|j|j|j	jfS)aEGet caller frame information.678 679        Args:680            offset (int): the caller offset within the current frame stack.681            currentframe (Callable[[], Optional[FrameType]], optional): the callable to use to682                retrieve the current frame. Defaults to ``inspect.currentframe``.683 684        Returns:685            Tuple[str, int, Dict[str, Any]]: A tuple containing the filename, the line number and686                the dictionary of local variables associated with the caller frame.687 688        Raises:689            RuntimeError: If the stack offset is invalid.690        r$N)691�f_back�f_code�co_filename�f_lineno�f_locals�inspect�stack�filename�lineno�frame)r�r&r0�692frame_inforararb�_caller_frame_infois�zConsole._caller_frame_info)	r�r�r�rur!ryrx�693log_locals�
_stack_offsetr3r4c	694s^|695st�f}696|jdd�}|��|j|697||||||d�}�dur)�fdd�|D�}|�|	�\}
}}|
�d�r8dntj�|
�}|
�tj	�d}|rZdd�|�698�D�}|�t|d	d699��|j
|||��|||d�g}|D]}|�|�}qjg}|j}|j}|j}|D]	}||||��q|jj}tj||jdd
�D]}||�q�Wd�dS1s�wYdS)aXLog rich content to the terminal.700 701        Args:702            objects (positional args): Objects to log to the terminal.703            sep (str, optional): String to write between print data. Defaults to " ".704            end (str, optional): String to write at end of print data. Defaults to "\\n".705            style (Union[str, Style], optional): A style to apply to output. Defaults to None.706            justify (str, optional): One of "left", "right", "center", or "full". Defaults to ``None``.707            emoji (Optional[bool], optional): Enable emoji code, or ``None`` to use console default. Defaults to None.708            markup (Optional[bool], optional): Enable markup, or ``None`` to use console default. Defaults to None.709            highlight (Optional[bool], optional): Enable automatic highlighting, or ``None`` to use console default. Defaults to None.710            log_locals (bool, optional): Boolean to enable logging of locals where ``log()``711                was called. Defaults to False.712            _stack_offset (int, optional): Offset of caller from end of call stack. Defaults to 1.713        Nr�cr�rarDr�r�rarbr��rzConsole.log.<locals>.<listcomp>�<�����cSs i|]\}}|�d�s||�qS)�__)r|)r�keyrerararbr�s��zConsole.log.<locals>.<dictcomp>z	[i]locals)r�)r#�path�line_no�	link_pathFr)r�rPr�r2r|r�r9�abspathrpr��itemsr|r?rGr(r714r�r6r�r�rAr�rh)r~r�r�r�rur!ryrxr3r4r�rr�r.r:�localsr;r9�715locals_mapr�r	r�r6r�r�r716r�rar�rb�log�s^�	���717718719�"�zConsole.logcCs0d|_t�tjtj�}t�|tj���t	d��)alThis function is called when a `BrokenPipeError` is raised.720 721        This can occur when piping Textual output in Linux and macOS.722        The default implementation is to exit the app, but you could implement723        this method in a subclass to change the behavior.724 725        See https://docs.python.org/3/library/signal.html#note-on-sigpipe for details.726        Tr$)727rr��open�devnull�O_WRONLY�dup2r[r\�fileno�728SystemExit)r~rBrararb�on_broken_pipe�s	zConsole.on_broken_pipecCsB|jr|jdd�=dSz|��WdSty |��YdSw)aQCheck if the buffer may be rendered. Render it if it can (e.g. Console.quiet is False)729        Rendering is supported on Windows, Unix and Jupyter environments. For730        legacy Windows consoles, the win32 API is called directly.731        This method will also record what it renders if recording is enabled via Console.record.732        N)rr��
_write_buffer�BrokenPipeErrorrGr}rararbrz�s�zConsole._check_buffercCs�|j��B|jr)|js)|j�|j�|jdd��Wd�n1s$wY|jdk�r6|jrMddlm	}||j|�733|jdd���|jdd�=n�tr�d}|jrat
|j�}|dura|tv}|r�ddlm}ddlm}|jdd�}|jr�|jr�tt�|��}||||j��n�|�734|jdd��}|jj}d}	zJt|�|	kr�||�n=g}735|736j}d}|�d	�D]#}
|t|
�|	kr�|737r�|d738�|739��|740��d}||
�|t|
�7}q�|741r�|d742�|743��|744��Wn<ty�}z|j �d�|_ �d}~ww|�745|jdd��}z|j�|�Wnt�y"}z|j �d�|_ �d}~ww|j�!�|jdd�=Wd�dSWd�dSWd�dS1�sJwYdS)z$Write the buffer to the output file.Nrr$)�displayF)�LegacyWindowsTerm)�legacy_windows_renderi Tr�zG746*** You may need to add PYTHONIOENCODING=utf-8 to your environment ***)"r�r rdrLrOr�r�r6�jupyterrJr�rror*rr��pip._vendor.rich._win32_consolerK�"pip._vendor.rich._windows_rendererrLrrBr�rA�remove_color�writer�r|rr�r��UnicodeEncodeError�reason�flush)r~rJ�use_legacy_windows_renderrErKrLr�r�rQ�	MAX_WRITE�batch�batch_appendrnr�r�rararbrH�s�747�748�749�����750��751$�zConsole._write_bufferr�cCszg}|j}|j}|j}|j}|jr|rt�|�}|D]\}}}	|r-||j|||d��q|r1|	s5||�qd�|�}752|753S)z)Render buffered output, and clear buffer.)rror�)	r|rBrorrrrArPr6r�)r~r��outputr|rro�not_terminalr�r�r��renderedrararbr�Cs*754755���756zConsole._render_buffer)ryr!�password�stream�promptr\r]cCsD|r|j|||dd�|rtd|d�}|S|r|��}|St�}|S)a5Displays a prompt and waits for input from the user. The prompt may contain color / style.757 758        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.759 760        Args:761            prompt (Union[str, Text]): Text to render in the prompt.762            markup (bool, optional): Enable console markup (requires a str prompt). Defaults to True.763            emoji (bool, optional): Enable emoji (requires a str prompt). Defaults to True.764            password: (bool, optional): Hide typed text. Defaults to False.765            stream: (TextIO, optional): Optional file to read input from (rather than stdin). Defaults to None.766 767        Returns:768            str: Text read from stdin.769        r�)ryr!r�)r])r�r�readline�input)r~r^ryr!r\r]�resultrararbr`[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).770 771        Args:772            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.773            styles (bool, optional): If ``True``, ansi escape codes will be included. ``False`` for plain text.774                Defaults to ``False``.775 776        Returns:777            str: String containing console contents.778 779        �ITo export console contents set record=True in the constructor or instancer�css(�|]\}}}|r|�|�n|VqdSr�r5)rr�r��_rararbr��s780��781�z&Console.export_text.<locals>.<genexpr>css�|]	}|js|jVqdSr�)r�r�rrararbr��s��782�N)r rLr�rO)r~r�r�r�rararb�export_text}s*
��783784785�786��787��zConsole.export_textr9cCsL|j||d�}t|ddd��}|�|�Wd�dS1swYdS)a�Generate text from console and save to a given location (requires record=True argument in constructor).788 789        Args:790            path (str): Path to write text files.791            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.792            styles (bool, optional): If ``True``, ansi style codes will be included. ``False`` for plain text.793                Defaults to ``False``.794 795        rb�wr��rsN)rerArQ)r~r9r�r�r��796write_filerararb�	save_text�s797"�zConsole.save_text�r�r��code_format�
inline_stylesrkrlc	Cs�|jsJd��g}|j}|pt}d}|durtn|}	|j��|rYt�t�|j��D].\}798}}t	|799�}800|rS|�801|�}
|jrFd|j�d|802�d�}803|
rQd|
�d|804�d�n|805}806||807�q)ndi}t�t�|j��D]8\}808}}t	|809�}810|r�|�811|�}
|�|
t
|�d	�}|jr�d812|�d|j�d|813�d�}814n	d|�d|815�d�}816||817�qdg}|j}|��D]\}}|r�|d
|�d|�d��q�d�|�}|	jd�|�||jj|jjd�}|r�|jdd�=Wd�|SWd�|S1s�wY|S)aIGenerate HTML from console contents (requires record=True argument in constructor).818 819        Args:820            theme (TerminalTheme, optional): TerminalTheme object containing console colors.821            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.822            code_format (str, optional): Format string to render HTML. In addition to '{foreground}',823                '{background}', and '{code}', should contain '{stylesheet}' if inline_styles is ``False``.824            inline_styles (bool, optional): If ``True`` styles will be inlined in to spans, which makes files825                larger but easier to cut and paste markup. If ``False``, styles will be embedded in a style tag.826                Defaults to False.827 828        Returns:829            str: String containing console contents as HTML.830        rcr�Nz	<a href="z">z</a>z
<span style="z</span>r$z<a class="rz" href="z<span class="rz.rz {�}r�)�code�831stylesheet�832foreground�833background)r r|rFr(rLrA�filter_control�simplifyrOr	�get_html_styler��834setdefaultr�r=r��format�foreground_color�hex�background_color)r~r�r�rkrl�	fragmentsr|�_themero�render_code_formatr�r�rdr�r��style_number�stylesheet_rules�stylesheet_append�835style_rule�
rendered_coderararb�export_html�sp��836�837838�839�840841�842�843�)�844�)�)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).845 846        Args:847            path (str): Path to write html file.848            theme (TerminalTheme, optional): TerminalTheme object containing console colors.849            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``.850            code_format (str, optional): Format string to render HTML. In addition to '{foreground}',851                '{background}', and '{code}', should contain '{stylesheet}' if inline_styles is ``False``.852            inline_styles (bool, optional): If ``True`` styles will be inlined in to spans, which makes files853                larger but easier to cut and paste markup. If ``False``, styles will be embedded in a style tag.854                Defaults to False.855 856        rjrfr�rgN)r�rArQ)r~r9r�r�rkrl�htmlrhrararb�	save_html�s�"�zConsole.save_html�Richg��Q���?�r�r�r�rk�font_aspect_ratio�	unique_idr�r�c2sddlm}i�dtdtf��fdd�}|pt�|j�d}	|	|�|	d�d	}857d	}d	}d	}
d858}d}d}d}||}||}|
|}|859|}g}g}i}d	}dtdtfd
d�}	d8dtdttdtdtfdd��|j�t	t860�|j��}|rz|j�
�Wd�n1s�wY�dur�dtt�d�dd�|D���dd�|�dd����d}tt861j|�d��D]�\}}d}|D]�\}} }!| p�t�} || �}"|"|vr�|||"<|d	7}d||"��}#| jr�d}$| jdur�jjn| j���j}%n| j}&|&duo�|&j}$| jdu�r�jjn| j���j}%||�}'|$�r-|��d|%|�|�d�|'�d d!d"��|d#t|�k�r\|��d||���d$|#��|�|�|	�t|�d%��d&|�d'�d(��|||�7}q�q��fd)d*�t|�D�}(d+������fd,d�t|(�D��})d+��fd-d�|��D��}*d�|�}+d�|�},t ��|�}-|d	�|}.�d�jjd.d/|
|862|-|.dd0�	}/�jj}0|�r�|/�d||���d1�|0d2|-d3|863|	d4d5�7}/|/d67}/|j!��|	���d	|d	�d	|-||.||
||864||*|/|+|,|)d7�}1|1S)9a865        Generate an SVG from the console contents (requires record=True in Console constructor).866 867        Args:868            title (str, optional): The title of the tab in the output image869            theme (TerminalTheme, optional): The ``TerminalTheme`` object to use to style the terminal870            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``871            code_format (str, optional): Format string used to generate the SVG. Rich will inject a number of variables872                into the string in order to form the final SVG output. The default template used and the variables873                injected by Rich can be found by inspecting the ``console.CONSOLE_SVG_FORMAT`` variable.874            font_aspect_ratio (float, optional): The width to height ratio of the font used in the ``code_format``875                string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font).876                If you aren't specifying a different font inside ``code_format``, you probably don't need this.877            unique_id (str, optional): unique id that is used as the prefix for various elements (CSS styles, node878                ids). If not set, this defaults to a computed value based on the recorded content.879        r)�cell_lenr�rzcs�|�vr�|Sg}|jdus|jjr�jn|j���}|jdus%|jjr(�jn|j���}|jr6||}}|jr?t||d�}|�	d|j880���|jrP|�	d�|jrX|�	d�|j
r`|�	d�|jrh|�	d�d�|�}|�|<|S)	z%Convert a Style to CSS rules for SVG.Ng�������?zfill: zfont-weight: boldzfont-style: italic;ztext-decoration: underline;ztext-decoration: line-through;�;)�color�881is_defaultrw�
get_truecolor�bgcolorry�reverse�dimr0r|rx�bold�italic�	underline�striker�)r��	css_rulesr�r��css)r{�style_cacherarb�
get_svg_style4	s6�882��883�884885886887888889z)Console.export_svg.<locals>.get_svg_style�g��Q���?r$�(rr�cSst|��dd�S)z.HTML escape text and replace spaces with nbsp.rWz&#160;)r	�replacerrararb�escape_textp	sz'Console.export_svg.<locals>.escape_textNrr��attribsc	sbdtdtfdd��d��fdd�|��D��}|r(d|�d|�d	|�d890|�d	�	Sd|�d|�d�S)z.Make a tag from name, content, and attributes.rerzcSst|t�r891t|d�St|�S)N�g)r��floatrvr�)rerararb�	stringifyy	s892893z7Console.export_svg.<locals>.make_tag.<locals>.stringifyrWc3s6�|]\}}|�d��dd��d�|��d�VqdS)rdrkz="�"N)�lstripr�)r�k�v�r�rarbr�~	s894� �895�z7Console.export_svg.<locals>.make_tag.<locals>.<genexpr>r5rXz</z/>)�objectr�r�r=)rr�r��tag_attribsrar�rb�make_tagt	s����z$Console.export_svg.<locals>.make_tagz	terminal-r�csr�r�)�reprrrararbr��	r�z%Console.export_svg.<locals>.<genexpr>r�r\)�length�rT�rect��?��?�896crispEdges)�fillr�r�rhri�shape_renderingrWrkzurl(#�-line-�))�_classr�r��897textLength�	clip_pathcsg|]}|�d�qS)r�ra)rr:)�line_heightrarbr��	sz&Console.export_svg.<locals>.<listcomp>r�c
3sB�|]\}}d��d|�d�dd|���dd��d�VqdS)	z<clipPath id="r�z">898    r�rr�)r�r�rhriz899            </clipPath>Nra)rr:r�)�900char_widthr�r�r�rhrarbr��	s���901�c3s,�|]\}}d��d|�d|�d�VqdS)�.z-rz { z }Nra)rr��rule_no)r�rarbr��	s�902�zrgba(255,255,255,0.35)r5)r��stroke�stroke_widthr�r�rhri�rxz-title�middlerc�)r�r��text_anchorr�r�z�903            <g transform="translate(26,22)">904            <circle cx="0" cy="0" r="7" fill="#ff5f57"/>905            <circle cx="22" cy="0" r="7" fill="#febc2e"/>906            <circle cx="44" cy="0" r="7" fill="#28c840"/>907            </g>908        )r�r��char_heightr��terminal_width�terminal_heightrhri�909terminal_x�910terminal_yr��chrome�backgrounds�matrixr�r�)"�pip._vendor.rich.cellsr�rBr�rGrhrr�rLr�rArrrOr��zlib�adler32r��encoder�r�r�r�rwrxr�r�r�ryr|r��ranger=rrv)2r~r�r�r�rkr�r�r�r�r��911margin_top�margin_right�
margin_bottom�margin_left�padding_top�
padding_right�padding_bottom�padding_left�
padding_width�padding_height�margin_width�
margin_height�text_backgrounds�912text_group�classes�style_nor�r�r�r�r�r�r�r��rules�913class_name�has_backgroundrqr��text_length�line_offsetsr�r�r�r�r�r�r��title_color�svgra)r{r�r�r�r�r�rhrb�914export_svg	s2!����915�916���917���	918919����920��921922���4��923924�925�	926�zConsole.export_svgc927CsT|j||||||d�}t|ddd��}	|	�|�Wd�dS1s#wYdS)a7Generate an SVG file from the console contents (requires record=True in Console constructor).928 929        Args:930            path (str): The path to write the SVG to.931            title (str, optional): The title of the tab in the output image932            theme (TerminalTheme, optional): The ``TerminalTheme`` object to use to style the terminal933            clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``934            code_format (str, optional): Format string used to generate the SVG. Rich will inject a number of variables935                into the string in order to form the final SVG output. The default template used and the variables936                injected by Rich can be found by inspecting the ``console.CONSOLE_SVG_FORMAT`` variable.937            font_aspect_ratio (float, optional): The width to height ratio of the font used in the ``code_format``938                string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font).939                If you aren't specifying a different font inside ``code_format``, you probably don't need this.940            unique_id (str, optional): unique id that is used as the prefix for various elements (CSS styles, node941                ids). If not set, this defaults to a computed value based on the recorded content.942        r�rfr�rgN)r�rArQ)943r~r9r�r�r�rkr�r�r�rhrararb�save_svg944s�"�zConsole.save_svgr�)rzr�r�r�r�)TNr�r�)rr)r^r_r`rjr�r�rrr�rlr4rrr�rKrrkrCr2r r+rrr�r�rYr�r�setterrrAr�rdrLrgr/rCr�r�r}r�r	r�r�r�rr�r�r�r�r�r�r�rrsrrrJrmr�rgrnrrhrir�r�r�r9r�r�r�r�r�r�r�r�r�r�r�r7r�rr6rBr�r�r�r*r�r�r�r�rJr.r�r1r�rr�rr>rrrr%�staticmethodr,r&rrr2r@rGrzrHr�rr`rerirHr�r(r�r)r�r�rarararbr�Ks�945#������	�946��947�
�������������948������ 949�	/
(950����951�952������953�!!���954����955����956�6�������957958�D��959�����	�960�961�>�962��963�$�������	�964 965�Q����966��967�
������968�#��������	�969���
����970�e��������	�971���
972�A����973�#�974���975��������	�976 977�#����%��������	�978��979�QI�980�������&", ������O981�������"�������	�982�������	�983�r��
svg_main_codecCstt�|����S)z�Returns a unique hash for the given SVG main code.984 985    Args:986        svg_main_code (str): The content we're going to inject in the SVG envelope.987 988    Returns:989        str: a hash of the given content990    )r�r�r�r�)r�rararb�	_svg_hash7991s	r��__main__)r zJSONRPC [i]request[/i]�g�������?Fz2.0�subtract�*�)�minuend�992subtrahendr)Zjsonrpcr��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�Zanswer)�answered�q1z	5 + 7 = ?)�993���
r�z99412 - 8 = ?)r$rcr�r�)r�r��q2)ZsportZmaths)r�emptyZquizr�)rzrM)�r,r�r[rEr��abcrr�dataclassesrrr�	functoolsrrr�r	r995�	itertoolsr�mathr�timer
�typesrrr�typingrrrrrrrrrrrrrrrr r!r"�pip._vendor.rich._null_filer#r�r%r&r'�_export_formatr(r)�_filenor*rGr+r,r�r-r.r�r/r0r�r1r!r2r&r3r4ryr6r�r�r7r8r�r9r:�prettyr;r<�protocolr=rr>�scoper?r�r@r�rAr�rBrC�styledrE�terminal_themerFrGrHr�rIrJr�rKrLrrMr{rNr�rPr8r9�platformrr�r*r�r�r]r��	__stdin__rE�
_STDIN_FILENO�	Exception�996__stdout__�_STDOUT_FILENO�997__stderr__�_STDERR_FILENOr�r�rmrrrqrgrmr�r�r�r�rHr�r�r�r�r�r�r�r�r�r�r�rlrDr=r��localrr	rrlr
rr�r�r^r�r@r�r�rarararb�<module>sJ998P999���1000�		1001!'/$!�10021003{10041005�����������
Aluode/PerceptionLabPortable · CoolFace