U
    祡c                     @   s  d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZ d dlmZ d dl mZmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZmZmZ d dlmZ d dlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ ej0dkr&d dlm1Z1 nd dl2m1Z1 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZF ddlGmHZHmIZI ddlJmKZKmLZL e(deMZNe.dZOe g ePf ZQe.de+eZRG dd deZSde/e*eO e%eO f eTe)eP eUe)e7 eUe)e g ePf  ePeFeFeFeFePeUeUe%eO d)d*d+ZVG d,d- d-eeZWG d.d/ d/e!eR e$eR ZXd0d!dd"dd#d$d%d&d'd"d1eeMeTeUe)e7 eUe)e g ePf  ePeFeFeFeFeUe!e d2d3d4ZYejZddd0d!dd"dd#d$d%d&d'd"d6e/eTd7e[f e/e1d8 e1d9 f eMe)eT e)eT e)eT e)eM eTeUe)e7 eUe)e g ePf  ePeFeFeFeFeUe!e+ d:d;d<Z\ejZddd0d!dd"dd#d$d%d&d'd"d6e/eTd7e[f e1d= eMe)eT e)eT e)eT e)eM eTeUe)e7 eUe)e g ePf  ePeFeFeFeFeUe!e d:d>d<Z\ddd0d!dd"dd#d$d%d&d'd"d6e/eTd7e[f e/e1d= e1d8 e1d9 f eMe)eT e)eT e)eT e)eM eTeUe)e7 eUe)e g ePf  ePeFeFeFeFeUe/e!e e!e+ f d:d?d<Z\G d@dA dAeZ]G dBdC dCe]Z^G dDdE dEe]Z_G dFdG dGe]Z`G dHdI dIe]ZaG dJdK dKe]ZbG dLdM dMe`ZcG dNdO dOe]ZdG dPdQ dQe]ZeG dRdS dSe]ZfG dTdU dUe]ZgG dVdW dWe]ZhG dXdY dYe]ZiG dZd[ d[e'ZjeG d\d] d]ZkG d^d_ d_e>Zlemd`krd dlnZnd dloZoddalpmqZq ddblrmsZs ddcltmuZu dddlGmIZI eudedfd!dgZteIdhdidjZGeGvdkdldm dneqdodpeGdqdrdsdtduetesdvg	Zwd dwlxmyZy eyewZze7d!dxZ6ele_ fel{ eb fe6d"dyZ|e|j}dzd{d|Z~e|j}d}d{d|Ze|j}d~dd|Ze|jse|je~dd e|jedd eod end ddk re|eez qW 5 Q R X dS )    N)ABCabstractmethoddeque)Sized)	dataclassfield)	timedelta)	RawIOBaseUnsupportedOperation)ceil)mmap)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   )filesizeget_console)ConsoleGroupJustifyMethodRenderableType)Highlighter)JupyterMixin)Live)ProgressBar)Spinner)	StyleType)ColumnTable)TextTextTypeTaskIDProgressType_Ic                       sj   e Zd ZdZdded fddZddd	d
Zd dddZee	e
  ee
 ee ddddZ  ZS )_TrackThreadz)A thread to periodically update progress.Progressr:   )progresstask_idupdate_periodc                    s.   || _ || _|| _t | _d| _t   d S )Nr   )r?   r@   rA   r   done	completedsuper__init__)selfr?   r@   rA   	__class__ 1/tmp/pip-unpacked-wheel-qkhzhrww/rich/progress.pyrE   B   s    z_TrackThread.__init__Nreturnc                 C   sd   | j }| jj}| j}d}| jj}||sJ| j}||kr ||||  |}q | jj| j | jdd d S )Nr   T)rC   refresh)r@   r?   advancerA   rB   waitrC   update)rF   r@   rN   rA   Zlast_completedrO   rC   rI   rI   rJ   runK   s    z_TrackThread.runc                 C   s   |    | S NstartrF   rI   rI   rJ   	__enter__Y   s    z_TrackThread.__enter__exc_typeexc_valexc_tbrL   c                 C   s   | j   |   d S rR   )rB   setjoinrF   rX   rY   rZ   rI   rI   rJ   __exit__]   s    
z_TrackThread.__exit__)__name__
__module____qualname____doc__floatrE   rQ   rV   r   r#   BaseExceptionr   r^   __classcell__rI   rI   rG   rJ   r=   ?   s   	
r=   
Working...TF
   bar.backbar.completebar.finished	bar.pulse皙?)sequencedescriptiontotalauto_refreshconsole	transientget_timerefresh_per_secondstylecomplete_stylefinished_stylepulse_stylerA   disable
show_speedrL   c              	   c   s~   |rt dgng }|t||	|
|dt|dt f t||||||pHd|d}| |j| |||dE dH  W 5 Q R X dS )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).
        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}ru   rv   rw   rx   )rz   rg   rp   rq   rr   rs   rt   ry   )ro   rn   rA   N)
TextColumnextend	BarColumnTaskProgressColumnTimeRemainingColumnr>   track)rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   rA   ry   rz   columnsr?   rI   rI   rJ   r   g   s:    (
   r   c                   @   s  e Zd ZdZd9edeeddddZd dd	d
Ze	e
e  e	e e	e ddddZedddZedddZeedddZedddZedddZeedddZeedddZedddZedddZedd d!Zd:eed#d$d%Zeeee f d&d'd(Z!d;eed#d)d*Z"d<ee#e d+d,d-Z$ddd.d/Z%d=eeed1d2d3Z&edd4d5Z'e(ed6d7d8Z)dS )>_Readerz9A reader that tracks progress while it's being read from.Tr>   N)handler?   taskclose_handlerL   c                 C   s"   || _ || _|| _|| _d| _d S NF)r   r?   r   r   _closed)rF   r   r?   r   r   rI   rI   rJ   rE      s
    z_Reader.__init__rK   c                 C   s   | j   | S rR   )r   rV   rU   rI   rI   rJ   rV      s    
z_Reader.__enter__rW   c                 C   s   |    d S rR   )closer]   rI   rI   rJ   r^      s    z_Reader.__exit__c                 C   s   | S rR   rI   rU   rI   rI   rJ   __iter__   s    z_Reader.__iter__c                 C   s$   t | j}| jj| jt|d |S NrN   )nextr   r?   rN   r   len)rF   linerI   rI   rJ   __next__   s    
z_Reader.__next__c                 C   s   | j S rR   )r   rU   rI   rI   rJ   closed   s    z_Reader.closedc                 C   s
   | j  S rR   )r   filenorU   rI   rI   rJ   r      s    z_Reader.filenoc                 C   s
   | j  S rR   )r   isattyrU   rI   rI   rJ   r      s    z_Reader.isattyc                 C   s   | j jS rR   )r   moderU   rI   rI   rJ   r      s    z_Reader.modec                 C   s   | j jS rR   )r   namerU   rI   rI   rJ   r      s    z_Reader.namec                 C   s
   | j  S rR   )r   readablerU   rI   rI   rJ   r      s    z_Reader.readablec                 C   s
   | j  S rR   )r   seekablerU   rI   rI   rJ   r      s    z_Reader.seekablec                 C   s   dS r   rI   rU   rI   rI   rJ   writable   s    z_Reader.writable)sizerL   c                 C   s&   | j |}| jj| jt|d |S r   )r   readr?   rN   r   r   )rF   r   blockrI   rI   rJ   r      s    z_Reader.read)bc                 C   s"   | j |}| jj| j|d |S r   )r   readintor?   rN   r   )rF   r   nrI   rI   rJ   r      s    z_Reader.readintoc                 C   s&   | j |}| jj| jt|d |S r   )r   readliner?   rN   r   r   )rF   r   r   rI   rI   rJ   r      s    z_Reader.readline)hintrL   c                 C   s,   | j |}| jj| jttt|d |S r   )r   	readlinesr?   rN   r   summapr   )rF   r   linesrI   rI   rJ   r      s    z_Reader.readlinesc                 C   s   | j r| j  d| _d S )NT)r   r   r   r   rU   rI   rI   rJ   r      s    
z_Reader.closer   )offsetwhencerL   c                 C   s$   | j ||}| jj| j|d |S )NrC   )r   seekr?   rP   r   )rF   r   r   posrI   rI   rJ   r     s    z_Reader.seekc                 C   s
   | j  S rR   )r   tellrU   rI   rI   rJ   r   
  s    z_Reader.tell)srL   c                 C   s   t dd S )Nwrite)r   )rF   r   rI   rI   rJ   r     s    z_Reader.write)T)r   )r   )r   )r   )*r_   r`   ra   rb   r   r:   boolrE   rV   r   r#   rd   r   r^   r   bytesr   propertyr   intr   r   strr   r   r   r   r   r   r%   	bytearray
memoryviewr   r   r   r   r   r   r   r   r   r   rI   rI   rI   rJ   r      sH    
r   c                   @   sT   e Zd ZdZdeddddZeddd	Zeee	  ee	 ee
 dd
ddZdS )_ReadContextzEA utility class to handle a context for both a reader and a progress.r>   N)r?   readerrL   c                 C   s   || _ || _d S rR   )r?   r   )rF   r?   r   rI   rI   rJ   rE     s    z_ReadContext.__init__rK   c                 C   s   | j   | j S rR   )r?   rT   r   rV   rU   rI   rI   rJ   rV     s    
z_ReadContext.__enter__rW   c                 C   s   | j   | j||| d S rR   )r?   stopr   r^   r]   rI   rI   rJ   r^     s    
z_ReadContext.__exit__)r_   r`   ra   rb   r<   rE   rV   r   r#   rd   r   r^   rI   rI   rI   rJ   r     s   
r   
Reading...)rn   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   )filero   rn   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rL   c             	   C   sh   |rt dgng }|t||	|
|dt t f t||||||pDd|d}|j| ||d}t||S )a  Read 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|   rg   r}   )ro   rn   )r~   r   r   DownloadColumnr   r>   	wrap_filer   )r   ro   rn   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   r   r?   r   rI   rI   rJ   r   &  s0    %
r   r   )ro   rn   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   PathLike[str]rtr)r   r   	bufferingencodingerrorsnewlinero   rn   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rL   c                C   s   d S rR   rI   r   r   r   r   r   r   ro   rn   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rI   rI   rJ   openg  s    r   rbc                C   s   d S rR   rI   r   rI   rI   rJ   r     s    c             
   C   sr   |rt dgng }|t||||dt t f t|||	|
||pDd|d}|j| |||||||d}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|   rg   r}   )r   r   r   r   r   ro   rn   )r~   r   r   r   r   r>   r   r   )r   r   r   r   r   r   ro   rn   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   r   r?   r   rI   rI   rJ   r     sB    1

c                   @   sj   e Zd ZU dZdZee ed< dee ddddZ	eddd	Z
d
edddZed
edddZdS )ProgressColumnz3Base class for a widget to use in progress display.Nmax_refresh)table_columnrL   c                 C   s   || _ i | _d | _d S rR   )_table_column_renderable_cacheZ_update_time)rF   r   rI   rI   rJ   rE     s    zProgressColumn.__init__rK   c                 C   s   | j p
t S )z.Get a table column, used to build tasks table.)r   r6   rU   rI   rI   rJ   get_table_column  s    zProgressColumn.get_table_columnTaskr   rL   c                 C   sr   |  }| jdk	rT|jsTz| j|j \}}W n tk
r@   Y nX || j |krT|S | |}||f| j|j< |S )a  Called 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).
        N)rs   r   rC   r   idKeyErrorrender)rF   r   current_time	timestamp
renderablerI   rI   rJ   __call__  s    	
zProgressColumn.__call__c                 C   s   dS )z"Should return a renderable object.NrI   rF   r   rI   rI   rJ   r     s    zProgressColumn.render)N)r_   r`   ra   rb   r   r   rc   __annotations__r6   rE   r   r/   r   r   r   rI   rI   rI   rJ   r     s   
r   c                       sD   e Zd ZdZdddeee d fddZded	d
dZ  Z	S )RenderableColumnzA column to insert an arbitrary column.

    Args:
        renderable (RenderableType, optional): Any renderable. Defaults to empty string.
     Nr   )r   r   c                   s   || _ t j|d d S Nr   )r   rD   rE   )rF   r   r   rG   rI   rJ   rE      s    zRenderableColumn.__init__r   r   c                 C   s   | j S rR   )r   r   rI   rI   rJ   r   &  s    zRenderableColumn.render)r   )
r_   r`   ra   rb   r/   r   r6   rE   r   re   rI   rI   rG   rJ   r     s     r   c                       sb   e Zd ZdZdeee eeee	 d fdd	Z
deee edd
ddZdedddZ  ZS )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 " ".
    dotsprogress.spinner      ? N)spinner_nameru   speedfinished_textr   c                    s<   t |||d| _t|tr$t|n|| _t j|d d S )Nru   r   r   )	r4   spinner
isinstancer   r8   from_markupr   rD   rE   )rF   r   ru   r   r   r   rG   rI   rJ   rE   4  s    zSpinnerColumn.__init__)r   spinner_styler   rL   c                 C   s   t |||d| _dS )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.
        r   N)r4   r   )rF   r   r   r   rI   rI   rJ   set_spinnerD  s    zSpinnerColumn.set_spinnerr   r   c                 C   s    |j r| jn| j| }|S rR   )finishedr   r   r   rs   )rF   r   textrI   rI   rJ   r   S  s
    zSpinnerColumn.render)r   r   r   r   N)r   r   )r_   r`   ra   rb   r   r   r5   rc   r9   r6   rE   r   r/   r   re   rI   rI   rG   rJ   r   *  s,          r   c                	       sL   e Zd ZdZdeeeeee	 ee
 dd fddZd	ed
ddZ  ZS )r~   zA column containing text.noneleftTN)text_formatru   justifymarkuphighlighterr   rL   c                    s:   || _ || _|| _|| _|| _t j|p0tddd d S )NTZno_wrapr   )r   r   ru   r   r   rD   rE   r6   )rF   r   ru   r   r   r   r   rG   rI   rJ   rE   _  s    	zTextColumn.__init__r   r   c                 C   sR   | j j|d}| jr*tj|| j| jd}nt|| j| jd}| jrN| j| |S Nr   )ru   r   )	r   formatr   r8   r   ru   r   r   	highlight)rF   r   _textr   rI   rI   rJ   r   o  s    zTextColumn.render)r   r   TNN)r_   r`   ra   rb   r   r5   r.   r   r   r0   r6   rE   r8   r   re   rI   rI   rG   rJ   r~   \  s         r~   c                	       sL   e Zd ZdZdee eeeeee dd fd	d
Zde	dddZ
  ZS )r   a  Renders 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".
    (   rh   ri   rj   rk   N)	bar_widthru   rv   rw   rx   r   rL   c                    s0   || _ || _|| _|| _|| _t j|d d S r   )r   ru   rv   rw   rx   rD   rE   )rF   r   ru   rv   rw   rx   r   rG   rI   rJ   rE     s    	zBarColumn.__init__r   r   c                 C   s^   t |jdk	rtd|jndtd|j| jdkr2dn
td| j|j | | j| j| j	| j
d	S )z&Gets a progress bar widget for a task.Nr   r)   )	ro   rC   widthZpulseZanimation_timeru   rv   rw   rx   )r3   ro   maxrC   r   startedrs   ru   rv   rw   rx   r   rI   rI   rJ   r     s    
zBarColumn.render)r   rh   ri   rj   rk   N)r_   r`   ra   rb   r   r   r5   r6   rE   r3   r   re   rI   rI   rG   rJ   r   z  s"         r   c                   @   s    e Zd ZdZdedddZdS )TimeElapsedColumnzRenders time elapsed.r   r   c                 C   sD   |j r|jn|j}|dkr&tdddS tt|d}tt|ddS )Show time remaining.N-:--:--progress.elapsedru   )seconds)r   finished_timeelapsedr8   r	   r   r   )rF   r   r  deltarI   rI   rJ   r     s
    zTimeElapsedColumn.renderNr_   r`   ra   rb   r8   r   rI   rI   rI   rJ   r     s   r   c                       sh   e Zd ZdZdeeeeeee	 ee
 edd		 fd
dZeee edddZdedddZ  ZS )r   a  Show 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.
    -[progress.percentage]{task.percentage:>3.0f}%r   r   r   TNF)	r   text_format_no_percentageru   r   r   r   r   rz   rL   c	           	         s(   || _ || _t j||||||d d S )N)r   ru   r   r   r   r   )r	  rz   rD   rE   )	rF   r   r	  ru   r   r   r   r   rz   rG   rI   rJ   rE     s    zTaskProgressColumn.__init__)r   rL   c                 C   sT   |dkrt dddS tt|dddddgd	\}}|| }t |d
| dddS )zRender the speed in iterations per second.

        Args:
            task (Task): A Task object.

        Returns:
            Text: Text object containing the task speed.
        Nr   zprogress.percentager  u   ×10³u   ×10⁶u   ×10⁹u   ×10¹²  z.1fz it/s)r8   r*   pick_unit_and_suffixr   )clsr   unitsuffix
data_speedrI   rI   rJ   render_speed  s    
zTaskProgressColumn.render_speedr   r   c                 C   s   |j d kr"| jr"| |jp|jS |j d kr2| jn| j}|j|d}| jr`t	j
|| j| jd}nt	|| j| jd}| jr| j| |S r   )ro   rz   r  finished_speedr   r	  r   r   r   r8   r   ru   r   r   r   )rF   r   r   r   r   rI   rI   rJ   r     s    zTaskProgressColumn.render)r  r   r   r   TNNF)r_   r`   ra   rb   r   r5   r.   r   r   r0   r6   rE   classmethodrc   r8   r  r   re   rI   rI   rG   rJ   r     s.           r   c                       sD   e Zd ZdZdZdeeee d fddZde	d	d
dZ
  ZS )r   a  Renders 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.
          ?FN)compactelapsed_when_finishedr   c                    s   || _ || _t j|d d S r   )r  r  rD   rE   )rF   r  r  r   rG   rI   rJ   rE     s    zTimeRemainingColumn.__init__r   r   c                 C   s   | j r|jr|j}d}n
|j}d}|jdkr8td|dS |dkrVt| jrLdnd|dS tt|d\}}t|d\}}| jr|s|d	d
|d	}n|dd
|d	d
|d	}t||dS )r   r  zprogress.remainingNr   r  z--:--r   <   Z02d:d)	r  r   r  time_remainingro   r8   r  divmodr   )rF   r   Z	task_timeru   minutesr  hours	formattedrI   rI   rJ   r     s    

zTimeRemainingColumn.render)FFN)r_   r`   ra   rb   r   r   r   r6   rE   r8   r   re   rI   rI   rG   rJ   r     s      
r   c                   @   s    e Zd ZdZdedddZdS )FileSizeColumnzRenders completed filesize.r   r   c                 C   s   t t|j}t|ddS )Show data completed.zprogress.filesizer  )r*   decimalr   rC   r8   rF   r   	data_sizerI   rI   rJ   r   ,  s    zFileSizeColumn.renderNr  rI   rI   rI   rJ   r  )  s   r  c                   @   s    e Zd ZdZdedddZdS )TotalFileSizeColumnzRenders total filesize.r   r   c                 C   s*   |j dk	rtt|j nd}t|ddS )r  Nr   zprogress.filesize.totalr  )ro   r*   r   r   r8   r!  rI   rI   rJ   r   5  s    zTotalFileSizeColumn.renderNr  rI   rI   rI   rJ   r#  2  s   r#  c                       s>   e Zd ZdZdeee d fddZdedd	d
Z	  Z
S )MofNCompleteColumnaH  Renders 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 "/".
    /N)	separatorr   c                    s   || _ t j|d d S r   )r&  rD   rE   )rF   r&  r   rG   rI   rJ   rE   G  s    zMofNCompleteColumn.__init__r   r   c                 C   sP   t |j}|jdk	rt |jnd}tt|}t|| d| j | ddS )zShow completed/total.N?r  progress.downloadr  )r   rC   ro   r   r   r8   r&  )rF   r   rC   ro   Ztotal_widthrI   rI   rJ   r   K  s    
zMofNCompleteColumn.render)r%  N)r_   r`   ra   rb   r   r   r6   rE   r8   r   re   rI   rI   rG   rJ   r$  ;  s   r$  c                       s@   e Zd ZdZdeee dd fddZdedd	d
Z	  Z
S )r   zRenders 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.
    FN)binary_unitsr   rL   c                    s   || _ t j|d d S r   )r)  rD   rE   )rF   r)  r   rG   rI   rJ   rE   ]  s    zDownloadColumn.__init__r   r   c                 C   s   t |j}|jdk	rt |jn|}| jrNt|dddddddd	d
g	d\}}n$t|dddddddddg	d\}}|dkr~dnd}|| }|d| d}|jdk	rt |j}	|	| }
|
d| d}nd}| d| d| }t|dd}|S )z.Calculate common unit for completed and total.Nr   ZKiBZMiBZGiBZTiBZPiBZEiBZZiBZYiBi   ZkBZMBZGBZTBZPBZEBZZBZYBr
  r)   r   z,.fr'  r%  r   r(  r  )r   rC   ro   r)  r*   r  r8   )rF   r   rC   Z unit_and_suffix_calculation_baser  r  Z	precisionZcompleted_ratioZcompleted_strro   Ztotal_ratioZ	total_strZdownload_statusZdownload_textrI   rI   rJ   r   c  s2    



zDownloadColumn.render)FN)r_   r`   ra   rb   r   r   r6   rE   r8   r   re   rI   rI   rG   rJ   r   V  s       r   c                   @   s    e Zd ZdZdedddZdS )TransferSpeedColumnz&Renders human readable transfer speed.r   r   c                 C   s@   |j p
|j}|dkr tdddS tt|}t| dddS )zShow data transfer speed.Nr'  zprogress.data.speedr  z/s)r  r   r8   r*   r   r   )rF   r   r   r  rI   rI   rJ   r     s
    zTransferSpeedColumn.renderNr  rI   rI   rI   rJ   r+    s   r+  c                   @   s"   e Zd ZU dZeed< eed< dS )ProgressSamplez$Sample of progress for a given time.r   rC   N)r_   r`   ra   rb   rc   r   rI   rI   rI   rJ   r,    s   
r,  c                   @   s  e Zd ZU dZeed< eed< ee ed< eed< e	ed< dZ
ee ed< d	Zeed
< eedZeeef ed< eddddZee ed< eddddZee ed< dZee ed< edd dddZee ed< ededZeed< edddZeedddZeee dddZeee ddd Zeedd!d"Zeedd#d$Z eee dd%d&Z!eee dd'd(Z"ddd)d*Z#dS )+r   zInformation regarding a progress task.

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

    r   rn   ro   rC   	_get_timeNr  Tvisible)default_factoryfieldsF)defaultinitrepr
start_time	stop_timer  c                   C   s
   t ddS )Nr
  )maxlenr   rI   rI   rI   rJ   <lambda>      zTask.<lambda>)r/  r2  r3  	_progress)r3  r/  _lockrK   c                 C   s   |   S )z(float: Get the current time, in seconds.)r-  rU   rI   rI   rJ   rs     s    zTask.get_timec                 C   s
   | j dk	S )z#bool: Check if the task as started.N)r4  rU   rI   rI   rJ   r     s    zTask.startedc                 C   s   | j dkrdS | j | j S )zPOptional[float]: Get the number of steps remaining, if a non-None total was set.N)ro   rC   rU   rI   rI   rJ   	remaining  s    
zTask.remainingc                 C   s2   | j dkrdS | jdk	r$| j| j  S |  | j  S )z]Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started.N)r4  r5  rs   rU   rI   rI   rJ   r    s
    

zTask.elapsedc                 C   s
   | j dk	S )zCheck if the task has finished.N)r  rU   rI   rI   rJ   r     s    zTask.finishedc                 C   s.   | j s
dS | j| j  d }tdtd|}|S )zOfloat: Get progress of task as a percentage. If a None total was set, returns 0              Y@)ro   rC   minr   )rF   rC   rI   rI   rJ   
percentage  s
    zTask.percentagec              
   C   s   | j dkrdS | j~ | j}|s.W 5 Q R  dS |d j|d j }|dkrXW 5 Q R  dS t|}t| tdd |D }|| }|W  5 Q R  S Q R X dS )z=Optional[float]: Get the estimated speed in steps per second.Nr   r   c                 s   s   | ]}|j V  qd S rR   r   ).0samplerI   rI   rJ   	<genexpr>  s     zTask.speed.<locals>.<genexpr>)r4  r:  r9  r   iterr   r   )rF   r?   Z
total_timeZiter_progressZtotal_completedr   rI   rI   rJ   r     s    
z
Task.speedc                 C   s:   | j r
dS | j}|sdS | j}|dkr*dS t|| }|S )zJOptional[float]: Get estimated time to completion, or ``None`` if no data.r<  N)r   r   r;  r   )rF   r   r;  ZestimaterI   rI   rJ   r    s    zTask.time_remainingc                 C   s   | j   d| _d| _dS )zReset progress.N)r9  clearr  r  rU   rI   rI   rJ   _reset  s    
zTask._reset)$r_   r`   ra   rb   r:   r   r   r   rc   GetTimeCallabler  r.  r   r   dictr0  r   r   r4  r5  r  r9  r   r,  r   r:  rs   r   r   r;  r  r   r?  r   r  rE  rI   rI   rI   rJ   r     sD   
  r   c                   @   s  e Zd ZdZddddddddddd
eeef ee e	e
e
e	e	e	ee e	e	ddd	d
Zeeedf dddZeedddZeee dddZeee dddZee	dddZddddZddddZd dddZeee  ee ee ddddZdXeee  e!e  f ee
 ee ee
ee  d"d#d$Z"dYdd%d&e#ee$ ee ee#d'd(d)Z%e&j'dZddd%d+eed,e(f e)d- e$ee ee ee ee$ ee ee#d.
d/d0Z*e&j'd[ddd%d+eed,e(f ee)d1 e)d2 f e$ee ee ee ee$ ee ee+d.
d3d0Z*d\ddd%d+eed,e(f ee)d- e)d2 e)d1 f e$ee ee ee ee$ ee eee#e+f d.
d4d0Z*edd5d6d7Z,edd5d8d9Z-ddddddd:eee
 ee
 ee
 ee ee	 e	e.dd;	d<d=Z/ddd>ddd?ee	ee
 e$ee	 ee e.dd@dAdBZ0d]ee
ddDdEdFZ1dddGdHZ2e3ddIdJZ4ee3 ddKdLZ5ee e6dMdNdOZ7e3ddPdQZ8d^ee	ee
 e$e	e.edSdTdUZ9edd5dVdWZ:dS )_r>   a  Renders an auto-updating progress bar(s).

    Args:
        console (Console, optional): Optional Console instance. Default will 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.
    NTrg   g      >@F)
rq   rp   rt   speed_estimate_periodrr   redirect_stdoutredirect_stderrrs   ry   expand)r   rq   rp   rt   rH  rr   rI  rJ  rs   ry   rK  rL   c       
      	   G   s   |dkst dt | _|p"|  | _|| _|	| _|
| _i | _t	d| _
t|pRt |||||| jd| _|pr| jj| _| jj| _| jj| _d S )Nr   zrefresh_per_second must be > 0)rq   rp   rt   rr   rI  rJ  get_renderable)AssertionErrorr   r:  get_default_columnsr   rH  ry   rK  _tasksr:   _task_indexr2   r+   rL  liverq   rs   printlog)rF   rq   rp   rt   rH  rr   rI  rJ  rs   ry   rK  r   rI   rI   rJ   rE   *  s(    
	
zProgress.__init__.rK   c                 C   s   t dt t t fS )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.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   )r  rI   rI   rJ   rN  N  s
    zProgress.get_default_columnsc                 C   s   | j jS rR   )rQ  rq   rU   rI   rI   rJ   rq   m  s    zProgress.consolec              
   C   s,   | j  t| j W  5 Q R  S Q R X dS )zGet a list of Task instances.N)r:  listrO  valuesrU   rI   rI   rJ   tasksq  s    zProgress.tasksc              
   C   s,   | j  t| j W  5 Q R  S Q R X dS )zA list of task IDs.N)r:  rT  rO  keysrU   rI   rI   rJ   task_idsw  s    zProgress.task_idsc              
   C   sJ   | j : | jsW 5 Q R  dS tdd | j D W  5 Q R  S Q R X dS )z'Check if all tasks have been completed.Tc                 s   s   | ]}|j V  qd S rR   )r   )r@  r   rI   rI   rJ   rB    s     z$Progress.finished.<locals>.<genexpr>N)r:  rO  allrU  rU   rI   rI   rJ   r   }  s    zProgress.finishedc                 C   s   | j s| jjdd dS )zStart the progress display.T)rM   N)ry   rQ  rT   rU   rI   rI   rJ   rT     s    zProgress.startc                 C   s    | j   | jjs| j  dS )zStop the progress display.N)rQ  r   rq   Zis_interactiverR  rU   rI   rI   rJ   r     s    
zProgress.stopc                 C   s   |    | S rR   rS   rU   rI   rI   rJ   rV     s    zProgress.__enter__rW   c                 C   s   |    d S rR   )r   r]   rI   rI   rJ   r^     s    zProgress.__exit__rf   rl   )rm   ro   r@   rn   rA   rL   c              	   c   s   d}|dkr$t |tr(tt|}n|}|dkr@| j||d}n| j||d | jjrt| ||$}|D ]}|V  | j	d7  _	qhW 5 Q R X n,| j
}	| j}
|D ]}|V  |	|d |
  qdS )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).
            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.
        Nro   r)   )r   r   rc   r   add_taskrP   rQ  rp   r=   rC   rN   rM   )rF   rm   ro   r@   rn   rA   Z
task_totalZtrack_threadvaluerN   rM   rI   rI   rJ   r     s&    

zProgress.trackr   )r@   rn   )r   ro   r@   rn   rL   c             	   C   s~   d}|dk	r|}n&|dk	r8| j  | j| j}W 5 Q R X |dkrHtd|dkr`| j||d}n| j||d t|| |ddS )aj  Track 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'rZ  Fr   )r:  rO  ro   
ValueErrorr[  rP   r   )rF   r   ro   r@   rn   total_bytesrI   rI   rJ   r     s    zProgress.wrap_filer   )ro   r@   rn   r   r   )
r   r   r   r   r   r   ro   r@   rn   rL   c          
      C   s   d S rR   rI   
rF   r   r   r   r   r   r   ro   r@   rn   rI   rI   rJ   r     s    zProgress.openr   r   c          
      C   s   d S rR   rI   r`  rI   rI   rJ   r     s    c                C   s   d t|dd}
|
dkr(td||dk}|
dkrR|dkrRtdt d	}n.|
d
ksb|
dkr|dkrttdn|dkrd	}|dkrt|j}|dkr| j	|	|d}n| j
||d tj|d|d}t|| |dd}|dks|d
krtj|||||d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.
        r   F)reverse)brr   r   zinvalid mode {!r}r)   rb  zaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedr   r   r   r   zcan't have unbuffered text I/ONrZ  r   )r   Tr]  )r   r   r   line_buffering)r\   sortedr^  r   warningswarnRuntimeWarningr   st_sizer[  rP   ior   r   TextIOWrapper)rF   r   r   r   r   r   r   ro   r@   rn   _moderc  r   r   rI   rI   rJ   r     s>    !

)r@   rL   c              	   C   s4   | j $ | j| }|jdkr&|  |_W 5 Q R X dS )zStart 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:  rO  r4  rs   )rF   r@   r   rI   rI   rJ   
start_taska  s    	

zProgress.start_taskc              	   C   s>   | j . | j| }|  }|jdkr*||_||_W 5 Q R X dS )zStop a task.

        This will freeze the elapsed time on the task.

        Args:
            task_id (TaskID): ID of task.
        N)r:  rO  rs   r4  r5  )rF   r@   r   r   rI   rI   rJ   	stop_tasko  s    

zProgress.stop_task)ro   rC   rN   rn   r.  rM   )	r@   ro   rC   rN   rn   r.  rM   r0  rL   c             	   K   s*  | j 
 | j| }	|	j}
|dk	r:||	jkr:||	_|	  |dk	rP|	 j|7  _|dk	r^||	_|dk	rl||	_|dk	rz||	_|	j| |	j|
 }| 	 }|| j
 }|	j}|j}|r|d j|k r|  q|dkr|t|| |	jdk	r|	j|	jkr|	jdkr|	j|	_W 5 Q R X |r&|   dS )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:  rO  rC   ro   rE  rn   r.  r0  rP   rs   rH  r9  popleftr   appendr,  r  r  rM   )rF   r@   ro   rC   rN   rn   r.  rM   r0  r   completed_startupdate_completedr   old_sample_timer9  rn  rI   rI   rJ   rP   ~  sB    




zProgress.updater   )rT   ro   rC   r.  rn   )r@   rT   ro   rC   r.  rn   r0  rL   c          
   	   K   s   |   }| jf | j| }	|	  |r*|nd|	_|dk	r>||	_||	_|dk	rR||	_|r\||	_|dk	rj||	_	d|	_
W 5 Q R X |   dS )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)rs   r:  rO  rE  r4  ro   rC   r.  r0  rn   r  rM   )
rF   r@   rT   ro   rC   r.  rn   r0  r   r   rI   rI   rJ   reset  s     
zProgress.resetr)   )r@   rN   rL   c           
   	   C   s   |   }| j | j| }|j}| j|7  _|j| }|| j }|j}|j}	|rh|d j|k rh|	  qNt|dkr||	  qh|	t
|| |jdk	r|j|jkr|jdkr|j|_|j|_W 5 Q R X dS )zAdvance task by a number of steps.

        Args:
            task_id (TaskID): ID of task.
            advance (float): Number of steps to advance. Default is 1.
        r   r
  N)rs   r:  rO  rC   rH  r9  rn  r   r   ro  r,  ro   r  r  r   r  )
rF   r@   rN   r   r   rp  rq  rr  r9  rn  rI   rI   rJ   rN     s,    



zProgress.advancec                 C   s   | j s| jjr| j  dS )z*Refresh (render) the progress information.N)ry   rQ  Z
is_startedrM   rU   rI   rI   rJ   rM      s    zProgress.refreshc                 C   s   t |   }|S )z*Get a renderable for the progress display.)r-   get_renderables)rF   r   rI   rI   rJ   rL    s    zProgress.get_renderablec                 c   s   |  | j}|V  dS )z5Get a number of renderables for the progress display.N)make_tasks_tablerV  )rF   tablerI   rI   rJ   rt  
  s    zProgress.get_renderables)rV  rL   c                    sR   dd | j D }tj|d| jd}|D ]$  jr(|j fdd| j D   q(|S )zGet 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.
        c                 s   s.   | ]&}t |trtd dn
|  V  qdS )Tr   N)r   r   r6   r   copy)r@  Z_columnrI   rI   rJ   rB    s   z,Progress.make_tasks_table.<locals>.<genexpr>)r   r)   )paddingrK  c                 3   s,   | ]$}t |tr|j d n| V  qdS )r   N)r   r   r   )r@  columnr   rI   rJ   rB  %  s   )r   r7   ZgridrK  r.  add_row)rF   rV  Ztable_columnsrv  rI   r   rJ   ru    s    	

zProgress.make_tasks_tablec              
   C   s&   | j  |  W  5 Q R  S Q R X dS )z+Makes the Progress class itself renderable.N)r:  rL  rU   rI   rI   rJ   __rich__0  s    zProgress.__rich__r=  )rn   rT   ro   rC   r.  r0  rL   c           	      K   sr   | j Z t| j|||||| j| j d}|| j| j< |rB| | j | j}tt| jd | _W 5 Q R X |   |S )a  Add 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.  r0  r-  r:  r)   )	r:  r   rP  rs   rO  rl  r:   r   rM   )	rF   rn   rT   ro   rC   r.  r0  r   Znew_task_indexrI   rI   rJ   r[  5  s$    
zProgress.add_taskc              	   C   s   | j  | j|= W 5 Q R X dS )z]Delete a task if it exists.

        Args:
            task_id (TaskID): A task ID.

        N)r:  rO  )rF   r@   rI   rI   rJ   remove_task`  s    zProgress.remove_task)NNrf   rl   )N)r   NNN)r   NNN)r   r   NNN)r)   )Tr=  r   T);r_   r`   ra   rb   r%   r   r   r   r,   r   rc   rF  rE   r  r"   rN  r   rq   r   r   rV  r:   rX  r   rT   r   rV   r#   rd   r   r^   r   r;   r    r   r   r   r   typingoverloadr   r(   r   r!   rl  rm  r   rP   rs  rN   rM   r/   rL  rt  r7   ru  r{  r[  r|  rI   rI   rI   rJ   r>     sn  
$
    1 *    	    	     	
MA'!    +r>   __main__)Panel)Rule)Syntax)r7   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)Zline_numbersZfoobarZbaz123z:Text may be printed while the progress bars are rendering.z(In fact, [i]any[/i] renderable will workzSuch as [magenta]tables[/]...zPretty printed structures...ZexamplezPretty printed)typer   z	Syntax...zGive it a try!)cycle)record)rq   rr   z[red]Downloadingr
  rZ  z[green]Processingz[yellow]Thinkingr  r   g333333?g{Gz?d   )rf   NTNFNrg   rh   ri   rj   rk   rl   FT)r   NNN)r   NNN)r   r   NNN)ri  sysr}  re  abcr   r   collectionsr   collections.abcr   Zdataclassesr   r   datetimer	   r
   r   mathr   r   osr   r   	threadingr   r   r   typesr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   version_infor(   Ztyping_extensionsr   r*   r+   rq   r,   r-   r.   r/   r   r0   Zjupyterr1   rQ  r2   progress_barr3   r   r4   ru   r5   rv  r6   r7   r   r8   r9   r   r:   r;   rc   rF  r<   r=   r   r   r   r   r   r   r~  r   r   r   r   r   r~   r   r   r   r   r  r#  r$  r   r+  r,  r   r>   r_   randomtimeZpanelr  Zruler  Zsyntaxr  rz  Zprogress_renderables	itertoolsr  ZexamplesrN  r?   r[  Ztask1Ztask2Ztask3r   rP   sleeprandintrS  r   rI   rI   rI   rJ   <module>   s,  P
*              FdA             V*2*I0		1	}    U


