
    rZh                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZmZmZmZmZmZ  G d d	      Zy
)z%allowing multiple rich.progress.track    )cycle)length_hint)Thread)sleep)IterableOptionalSequenceUnion)MofNCompleteColumnProgressProgressTypeSpinnerColumnTaskIDTimeElapsedColumnc                       e Zd ZdZddededededdf
dZd	 Zd
 Zdde	de
defdZddeee   ee   f   de	dee   dedee   f
dZy)Bara"  Container for an auto-updating progress bar(s).

    Args:
        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.
        expand (bool, optional): Expand tasks table to fit width. Defaults to False.
    auto_refreshrefresh_per_secondspeed_estimate_periodexpandreturnNc                 J    d | _         || _        || _        || _        || _        y N)progressr   r   r   r   )selfr   r   r   r   s        a/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/epicstuff/progress.py__init__zBar.__init__   s(    $-"$.$4$$+    c                 &   t        t               t               gt        j                         t	               | j
                  | j                  | j                  | j                  d| _	        | j                  j                          | j                  S )N)r   r   r   r   )r   r   r   get_default_columnsr   r   r   r   r   r   starttrack)r   s    r   	__enter__zBar.__enter__   s    -/  J8C_C_Ca  Jctcv  J  FJ  FW  FW  lp  lC  lC  [_  [u  [u  ~B  ~I  ~I  J$---	r   c                 8    | j                   j                          y r   )r   stop)r   exc_type	exc_value	tracebacks       r   __exit__zBar.__exit__   s    --r   desctaskdelayc                     t        | d| d| d| dg      }|| j                  j                  v rK| j                  j                  |t	        |             t        |       || j                  j                  v rJyy)z*cycle description through ..., , ., and ..   z.  z.. z...descriptionN)r   r   task_idsupdatenextr   )r   r*   r+   r,   desc_ss        r   _cyclez
Bar._cycle    su    TF#,4&cltfCLJK&&&&==$v,7<	 	&&&r   sequencer0   total	transientc              #     K   | j                   j                  ||xs t        t        |            xs d      }t	        | j
                  ||fd      j                          |D ]<  }| | j                   j                  |d       | j                   j                          > |r| j                   j                  |       y| j                   j                  || d       y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.
			description: (str, optional): Description of task, if new task is created.
			total: (float, optional): Total number of steps. Default is len(sequence).
			transient: (bool, optional): Clear the progress on exit. Defaults to False.

		Returns:
			Iterable[ProgressType]: An iterable of values taken from the provided sequence.
		N)r7   T)targetargsdaemon   r.   r/   )r   add_taskfloatr   r   r5   r!   advancerefreshremove_taskr2   )r   r6   r0   r7   r8   task_idvalues          r   r"   z	Bar.track)   s      MM"";e6cu[QYEZ?[6c_c"d';"8FLLN e	;==!$== ==W% ==}C-@As   C C")T
   g      >@F)g      ?)WorkingNF)__name__
__module____qualname____doc__boolr?   r   r#   r)   strr   r5   r
   r   r   r	   r   r"    r   r   r   r      s    $ 5 fk   }A   NR  6 % B5,!7,9O!OP B_b Bw  AF  xG B  [_ B  lt  uA  lB Br   r   N)rJ   	itertoolsr   operatorr   	threadingr   timer   typingr   r   r	   r
   rich.progressr   r   r   r   r   r   r   rM   r   r   <module>rT      s,    +      6 6 n n7B 7Br   