Current File : /home/inlingua/miniconda3/lib/python3.1/site-packages/rich/__pycache__/progress.cpython-312.pyc
�

~�Eg���+��
�ddlZddlZddlZddlZddlmZmZddlmZddl	m
Z
mZddlm
Z
ddlmZmZddlmZddlmZdd	lmZdd
lmZmZddlmZmZmZddlmZdd
lmZmZm 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.m/Z/ej`dk\rddlm1Z1nddl2m1Z1ej`dk\rddlm3Z3nddl2m3Z3ddl4m5Z5m6Z6ddl7m8Z8m9Z9m:Z:m;Z;ddl<m=Z=ddl>m?Z?ddl@mAZAddlBmCZCddlDmEZEddlFmGZGddlHmIZImJZJddlKmLZLmMZMe(deN�ZOe.d�ZPe geQfZRej\de+e�ZSGd �d!e�ZT															d�d)e/e*ePe%ePfd*eUd+e)eQd,eNd-eVd.e)e8d/eVd0e)e geQfd1eQd2eGd3eGd4eGd5eGd6eQd7eVd8eVd9e%ePf"d:�ZWGd;�d<ee�ZXGd=�d>e!eSe$eS�ZYd?d"dd#dd$d%d&d'd(d#d@�dAed+eNd*eUd-eVd.e)e8d/eVd0e)e geQfd1eQd2eGd3eGd4eGd5eGd7eVd9e!efdB�ZZej�				d�dd?d"dd#dd$d%d&d'd(d#dC�dAe/eUdDe\fdEe/e1dFe1dGfdHeNdIe)eUdJe)eUdKe)eUd+e)eNd*eUd-eVd.e)e8d/eVd0e)e geQfd1eQd2eGd3eGd4eGd5eGd7eVd9e!e+f&dL��Z]ej�				d�dd?d"dd#dd$d%d&d'd(d#dC�dAe/eUdDe\fdEe1dMdHeNdIe)eUdJe)eUdKe)eUd+e)eNd*eUd-eVd.e)e8d/eVd0e)e geQfd1eQd2eGd3eGd4eGd5eGd7eVd9e!ef&dN��Z]					d�dd?d"dd#dd$d%d&d'd(d#dC�dAe/eUdDe\fdEe/e1dMe1dFe1dGfdHeNdIe)eUdJe)eUdKe)eUd+e)eNd*eUd-eVd.e)e8d/eVd0e)e geQfd1eQd2eGd3eGd4eGd5eGd7eVd9e/e!ee!e+ff&dO�Z]GdP�dQe�Z^GdR�dSe^�Z_GdT�dUe^�Z`GdV�dWe^�ZaGdX�dYe^�ZbGdZ�d[e^�ZcGd\�d]ea�ZdGd^�d_e^�ZeGd`�dae^�ZfGdb�dce^�ZgGdd�dee^�ZhGdf�dge^�ZiGdh�die^�ZjGdj�dke'�Zke
Gdl�dm��ZlGdn�doe?�Zmendpk(�rhddloZoddlpZpddqlqmrZrddrlsmtZtddslumvZvddtlHmJZJevdudvd"�w�ZueJdxdydz�ZHeHj�d{d|d}�d~erd�d�eHd�d�d�d��d�euetd��g	Zxdd�lymzZzezex�Z{e8d"���Z7eme`�gemj���ec���e7d#d���5Z}e}j�d�d����Ze}j�d�d����Z�e}j�d�d���Z�e}�jsxe}�jed����e}�je�d����ep�jd��eo�j
dd��dkre}�j
e�e{��e}�js�xddd�yy#1swYyxYw)��N)�ABC�abstractmethod��deque)�	dataclass�field)�	timedelta)�	RawIOBase�UnsupportedOperation)�ceil)�mmap)�length_hint)�PathLike�stat)�Event�RLock�Thread)�
TracebackType)�Any�BinaryIO�Callable�ContextManager�Deque�Dict�Generic�Iterable�List�
NamedTuple�NewType�Optional�Sequence�TextIO�Tuple�Type�TypeVar�Union)��)�Literal)r'�)�Self�)�filesize�get_console)�Console�Group�
JustifyMethod�RenderableType)�Highlighter)�JupyterMixin)�Live)�ProgressBar)�Spinner)�	StyleType)�Column�Table)�Text�TextType�TaskID�ProgressType�_Ic�p��eZdZdZdddddef�fd�Zdd
�Zdd�Zdee	e
d
ee
deedd	fd�Z�xZ
S)�_TrackThreadz)A thread to periodically update progress.�progress�Progress�task_idr=�
update_periodc�|��||_||_||_t�|_d|_t�|�d��y)NrT)�daemon)rBrDrEr�done�	completed�super�__init__)�selfrBrDrE�	__class__s    ��-lib/python3.12/site-packages/rich/progress.pyrKz_TrackThread.__init__Gs9��� ��
����*����G��	����
�����%��returnNc���|j}|jj}|j}d}|jj
}||�sh|jjjrH|j}||k7r||||z
�|}||�s!|jjjr�H|jj|j|jd��y)NrT)rI�refresh)
rDrB�advancerErH�wait�live�
is_startedrI�update)rLrDrSrE�last_completedrTrIs       rN�runz_TrackThread.runPs����,�,���-�-�'�'���*�*�
����y�y�~�~���}�%�$�-�-�*<�*<�*G�*G����I���*����^�!;�<�!*��	�}�%�$�-�-�*<�*<�*G�*G�	
�
�
���T�\�\�T�^�^�T��RrOc�&�|j�|S�N��start�rLs rN�	__enter__z_TrackThread.__enter__^����
�
���rO�exc_type�exc_val�exc_tbc�X�|jj�|j�yr[)rH�set�join�rLrarbrcs    rN�__exit__z_TrackThread.__exit__bs��	
�	�	�
�
���	�	�rO�rPN)rPrA)�__name__�
__module__�__qualname__�__doc__�floatrKrYr_r r$�
BaseExceptionrrh�
__classcell__�rMs@rNrArADsj���3�&��&�h�&�u�&�S����4�
�.�/���-�(����'�	�

�rOrATF�
�bar.back�bar.complete�bar.finished�	bar.pulse�sequence�description�totalrI�auto_refresh�console�	transient�get_time�refresh_per_second�style�complete_style�finished_style�pulse_stylerE�disable�
show_speedrPc
#�,K�|rtd�gng}|jt|	|
||��t|��t	d��f�t||||||xsd|d��}|5|j
|||||
��Ed	{���d	d	d	�y	7�
#1swYy	xYw�w)
a=Track progress by iterating over a sequence.

    Args:
        sequence (Iterable[ProgressType]): A sequence (must support "len") you wish to iterate over.
        description (str, optional): Description of task show next to progress bar. Defaults to "Working".
        total: (float, optional): Total number of steps. Default is len(sequence).
        completed (int, optional): Number of steps completed so far. Defaults to 0.
        auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True.
        transient: (bool, optional): Clear the progress on exit. Defaults to False.
        console (Console, optional): Console to write to. Default creates internal Console instance.
        refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10.
        style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
        complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
        finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
        pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
        update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.
        disable (bool, optional): Disable display of progress.
        show_speed (bool, optional): Show speed if total isn't known. Defaults to True.
    Returns:
        Iterable[ProgressType]: An iterable of the values in the sequence.

    �([progress.description]{task.description}�rr�r�r�)r�T)�elapsed_when_finishedrr�rzr{r|r}r~r�)ryrIrxrEN)�
TextColumn�extend�	BarColumn�TaskProgressColumn�TimeRemainingColumnrC�track)rwrxryrIrzr{r|r}r~rr�r�r�rEr�r��columnsrBs                  rNr�r�ls�����TEP��>�	?�@�UW���N�N���-�-�'�	
�
�*�5��d�;�		
���	�!����-�3����H�
��>�>����#�'�"�
�	
�	
�
��	
��
��s0�AB�B�8B�9B�=	B�B�B�
Bc��eZdZdZ	d)dedddededdf
d	�Zd*d
�Zde	e
ede	ed
e	eddfd�Z
defd�Zdefd�Zedefd��Zdefd�Zdefd�Zedefd��Zedefd��Zdefd�Zdefd�Zdefd�Zd+dedefd�Zdeeee ffd�Z!d+dedefd�Z"d+dede#efd�Z$d,d �Z%d-d!ed"edefd#�Z&defd$�Z'd%e(defd&�Z)d'e*e(ddfd(�Z+y).�_Readerz9A reader that tracks progress while it's being read from.�handlerBrC�task�close_handlerPNc�J�||_||_||_||_d|_y�NF)r�rBr�r��_closed)rLr�rBr�r�s     rNrKz_Reader.__init__�s(����� ��
���	�(�����rOc�:�|jj�|Sr[)r�r_r^s rNr_z_Reader.__enter__�s���������rOrarbrcc�$�|j�yr[)�closergs    rNrhz_Reader.__exit__�s
��	
�
�
�rOc��|Sr[�r^s rN�__iter__z_Reader.__iter__�s���rOc��t|j�}|jj|jt|���|S�N�rS)�nextr�rBrSr��len)rL�lines  rN�__next__z_Reader.__next__�s4���D�K�K� ���
�
���d�i�i��T���;��rOc��|jSr[)r�r^s rN�closedz_Reader.closed�s���|�|�rOc�6�|jj�Sr[)r��filenor^s rNr�z_Reader.fileno�����{�{�!�!�#�#rOc�6�|jj�Sr[)r��isattyr^s rNr�z_Reader.isatty�r�rOc�.�|jjSr[)r��moder^s rNr�z_Reader.mode�����{�{���rOc�.�|jjSr[)r��namer^s rNr�z_Reader.name�r�rOc�6�|jj�Sr[)r��readabler^s rNr�z_Reader.readable�����{�{�#�#�%�%rOc�6�|jj�Sr[)r��seekabler^s rNr�z_Reader.seekable�r�rOc��yr�r�r^s rN�writablez_Reader.writable�s��rO�sizec��|jj|�}|jj|jt|���|Sr�)r��readrBrSr�r�)rLr��blocks   rNr�z_Reader.read�s:����� � ��&���
�
���d�i�i��U���<��rO�bc��|jj|�}|jj|j|��|Sr�)r��readintorBrSr�)rLr��ns   rNr�z_Reader.readinto�s6���K�K� � ��#���
�
���d�i�i���3��rOc��|jj|�}|jj|jt|���|Sr�)r��readlinerBrSr�r�)rLr�r�s   rNr�z_Reader.readlines:���{�{�#�#�D�)���
�
���d�i�i��T���;��rO�hintc	��|jj|�}|jj|jtt
t|����|Sr�)r��	readlinesrBrSr��sum�mapr�)rLr��liness   rNr�z_Reader.readlinessA�����%�%�d�+���
�
���d�i�i��S��e�_�1E��F��rOc�^�|jr|jj�d|_y)NT)r�r�r�r�r^s rNr�z
_Reader.closes"������K�K������rO�offset�whencec��|jj||�}|jj|j|��|S)N�rI)r��seekrBrWr�)rLr�r��poss    rNr�z_Reader.seeks8���k�k���v�v�.���
�
���T�Y�Y�#��6��
rOc�6�|jj�Sr[)r��tellr^s rNr�z_Reader.tells���{�{���!�!rO�sc��td��)N�write�r)rLr�s  rNr�z
_Reader.writes
��"�7�+�+rOr�c��td��)N�
writelinesr�)rLr�s  rNr�z_Reader.writeliness
��"�<�0�0rO)T)rPr�)���ri)r),rjrkrlrmrr=�boolrKr_r r$rorrhr��bytesr��propertyr��intr�r��strr�r�r�r�r�r�r&�	bytearray�
memoryviewr
r�r�rr�r�r�r�rr�rr�r�rOrNr�r��s���C�"�������	�
��
�
����4�
�.�/���-�(����'�	�

���(���%��
������$��$�$��$�� �c� �� �� �c� �� �&�$�&�&�$�&��$�����e��
�%�	�:�t� ;�<��
�S��%��
�c��4��;��
�
�3����C��
"�c�"�,�s�,�s�,�1���
�1�$�1rOr�c�`�eZdZdZdddeddfd�Zdefd�Zd	eee	d
ee	dee
ddfd�Zy)
�_ReadContextzEA utility class to handle a context for both a reader and a progress.rBrC�readerrPNc� �||_||_yr[)rBr�)rLrBr�s   rNrKz_ReadContext.__init__"s�� ��
� ��rOc�j�|jj�|jj�Sr[)rBr]r�r_r^s rNr_z_ReadContext.__enter__&s%���
�
�����{�{�$�$�&�&rOrarbrcc�r�|jj�|jj|||�yr[)rB�stopr�rhrgs    rNrhz_ReadContext.__exit__*s*��	
�
�
���������X�w��7rO)rjrkrlrmr?rKr_r r$rorrhr�rOrNr�r�sj��O�!��!�R�!�D�!�'�2�'�8��4�
�.�/�8��-�(�8���'�	8�

�8rOr��
Reading...)rxrzr{r|r}r~rr�r�r�r��filec
���|rtd�gng}
|
jt||	|
|��t�t	�f�t|
|||||xsd|d��}|j
|||��}t||�S)aRead bytes from a file while tracking progress.

    Args:
        file (Union[str, PathLike[str], BinaryIO]): The path to the file to read, or a file-like object in binary mode.
        total (int): Total number of bytes to read.
        description (str, optional): Description of task show next to progress bar. Defaults to "Reading".
        auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True.
        transient: (bool, optional): Clear the progress on exit. Defaults to False.
        console (Console, optional): Console to write to. Default creates internal Console instance.
        refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10.
        style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
        complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
        finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
        pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
        disable (bool, optional): Disable display of progress.
    Returns:
        ContextManager[BinaryIO]: A context manager yielding a progress reader.

    r�r�rrr�)ryrx)r�r�r��DownloadColumnr�rC�	wrap_filer�)r�ryrxrzr{r|r}r~rr�r�r�r�r�rBr�s                rNr�r�4s���JEP��>�	?�@�UW���N�N���-�-�'�	
�
���!�		
���	�!����-�3����H��
�
��E�{�
�
K�F���&�)�)rO)ryrxrzr{r|r}r~rr�r�r�r��
PathLike[str]r��rt�r�	buffering�encoding�errors�newlinec��yr[r��r�r�r�r�r�r�ryrxrzr{r|r}r~rr�r�r�r�s                  rN�openr�u���,	rO�rbc��yr[r�r�s                  rNr�r��r�rOc
��|rtd�gng}|jt|
|||��t�t	�f�t|||	|
||xsd|d��}|j
||||||||��}t||�S)a�Read bytes from a file while tracking progress.

    Args:
        path (Union[str, PathLike[str], BinaryIO]): The path to the file to read, or a file-like object in binary mode.
        mode (str): The mode to use to open the file. Only supports "r", "rb" or "rt".
        buffering (int): The buffering strategy to use, see :func:`io.open`.
        encoding (str, optional): The encoding to use when reading in text mode, see :func:`io.open`.
        errors (str, optional): The error handling strategy for decoding errors, see :func:`io.open`.
        newline (str, optional): The strategy for handling newlines in text mode, see :func:`io.open`
        total: (int, optional): Total number of bytes to read. Must be provided if reading from a file handle. Default for a path is os.stat(file).st_size.
        description (str, optional): Description of task show next to progress bar. Defaults to "Reading".
        auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True.
        transient: (bool, optional): Clear the progress on exit. Defaults to False.
        console (Console, optional): Console to write to. Default creates internal Console instance.
        refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10.
        style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
        complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
        finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
        pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
        disable (bool, optional): Disable display of progress.
        encoding (str, optional): The encoding to use when reading in text mode.

    Returns:
        ContextManager[BinaryIO]: A context manager yielding a progress reader.

    r�r�rrr�)r�r�r�r�r�ryrx)r�r�r�r�r�rCr�r�)r�r�r�r�r�r�ryrxrzr{r|r}r~rr�r�r�r�r�rBr�s                     rNr�r��s���bEP��>�	?�@�UW���N�N���-�-�'�	
�
���!�		
���	�!����-�3����H��]�]��
��������	�F���&�)�)rOc�t�eZdZUdZdZeeed<ddeeddfd�Z	defd�Z
dd	defd
�Ze
dd	defd��Zy)
�ProgressColumnz3Base class for a widget to use in progress display.N�max_refresh�table_columnrPc�.�||_i|_d|_yr[)�
_table_column�_renderable_cache�_update_time)rLr�s  rNrKzProgressColumn.__init__s��)���MO���-1��rOc�2�|jxs
t�S)z.Get a table column, used to build tasks table.)r�r9r^s rN�get_table_columnzProgressColumn.get_table_columns���!�!�-�V�X�-rOr��Taskc�.�|j�}|j�=|js1	|j|j\}}||jz|kDr|S|j
|�}||f|j|j<|S#t
$rY�9wxYw)aCalled by the Progress object to return a renderable for the given task.

        Args:
            task (Task): An object containing information regarding the task.

        Returns:
            RenderableType: Anything renderable (including str).
        )r}r�rIr�id�KeyError�render)rLr��current_time�	timestamp�
renderables     rN�__call__zProgressColumn.__call__s����}�}������'����
&�(,�(>�(>�t�w�w�(G�%�	�:��t�/�/�/�,�>�%�%��[�[��&�
�+7��*D����t�w�w�'�����
��
�s�B�	B�Bc��y)z"Should return a renderable object.Nr��rLr�s  rNrzProgressColumn.render"s�rOr[)rjrkrlrmr�r rn�__annotations__r9rKrr2rrrr�rOrNr�r��sl��=�#'�K��%��'�2�X�f�%5�2��2�
.�&�.��V����.�1�6�1�n�1��1rOr�c�L��eZdZdZ	ddd�dedeef�fd�Zddd	efd
�Z�xZ	S)�RenderableColumnz�A column to insert an arbitrary column.

    Args:
        renderable (RenderableType, optional): Any renderable. Defaults to empty string.
    N�r�rr�c�4��||_t�|�	|��y�Nr)rrJrK)rLrr�rMs   �rNrKzRenderableColumn.__init__.s���%���
���l��3rOr�rrPc��|jSr[)rrs  rNrzRenderableColumn.render4s�����rO)�)
rjrkrlrmr2r r9rKrrprqs@rNrr'sB����,.�4�SW�4�(�4�@H��@P�4��6��n�rOrc���eZdZdZ					ddedeedededee	f
�fd�
Z
		dded	eeded
dfd�Zdd
d
efd�Z
�xZS)�
SpinnerColumna�A column with a 'spinner' animation.

    Args:
        spinner_name (str, optional): Name of spinner animation. Defaults to "dots".
        style (StyleType, optional): Style of spinner. Defaults to "progress.spinner".
        speed (float, optional): Speed factor of spinner. Defaults to 1.0.
        finished_text (TextType, optional): Text used when task is finished. Defaults to " ".
    N�spinner_namer�speed�
finished_textr�c���t|||��|_t|t�rt	j
|�n||_t�|�!|��y)N�rrr)	r7�spinner�
isinstancer�r;�from_markuprrJrK)rLrrrrr�rMs      �rNrKzSpinnerColumn.__init__BsN����|�5��F����-��-�
���]�+��	
��
	���l��3rO�
spinner_stylerPc�*�t|||��|_y)a-Set a new spinner.

        Args:
            spinner_name (str): Spinner name, see python -m rich.spinner.
            spinner_style (Optional[StyleType], optional): Spinner style. Defaults to "progress.spinner".
            speed (float, optional): Speed factor of spinner. Defaults to 1.0.
        rN)r7r)rLrr!rs    rN�set_spinnerzSpinnerColumn.set_spinnerRs���|�=��N��rOr�rc��|jr|j}|S|jj|j	��}|Sr[)�finishedrrrr})rLr��texts   rNrzSpinnerColumn.renderasH���}�}�
���	
�
�����$�$�T�]�]�_�5�	
�
�rO)�dots�progress.spinner��?� N)r(r))rjrkrlrmr�r r8rnr<r9rKr#r2rrprqs@rNrr8s�����#�%7��"%�)-�
4��4��	�"�4��	4�
 �4��v�&�
4�&.@��	
O��
O� �	�*�
O��	
O�

�
O��6��n�rOrc�h��eZdZdZ					ddededededee	dee
d	df�fd
�
Zddd	efd
�Z
�xZS)r�zA column containing text.N�text_formatr�justify�markup�highlighterr�rPc���||_||_||_||_||_t
�|�|xstd����y)NT��no_wrapr)r,r-rr.r/rJrKr9)rLr,rr-r.r/r�rMs       �rNrKzTextColumn.__init__msD���'���&-�����
����&���
���l�&J�f�T�6J��KrOr�rc�B�|jj|��}|jr-tj||j
|j��}n"t||j
|j��}|jr|jj|�|S�N�r�)rr-)	r,�formatr.r;r rr-r/�	highlight)rLr��_textr&s    rNrzTextColumn.render}sv��� � �'�'�T�'�2���;�;��#�#�E����T�\�\�R�D���T�Z�Z����F�D�������&�&�t�,��rO)�none�leftTNN)rjrkrlrmr�r8r1r�r r3r9rKr;rrprqs@rNr�r�js����#�
"�!'��-1�)-�L��L��L��	L�
�L��k�*�
L��v�&�L�
�L� �6��d�rOr�c�j��eZdZdZ						ddeedededededeed	df�fd
�
Zddd	e	fd
�Z
�xZS)r�aRenders a visual progress bar.

    Args:
        bar_width (Optional[int], optional): Width of bar or None for full width. Defaults to 40.
        style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
        complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
        finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
        pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
    N�	bar_widthrr�r�r�r�rPc�l��||_||_||_||_||_t
�|�|��yr)r<rr�r�r�rJrK)rLr<rr�r�r�r�rMs       �rNrKzBarColumn.__init__�s;���#�����
�,���,���&���
���l��3rOr�rc�\�t|j�td|j�ndtd|j�|j�dntd|j�|j
|j
�|j|j|j|j��	S)z&Gets a progress bar widget for a task.Nrr,)	ryrI�width�pulse�animation_timerr�r�r�)r6ry�maxrIr<�startedr}rr�r�r�rs  rNrzBarColumn.render�s����(,�
�
�(>�#�a����$�D��!�T�^�^�,��.�.�0�$�c�!�T�^�^�6L��l�l�"��=�=�?��*�*��.�.��.�.��(�(�

�
	
rO)�(rsrtrurvN)rjrkrlrmr r�r8r9rKr6rrprqs@rNr�r��s�����$&�%�$2�$2�!,�)-�4��C�=�4��4�"�	4�
"�4��
4��v�&�4�
�4� 
�6�
�k�
rOr�c� �eZdZdZdddefd�Zy)�TimeElapsedColumnzRenders time elapsed.r�rrPc���|jr|jn|j}|�
tdd��St	tdt
|����}tt|�d��S)zShow time elapsed.�-:--:--�progress.elapsed�rr)�seconds)r%�
finished_time�elapsedr;r	rBr�r�)rLr�rM�deltas    rNrzTimeElapsedColumn.render�sS��(,�
�
�$�$�$�4�<�<���?��	�);�<�<��#�a��W��"6�7���C��J�&8�9�9rON�rjrkrlrmr;rr�rOrNrFrF�s���:�6�:�d�:rOrFc���eZdZdZ								ddedededededee	d	ee
d
eddf�fd�
Zed
ee
defd��Zdddefd�Z�xZS)r�aShow task progress as a percentage.

    Args:
        text_format (str, optional): Format for percentage display. Defaults to "[progress.percentage]{task.percentage:>3.0f}%".
        text_format_no_percentage (str, optional): Format if percentage is unknown. Defaults to "".
        style (StyleType, optional): Style of output. Defaults to "none".
        justify (JustifyMethod, optional): Text justification. Defaults to "left".
        markup (bool, optional): Enable markup. Defaults to True.
        highlighter (Optional[Highlighter], optional): Highlighter to apply to output. Defaults to None.
        table_column (Optional[Column], optional): Table Column to use. Defaults to None.
        show_speed (bool, optional): Show speed if total is unknown. Defaults to False.
    Nr,�text_format_no_percentagerr-r.r/r�r�rPc	�L��||_||_t�	|�
||||||��y)N)r,rr-r.r/r�)rQr�rJrK)
rLr,rQrr-r.r/r�r�rMs
         �rNrKzTaskProgressColumn.__init__�s9���*C��&�$���
���#����#�%�
	�	
rOrc��|�
tdd��Stjt|�gd�d�\}}||z}t|d�|�d�d��S)z�Render the speed in iterations per second.

        Args:
            task (Task): A Task object.

        Returns:
            Text: Text object containing the task speed.
        rzprogress.percentagerJ)ru×10³u×10⁶u×10⁹u×10¹²��z.1fz it/s)r;r-�pick_unit_and_suffixr�)�clsr�unit�suffix�
data_speeds     rN�render_speedzTaskProgressColumn.render_speed�s_���=���"7�8�8��4�4���J�<��
���f�
�T�\�
��z�#�&�v�h�e�4�<Q�R�RrOr�rc��|j�5|jr)|j|jxs|j�S|j�|j
n|j}|j|��}|jr-tj||j|j��}n"t||j|j��}|jr|jj|�|Sr4)ryr�rZ�finished_speedrrQr,r6r.r;r rr-r/r7)rLr�r,r8r&s     rNrzTaskProgressColumn.render�s����:�:��$�/�/��$�$�T�%8�%8�%F�D�J�J�G�G�.2�j�j�.@�D�*�*�d�FV�FV�	��"�"��"�-���;�;��#�#�E����T�\�\�R�D���T�Z�Z����F�D�������&�&�t�,��rO)z-[progress.percentage]{task.percentage:>3.0f}%rr9r:TNNF)rjrkrlrmr�r8r1r�r r3r9rK�classmethodrnr;rZrrprqs@rNr�r��s�����K�)+�!�!'��-1�)-� �
��
�$'�
��	
�
�
��

��k�*�
��v�&�
��
�
�
�,�S��%��S�T�S��S�&
�6�
�d�
rOr�c�R��eZdZdZdZ			ddededeef�fd�
Zddd	e	fd
�Z
�xZS)r�aRenders estimated time remaining.

    Args:
        compact (bool, optional): Render MM:SS when time remaining is less than an hour. Defaults to False.
        elapsed_when_finished (bool, optional): Render time elapsed when the task is finished. Defaults to False.
    ��?�compactr�r�c�B��||_||_t�|�
|��yr)r`r�rJrK)rLr`r�r�rMs    �rNrKzTimeRemainingColumn.__init__s$������%:��"�
���l��3rOr�rrPc��|jr|jr|j}d}n|j}d}|j�
td|��S|�!t|jrd|��Sd|��Stt|�d�\}}t|d�\}}|jr|s
|d�d	|d��}n
|d
�d	|d�d	|d��}t||��S)zShow time remaining.rIzprogress.remainingrrJz--:--rH�<�02d�:�d)	r�r%rL�time_remainingryr;r`�divmodr�)rLr��	task_timer�minutesrK�hours�	formatteds        rNrzTimeRemainingColumn.renders����%�%�$�-�-��*�*�I�&�E��+�+�I�(�E��:�:����%�(�(����4�<�<��e�L�L�Y�e�L�L�"�#�i�.�"�5�������,���w��<�<��"�3�-�q���
�6�I� ��)�1�W�S�M��7�3�-�@�I��I�U�+�+rO)FFN)rjrkrlrmr�r�r r9rKr;rrprqs@rNr�r�sS�����K��&+�)-�	4��4� $�4��v�&�	4�,�6�,�d�,rOr�c� �eZdZdZdddefd�Zy)�FileSizeColumnzRenders completed filesize.r�rrPc�l�tjt|j��}t	|d��S)�Show data completed.zprogress.filesizerJ)r-�decimalr�rIr;�rLr��	data_sizes   rNrzFileSizeColumn.render9s)���$�$�S����%8�9�	��I�%8�9�9rONrOr�rOrNrnrn6s��%�:�6�:�d�:rOrnc� �eZdZdZdddefd�Zy)�TotalFileSizeColumnzRenders total filesize.r�rrPc��|j�(tjt|j��nd}t	|d��S)rprzprogress.filesize.totalrJ)ryr-rqr�r;rrs   rNrzTotalFileSizeColumn.renderBs4��9=���9O�H�$�$�S����_�5�UW�	��I�%>�?�?rONrOr�rOrNruru?s��!�@�6�@�d�@rOruc�D��eZdZdZd	dedeef�fd�
Zdddefd�Z	�xZ
S)
�MofNCompleteColumnaHRenders completed count/total, e.g. '  10/1000'.

    Best for bounded tasks with int quantities.

    Space pads the completed count so that progress length does not change as task progresses
    past powers of 10.

    Args:
        separator (str, optional): Text to separate completed and total values. Defaults to "/".
    �	separatorr�c�4��||_t�|�	|��yr)ryrJrK)rLryr�rMs   �rNrKzMofNCompleteColumn.__init__Ts���"���
���l��3rOr�rrPc���t|j�}|j�t|j�nd}tt	|��}t||�d��|j�|��d��S)zShow completed/total.�?rf�progress.downloadrJ)r�rIryr�r�r;ry)rLr�rIry�total_widths     rNrzMofNCompleteColumn.renderXsc������'�	�#'�:�:�#9��D�J�J��s���#�e�*�o����+��a��(����(8���@�%�
�	
rO)�/N)rjrkrlrmr�r r9rKr;rrprqs@rNrxrxHs3���	�4�#�4�8�F�;K�4�
�6�
�d�
rOrxc�J��eZdZdZ	d
dedeeddf�fd�
Zdddefd	�Z	�xZ
S)r�z�Renders file size downloaded and total, e.g. '0.5/2.3 GB'.

    Args:
        binary_units (bool, optional): Use binary units, KiB, MiB etc. Defaults to False.
    N�binary_unitsr�rPc�4��||_t�|�	|��yr)r�rJrK)rLr�r�rMs   �rNrKzDownloadColumn.__init__js���)���
���l��3rOr�rc��t|j�}|j�t|j�n|}|jrt	j
|gd�d�\}}nt	j
|gd�d�\}}|dk(rdnd}||z}|d|�d��}|j�#t|j�}	|	|z}
|
d|�d��}nd	}|�d
|�d|��}t
|d�
�}
|
S)z.Calculate common unit for completed and total.)	r��KiB�MiB�GiB�TiB�PiB�EiB�ZiB�YiBi)	r��kB�MB�GB�TB�PB�EB�ZB�YBrTr,rz,.�fr|rr*r}rJ)r�rIryr�r-rUr;)rLr�rI� unit_and_suffix_calculation_baserWrX�	precision�completed_ratio�
completed_strry�total_ratio�	total_str�download_status�
download_texts              rNrzDownloadColumn.renderps�������'�	� $�z�z�5�C��
�
�O�9�	)����#�8�8�0�Q���L�D�&�$�8�8�0�I���L�D�&�
���A��	�#�d�*��*�2�i�[��/�:�
��:�:�!���
�
�O�E��$�,�K�&�r�)��A�o�6�I��I�*�O�1�Y�K�q���A���_�4G�H�
��rO)FN)rjrkrlrmr�r r9rKr;rrprqs@rNr�r�csD����LP�4� �4�8@��8H�4�	
�4�!�6�!�d�!rOr�c� �eZdZdZdddefd�Zy)�TransferSpeedColumnz&Renders human readable transfer speed.r�rrPc��|jxs|j}|�
tdd��Stjt|��}t|�d�d��S)zShow data transfer speed.r|zprogress.data.speedrJz/s)r\rr;r-rqr�)rLr�rrYs    rNrzTransferSpeedColumn.render�sR���#�#�1�t�z�z���=���#8�9�9��%�%�c�%�j�1�
��z�l�"�%�-B�C�CrONrOr�rOrNr�r��s��0�D�6�D�d�DrOr�c�(�eZdZUdZeed<	eed<y)�ProgressSamplez$Sample of progress for a given time.r
rIN)rjrkrlrmrnrr�rOrNr�r��s��.������$rOr�c��eZdZUdZeed<	eed<	eeed<	eed<	e	ed<	dZ
eeed<	d	Zeed
<	e
e��Zeeefed<	e
dd
d
��Zeeed<	e
dd
d
��Zeeed<	dZeeed<	e
d�d
d
��Zeeed<e
d
e��Zeed<	defd�Zedefd��Zedeefd��Zedeefd��Zedefd��Zedefd��Z edeefd��Z!edeefd��Z"d!d �Z#y)"rz�Information regarding a progress task.

    This object should be considered read-only outside of the :class:`~Progress` class.

    rrxryrI�	_get_timeNrLT�visible)�default_factory�fieldsF)�default�init�repr�
start_time�	stop_timer\c��td��S)NrT)�maxlenrr�rOrN�<lambda>z
Task.<lambda>�s	���T� 2rO)r�r�r��	_progress)r�r��_lockrPc�"�|j�S)z(float: Get the current time, in seconds.)r�r^s rNr}z
Task.get_time�s���~�~��rOc��|jduS)z#bool: Check if the task as started.N)r�r^s rNrCzTask.started�s�����d�*�*rOc�N�|j�y|j|jz
S)zPOptional[float]: Get the number of steps remaining, if a non-None total was set.N�ryrIr^s rN�	remainingzTask.remaining�s$���:�:����z�z�D�N�N�*�*rOc��|j�y|j�|j|jz
S|j�|jz
S)z]Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started.N)r�r�r}r^s rNrMzTask.elapsed�sC���?�?�"���>�>�%��>�>�D�O�O�3�3��}�}�����0�0rOc��|jduS)zCheck if the task has finished.N)rLr^s rNr%z
Task.finished�s���!�!��-�-rOc��|jsy|j|jzdz}tdtd|��}|S)zOfloat: Get progress of task as a percentage. If a None total was set, returns 0��Y@)ryrI�minrB)rLrIs  rN�
percentagezTask.percentage�s>���z�z���^�^�d�j�j�0�E�9�	���s�3�	�2�3�	��rOc�J�|j�y|j5|j}|s
	ddd�y|dj|djz
}|dk(r
	ddd�yt	|�}t|�t
d�|D��}||z}|cddd�S#1swYyxYw)z=Optional[float]: Get the estimated speed in steps per second.Nr�rc3�4K�|]}|j���y�wr[r�)�.0�samples  rN�	<genexpr>zTask.speed.<locals>.<genexpr>s����!O��v�&�"2�"2����)r�r�r�r
�iterr�r�)rLrB�
total_time�
iter_progress�total_completedrs      rNrz
Task.speeds����?�?�"��
�Z�Z��~�~�H����Z�"�"��/�/�(�1�+�2G�2G�G�J��Q���
�Z�!��N�M����!�!O��!O�O�O�#�j�0�E���Z�Z�s�B�%B�!.B�B"c�x�|jry|j}|sy|j}|�yt||z�}|S)zJOptional[float]: Get estimated time to completion, or ``None`` if no data.r�N)r%rr�r)rLrr��estimates    rNrgzTask.time_remainingsC���=�=���
�
�����N�N�	�����	�E�)�*���rOc�T�|jj�d|_d|_y)zReset progress.N)r��clearrLr\r^s rN�_resetzTask._reset s"��������!���"��rOri)$rjrkrlrmr=rr�r rn�GetTimeCallablerLr�r�r�dictr�rrr�r�r\r�rr�rr�r}r�rCr�rMr%r�rrgr�r�rOrNrr�s����	�J�G���'��E�?��>���*���+�%)�M�8�E�?�)�(��G�T��J�"�4�8�F�D��c��N�8�?�"'��5�u�"M�J����M�N�!&�t�%�e�!L�I�x���L�N�&*�N�H�U�O�*�>�',�2��U�(�I�u�^�$���e�U�;�E�5�;�� �%� ��+��+��+��+�8�E�?�+��+��1��%��1��1��.�$�.��.���E������x������"��������#rOrc��eZdZdZddddddddddd�
deeefd	eed
e	de
de
d
e	de	de	deede	de	ddfd�Ze
deedffd��Zedefd��Zedeefd��Zedeefd��Zede	fd��ZdOd�ZdOd�Zdefd�Zdeeedeed eeddfd!�Z					dPd#ee e!e"e!fd$ee
d%e#d&eed'ed(e
de e!fd)�Z$	dQdd*d+�d,e%d$ee#d&eed'ede%f
d-�Z&e'jP				dRddd*d.�d,eed/e)fd0e*d1d2e#d3eed4eed5eed$ee#d&eed'ede%fd6��Z+e'jP				dRddd*d.�d,eed/e)fd0ee*d7e*d8fd2e#d3eed4eed5eed$ee#d&eed'ede,fd9��Z+					dSddd*d.�d,eed/e)fd0ee*d1e*d8e*d7fd2e#d3eed4eed5eed$ee#d&eed'edee%e,ffd:�Z+d&eddfd;�Z-d&eddfd<�Z.ddddddd=�d&ed$ee
d%ee
d>ee
d'eed?ee	d@e	dAe/ddfdB�Z0ddd"dddC�d&edDe	d$ee
d%e#d?ee	d'eedAe/ddfdE�Z1dTd&ed>e
ddfdF�Z2dOdG�Z3de4fdH�Z5de e4fdI�Z6dJe ede7fdK�Z8de4fdL�Z9				dUd'edDe	d$ee
d%e#d?e	dAe/defdM�Z:d&eddfdN�Z;y)VrCa�Renders an auto-updating progress bar(s).

    Args:
        console (Console, optional): Optional Console instance. Defaults to an internal Console instance writing to stdout.
        auto_refresh (bool, optional): Enable auto refresh. If disabled, you will need to call `refresh()`.
        refresh_per_second (Optional[float], optional): Number of times per second to refresh the progress information or None to use default (10). Defaults to None.
        speed_estimate_period: (float, optional): Period (in seconds) used to calculate the speed estimate. Defaults to 30.
        transient: (bool, optional): Clear the progress on exit. Defaults to False.
        redirect_stdout: (bool, optional): Enable redirection of stdout, so ``print`` may be used. Defaults to True.
        redirect_stderr: (bool, optional): Enable redirection of stderr. Defaults to True.
        get_time: (Callable, optional): A callable that gets the current time, or None to use Console.get_time. Defaults to None.
        disable (bool, optional): Disable progress display. Defaults to False
        expand (bool, optional): Expand tasks table to fit width. Defaults to False.
    NTrrg>@F)
r{rzr~�speed_estimate_periodr|�redirect_stdout�redirect_stderrr}r��expandr�r{rzr~r�r|r�r�r}r�r�rPc
	���|dkDsJd��t�|_|xs|j�|_||_|	|_|
|_i|_td�|_	t|xs
t�||||||j��|_
|xs|jj|_|jj |_|jj"|_y)Nrzrefresh_per_second must be > 0)r{rzr~r|r�r��get_renderable)rr��get_default_columnsr�r�r�r��_tasksr=�_task_indexr5r.r�rUr{r}�print�log)rLr{rzr~r�r|r�r�r}r�r�r�s            rNrKzProgress.__init__7s���"�A�%�G�'G�G�%��W��
��<�$�":�":�"<���%:��"�������*,���#)�!�9�����,�{�}�%�1��+�+��.�.�
��	�!�9�D�L�L�$9�$9��
��\�\�'�'��
��<�<�#�#��rO.c�P�td�t�t�t�fS)a�Get the default columns used for a new Progress instance:
           - a text column for the description (TextColumn)
           - the bar itself (BarColumn)
           - a text column showing completion percentage (TextColumn)
           - an estimated-time-remaining column (TimeRemainingColumn)
        If the Progress instance is created without passing a columns argument,
        the default columns defined here will be used.

        You can also create a Progress instance using custom columns before
        and/or after the defaults, as in this example:

            progress = Progress(
                SpinnerColumn(),
                *Progress.get_default_columns(),
                "Elapsed:",
                TimeElapsedColumn(),
            )

        This code shows the creation of a Progress display, containing
        a spinner to the left, the default columns, and a labeled elapsed
        time column.
        r�)r�r�r�r�)rVs rNr�zProgress.get_default_columns[s(��2
�A�B��K�� ��!�	
�	
rOc�.�|jjSr[)rUr{r^s rNr{zProgress.consolezs���y�y� � � rOc��|j5t|jj��cddd�S#1swYyxYw)zGet a list of Task instances.N)r��listr��valuesr^s rN�taskszProgress.tasks~s*���Z�Z�����*�*�,�-��Z�Z��	�#:�Ac��|j5t|jj��cddd�S#1swYyxYw)zA list of task IDs.N)r�r�r��keysr^s rN�task_idszProgress.task_ids�s*���Z�Z�����(�(�*�+��Z�Z�r�c���|j5|js
	ddd�ytd�|jj�D��cddd�S#1swYyxYw)z'Check if all tasks have been completed.NTc3�4K�|]}|j���y�wr[)r%)r�r�s  rNr�z$Progress.finished.<locals>.<genexpr>�s����F�1E��t�}�}�1E�r�)r�r��allr�r^s rNr%zProgress.finished�sC���Z�Z��;�;���Z��F����1C�1C�1E�F�F��Z�Z�s�A�)A�A c�V�|js|jjd��yy)zStart the progress display.T)rRN)r�rUr]r^s rNr]zProgress.start�s ���|�|��I�I�O�O�D�O�)�rOc���|jj�|jjs2|jjs|jj�yyy)zStop the progress display.N)rUr�r{�is_interactive�
is_jupyterr�r^s rNr�z
Progress.stop�sB���	�	�����|�|�*�*�4�<�<�3J�3J��L�L��� �4K�*rOc�&�|j�|Sr[r\r^s rNr_zProgress.__enter__�r`rOrarbrcc�$�|j�yr[)r�rgs    rNrhzProgress.__exit__�s
��	
�	�	�rOrrwryrIrDrxrEc#�K�|�tt|��xsd}|�|j|||��}n|j|||��|jj
r8t
|||�5}|D]}|��|xjdz
c_�	ddd�y|j}	|j}
|D]}|��|	|d�|
��y#1swYyxYw�w)a�Track progress by iterating over a sequence.

        Args:
            sequence (Sequence[ProgressType]): A sequence of values you want to iterate over and track progress.
            total: (float, optional): Total number of steps. Default is len(sequence).
            completed (int, optional): Number of steps completed so far. Defaults to 0.
            task_id: (TaskID): Task to track. Default is new task.
            description: (str, optional): Description of task, if new task is created.
            update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.

        Returns:
            Iterable[ProgressType]: An iterable of values taken from the provided sequence.
        Nr�r,)
rnr�add_taskrWrUrzrArIrSrR)rLrwryrIrDrxrE�track_thread�valuerSrRs           rNr�zProgress.track�s�����,�=��+�h�/�0�8�D�E��?��m�m�K�u�	�m�R�G��K�K��u�	�K�B��9�9�!�!��d�G�]�;�|�%�E��K� �*�*�a�/�*�&�<�;�
�l�l�G��l�l�G�!�������#��	�"�<�;�s�A)C�+!C
�
=C�
C�Cr�)rDrxr�c��d}|�|}n0|�.|j5|j|j}ddd�|�td��|�|j	||��}n|j||��t
|||d��S#1swY�NxYw)ajTrack progress file reading from a binary file.

        Args:
            file (BinaryIO): A file-like object opened in binary mode.
            total (int, optional): Total number of bytes to read. This must be provided unless a task with a total is also given.
            task_id (TaskID): Task to track. Default is new task.
            description (str, optional): Description of task, if new task is created.

        Returns:
            BinaryIO: A readable file-like object in binary mode.

        Raises:
            ValueError: When no total value can be extracted from the arguments or the task.
        Nz?unable to get the total number of bytes, please specify 'total'�ryF�r�)r�r�ry�
ValueErrorr�rWr�)rLr�ryrDrx�total_bytess      rNr�zProgress.wrap_file�s���.(,�����K�
�
 ����"�k�k�'�2�8�8������Q��
�
�?��m�m�K�{�m�C�G��K�K��{�K�3��t�T�7��?�?���s�A=�=B)ryrDrxr�r�r�r�r�r�r�c��yr[r��
rLr�r�r�r�r�r�ryrDrxs
          rNr�z
Progress.open����	
rOr�r�c��yr[r�r�s
          rNr�z
Progress.openr�rOc��djt|d���}
|
dvrtd|����|dk(}|
dk(r"|dk(rtjdt
�d	}n|
d
vr|dk(rtd��|dk(rd	}|�t
|�j}|�|j|	|�
�}n|j||�
�tj|d|��}t|||d��}
|dvrtj|
||||��S|
S)a#Track progress while reading from a binary file.

        Args:
            path (Union[str, PathLike[str]]): The path to the file to read.
            mode (str): The mode to use to open the file. Only supports "r", "rb" or "rt".
            buffering (int): The buffering strategy to use, see :func:`io.open`.
            encoding (str, optional): The encoding to use when reading in text mode, see :func:`io.open`.
            errors (str, optional): The error handling strategy for decoding errors, see :func:`io.open`.
            newline (str, optional): The strategy for handling newlines in text mode, see :func:`io.open`.
            total (int, optional): Total number of bytes to read. If none given, os.stat(path).st_size is used.
            task_id (TaskID): Task to track. Default is new task.
            description (str, optional): Description of task, if new task is created.

        Returns:
            BinaryIO: A readable file-like object in binary mode.

        Raises:
            ValueError: When an invalid mode is given.
        rF)�reverse)�brr�r�z
invalid mode r,r�zaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedr�)r�r�rzcan't have unbuffered text I/Or�r�)r�Tr�)r�r�)r�r�r��line_buffering)rf�sortedr��warnings�warn�RuntimeWarningr�st_sizer�rW�ior�r��
TextIOWrapper)rLr�r�r�r�r�r�ryrDrx�_moder�r�r�s              rNr�z
Progress.opens#��B����t�U�3�4���)�)��}�T�H�5�6�6�#�a����D�=�Y�!�^��M�M�s��
��I�
�k�
!��A�~� �!A�B�B��a���	��=���J�&�&�E��?��m�m�K�u�m�=�G��K�K��u�K�-�����t�y�9�����w�T�B���;���#�#��!���-��
��
rOc��|j5|j|}|j�|j�|_ddd�y#1swYyxYw)z�Start a task.

        Starts a task (used when calculating elapsed time). You may need to call this manually,
        if you called ``add_task`` with ``start=False``.

        Args:
            task_id (TaskID): ID of task.
        N)r�r�r�r})rLrDr�s   rN�
start_taskzProgress.start_taskks:���Z�Z��;�;�w�'�D����&�"&�-�-�/����Z�Z�s�1A�Ac��|j5|j|}|j�}|j�||_||_ddd�y#1swYyxYw)z�Stop a task.

        This will freeze the elapsed time on the task.

        Args:
            task_id (TaskID): ID of task.
        N)r�r�r}r�r�)rLrDr�r	s    rN�	stop_taskzProgress.stop_taskysF���Z�Z��;�;�w�'�D��=�=�?�L����&�".���)�D�N��Z�Z�s�:A�A)ryrIrSrxr�rRrSr�rRr�c�<�|j5|j|}	|	j}
|�&||	jk7r||	_|	j	�|�|	xj|z
c_|�||	_|�||	_|�||	_|	jj|�|	j|
z
}|j�}||jz
}
|	j}|j}|r.|dj|
kr|�|r|dj|
kr�|dkDr|jt||��|	j�6|	j|	jk\r|	j �|	j"|	_ddd�|r|j%�yy#1swY�xYw)a�Update information associated with a task.

        Args:
            task_id (TaskID): Task id (returned by add_task).
            total (float, optional): Updates task.total if not None.
            completed (float, optional): Updates task.completed if not None.
            advance (float, optional): Add a value to task.completed if not None.
            description (str, optional): Change task description if not None.
            visible (bool, optional): Set visible flag if not None.
            refresh (bool): Force a refresh of progress information. Default is False.
            **fields (Any): Additional data fields required for rendering.
        Nr)r�r�rIryr�rxr�r�rWr}r�r��popleftr
�appendr�rLrMrR)rLrDryrIrSrxr�rRr�r��completed_start�update_completedr	�old_sample_timer�rs                rNrWzProgress.update�sq��0�Z�Z��;�;�w�'�D�"�n�n�O�� �U�d�j�j�%8�"��
����
��"����'�)���$�!*����&�#.�� ��"�&����K�K���v�&�#�~�~��?���=�=�?�L�*�T�-G�-G�G�O����I��'�'�G��	�!�� 6� 6�� H��	��	�!�� 6� 6�� H��!�#�� � ���>N�!O�P��
�
�&��N�N�d�j�j�0��&�&�.�%)�\�\��"�A�D��L�L�N��E�Z�s�DF�A"F�F)r]ryrIr�rxr]c�>�|j�}|j5|j|}	|	j�|r|nd|	_|�||	_||	_|�||	_|r||	_|�||	_	d|	_
ddd�|j�y#1swY�xYw)a�Reset a task so completed is 0 and the clock is reset.

        Args:
            task_id (TaskID): ID of task.
            start (bool, optional): Start the task after reset. Defaults to True.
            total (float, optional): New total steps in task, or None to use current total. Defaults to None.
            completed (int, optional): Number of steps completed. Defaults to 0.
            visible (bool, optional): Enable display of the task. Defaults to True.
            description (str, optional): Change task description if not None. Defaults to None.
            **fields (str): Additional data fields required for rendering.
        N)r}r�r�r�r�ryrIr�r�rxrLrR)
rLrDr]ryrIr�rxr�r	r�s
          rN�resetzProgress.reset�s���,�}�}���
�Z�Z��;�;�w�'�D��K�K�M�.3�l��D�O�� �"��
�&�D�N��"�&����$����&�#.�� �!%�D���	
�����Z�s�AB�Bc��|j�}|j5|j|}|j}|xj|z
c_|j|z
}||jz
}|j
}|j}	|r.|dj|kr|	�|r|dj|kr�t|�dkDr|	�t|�dkDr�|jt||��|j�G|j|jk\r.|j�"|j|_|j|_ddd�y#1swYyxYw)z�Advance task by a number of steps.

        Args:
            task_id (TaskID): ID of task.
            advance (float): Number of steps to advance. Default is 1.
        rrTN)r}r�r�rIr�r�rr
r�rr�ryrLrMrr\)
rLrDrSr	r�r
rrr�rs
          rNrSzProgress.advance�s���}�}���
�Z�Z��;�;�w�'�D�"�n�n�O��N�N�g�%�N�#�~�~��?��*�T�-G�-G�G�O����I��'�'�G��	�!�� 6� 6�� H��	��	�!�� 6� 6�� H��i�.�4�'��	��i�.�4�'����^�L�:J�K�L��
�
�&��N�N�d�j�j�0��&�&�.�%)�\�\��"�&*�j�j��#�)�Z�Z�s�BE�4#E�A.E�Ec��|js2|jjr|jj�yyy)z*Refresh (render) the progress information.N)r�rUrVrRr^s rNrRzProgress.refresh
s,���|�|��	�	� 4� 4��I�I����!5�|rOc�2�t|j��}|S)z*Get a renderable for the progress display.)r0�get_renderables)rLrs  rNr�zProgress.get_renderables���D�0�0�2�3�
��rOc#�JK�|j|j�}|��y�w)z5Get a number of renderables for the progress display.N)�make_tasks_tabler�)rL�tables  rNrzProgress.get_renderabless�����%�%�d�j�j�1����s�!#r�c����d�|jD�}tj|d|jd��}|D]1��js�|j
�fd�|jD���3|S)z�Get a table to render the Progress display.

        Args:
            tasks (Iterable[Task]): An iterable of Task instances, one per row of the table.

        Returns:
            Table: A table instance.
        c3�K�|]>}t|t�rtd��n|j�j	����@y�w)Tr1N)rr�r9r�copy)r��_columns  rNr�z,Progress.make_tasks_table.<locals>.<genexpr>"sG����
�(���g�s�+��t�$��-�-�/�4�4�6�7�(�s�AA)rr,)�paddingr�c3�r�K�|].}t|t�r|j���n|�����0y�w)r5N)rr�r6)r��columnr�s  �rNr�z,Progress.make_tasks_table.<locals>.<genexpr>/s@������'3�F� *�&�#�6�#�M�M�t�M�4�!'���.�'3�s�47)r�r:�gridr�r��add_row)rLr��
table_columnsrr�s    @rNrzProgress.make_tasks_tablesi���
� �<�<�

�
��
�
�M�6�$�+�+�N���D��|�|���
�
��'+�l�l�
�	���rOc�f�|j5|j�cddd�S#1swYyxYw)z+Makes the Progress class itself renderable.N)r�r�r^s rN�__rich__zProgress.__rich__:s��
�Z�Z��&�&�(��Z�Z�s�'�0c��|j5t|j||||||j|j��}||j|j<|r|j|j�|j}t
t|j�dz�|_ddd�|j�S#1swY�xYw)aAdd a new 'task' to the Progress display.

        Args:
            description (str): A description of the task.
            start (bool, optional): Start the task immediately (to calculate elapsed time). If set to False,
                you will need to call `start` manually. Defaults to True.
            total (float, optional): Number of total steps in the progress if known.
                Set to None to render a pulsing animation. Defaults to 100.
            completed (int, optional): Number of steps completed so far. Defaults to 0.
            visible (bool, optional): Enable display of the task. Defaults to True.
            **fields (str): Additional data fields required for rendering.

        Returns:
            TaskID: An ID you can use when calling `update`.
        )r�r�r�r�r,N)	r�rr�r}r�rr=r�rR)	rLrxr]ryrIr�r�r��new_task_indexs	         rNr�zProgress.add_task?s���0�Z�Z��� � �������-�-��j�j�	�D�-1�D�K�K��(�(�)������ 0� 0�1�!�-�-�N�%�c�$�*:�*:�&;�a�&?�@�D��� 	
������#�Z�s�BC�C
c�`�|j5|j|=ddd�y#1swYyxYw)z]Delete a task if it exists.

        Args:
            task_id (TaskID): A task ID.

        N)r�r�)rLrDs  rN�remove_taskzProgress.remove_taskjs!���Z�Z����G�$��Z�Z�s�$�-ri)NrN�
Working...皙�����?r[�r�NNN�r�r�NNN)r,)Tr�rT)<rjrkrlrmr&r�r�r r/r�rnr�rKr]r#r�r�r{rrr�r=r�r%r]r�r+r_r$rorrhrr>r!r�r�rr��typing�overloadr�r)r�r"rr	rrWrrSrRr2r�rr:rr$r�r(r�rOrNrCrC's���
�$&*�!�$&�'+�� $� $�.2���"$���^�+�,�"$��'�"�"$��	"$�
"�"$� %�
"$��"$��"$��"$��?�+�"$��"$��"$�
�"$�H�
�E�.�#�*=�$>�
��
�<�!��!��!��.�t�D�z�.��.�
�,�$�v�,�,��,�
�G�$�G��G�*�
!��4����4�
�.�/���-�(����'�	�

��"&��$(�'�"�)����.���0F�F�G�)����)��	)�
�&�!�)��
)��)�
�,�	�)�\ $�(@�
%)�'�
(@��(@���}�(@�
�&�!�(@��
(@�
�(@�T�_�_�
�"&� $�!%�

� $�$(�'�

��C��%�/�0�

��d�m�

��	

�
�3�-�

���
�


��#��

���}�

��&�!�

��

�
�

��

��_�_�
�"&� $�!%�

� $�$(�'�

��C��%�/�0�

��G�C�L�'�$�-�/�0�

��	

�
�3�-�

���
�


��#��

���}�

��&�!�

��

�
�

��

�$CF��"&� $�!%�K� $�$(�'�K��C��%�/�0�K��G�D�M�7�4�=�'�#�,�>�?�K��	K�
�3�-�K���
�
K��#��K���}�K��&�!�K��K�
�x���	 �K�Z2�&�2�T�2�
*��
*�D�
*�&"&�%)�#'�%)�"&��;��;����	;�
�E�?�;��%��
;��c�]�;��$��;��;��;�
�;�B�!%��"&�%)�%��%��	%�
���%��
%��$��%��c�]�%��%�
�%�N1�v�1��1�d�1�< �
���
��.�!9��
�h�t�n����B)�.�)��!&���
)��)��)����	)�
�)��
)��)�
�)�V%�6�%�d�%rOrC�__main__)�Panel)�Rule)�Syntax)r:a~def loop_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
    """Iterate and generate a tuple with a flag for last value."""
    iter_values = iter(values)
    try:
        previous_value = next(iter_values)
    except StopIteration:
        return
    for value in iter_values:
        yield False, previous_value
        previous_value = value
    yield True, previous_value�python)�line_numbers�foo�bar�baz�1�2�3z:Text may be printed while the progress bars are rendering.z(In fact, [i]any[/i] renderable will workzSuch as [magenta]tables[/]...zPretty printed structures...�examplezPretty printed)�typer&z	Syntax...zGive it a try!)�cycle)�record)r{r|z[red]DownloadingrTr�z[green]Processingz[yellow]Thinkingr_r�g333333�?g{�G�z�?�d)r)NrTNFNrrrsrtrurvr*FTr+r,)�r�sysr-r��abcrr�collectionsr�dataclassesrr�datetimer	r
r�mathrr
�operatorr�osrr�	threadingrrr�typesrrrrrrrrrrrrr r!r"r#r$r%r&�version_infor)�typing_extensionsr+rr-r.r{r/r0r1r2r/r3�jupyterr4rUr5�progress_barr6rr7rr8rr9r:r&r;r<r�r=r>rnr�r?rAr�r�r�r�r�r�r.r�r�r�rrr�r�rFr�r�rnrurxr�r�r�rrCrj�random�time�panelr0�ruler1�syntaxr2r!�progress_renderables�	itertoolsr=�examplesr�rBr��task1�task2�task3r%rW�sleep�randintr�r�r�rOrN�<module>r[sv	��	�
�
��#��(��.��� ��*�*�������*���v���)����w���&�#�B�B�$�!��%��� � �	��3�	���~�&���2�u�9�%���V�^�^�D�&�(�+��%�6�%�T$�!���!%��.2� "�!� .� .�(����!I
��H�\�*�H�\�,B�B�C�I
��I
��E�?�I
��	I
�
�I
��g�
�
I
��I
��x��E�	�*�+�I
��I
��I
��I
��I
��I
��I
��I
� �!I
�"�l��#I
�Xd1�i��d1�N8�>�"�%�w�r�{�8�2$��!%��.2� "�!� .� .�(��>*�
�>*��>*��	>*�
�>*��g�
�
>*��>*��x��E�	�*�+�>*��>*��>*��>*��>*��>*��>*��H��>*�B����"� �!�
	� �#��!%��.2� "�!� .� .�(��'	�
��_�e�+�
,�	�
���
�w�s�|�+�
,�	��	��s�m�		�

�S�M�	��c�]�
	��C�=�	��	��	��g�
�	��	��x��E�	�*�+�	��	��	� �!	�"�#	�$�%	�&�'	�(�F��)	��	�0����"� �!�
	� �#��!%��.2� "�!� .� .�(��'	�
��_�e�+�
,�	�
�$�-�	��	��s�m�		�

�S�M�	��c�]�
	��C�=�	��	��	��g�
�	��	��x��E�	�*�+�	��	��	� �!	�"�#	�$�%	�&�'	�(�H��)	��	�4?B��"� �!�
S*� �#��!%��.2� "�!� .� .�(��'S*�
��_�e�+�
,�S*�
���
�w�t�}�g�c�l�:�
;�S*��S*��s�m�	S*�

�S�M�S*��c�]�
S*��C�=�S*��S*��S*��g�
�S*��S*��x��E�	�*�+�S*��S*��S*� �!S*�"�#S*�$�%S*�&�'S*�(�>�(�#�^�F�%;�;�<�)S*�l'1�S�'1�T�~��"/�N�/�d���<'
��'
�T	:��	:�E��E�P-,�.�-,�`:�^�:�@�.�@�
��
�6.�^�.�b	D�.�	D�%�Z�%��z#�z#��z#�zK	%�|�K	%�\�z��������
�
	"�	���F� 
�%���&�E�	�M�M�#�s�C� �	E�
�8�9�'�
�&��$4�5����
��
�� ��)�*�H��T�"�G�	���
�	�	%�	%�	'�
�	��
���
�
��!�!�"4�D�!�A���!�!�"5�T�!�B���!�!�"4�D�!�A���#�#��O�O�E�3�O�/��O�O�E�3�O�/��D�J�J�t���v�~�~�a��%��)����T�(�^�,��#�#�
�
�]�\
�
�s
�B>U'�'U0