
    ^hB8                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
JrJrJrJrJrJrJrJrJr  SSKJr  SSKJr  SSKJrJrJr  SSKJrJrJr  SS	K J!r!  SS
K"J#r#  SSK$J%r%  SSK&J'r'J(r(J)r)J*r*J+r+J,r,  SSK-J.r.J/r/  SSK0J1r1J2r2  SSK3J4r4J5r5  SSK6J7r7  SSK8J9r9  SSK:J;r;J<r<  S/r=\%r>\?" \SS5      r@S S jrA\" S5      rB " S S5      rC " S S\/5      rD\" SSS9rE " S S\\E   5      rFg)!z
Progress bar implementation on top of prompt_toolkit.

::

    with ProgressBar(...) as pb:
        for item in pb(data):
            ...
    )annotationsN)	CallableGenericIterableIteratorSequenceSizedTextIOTypeVarcast)Application)get_app_session)	Conditionis_donerenderer_height_is_known)AnyFormattedTextStyleAndTextTuplesto_formatted_text)Input)KeyBindings)KeyPressEvent)ConditionalContainerFormattedTextControlHSplitLayoutVSplitWindow)	UIContent	UIControl)AnyDimensionD)
ColorDepthOutput)	BaseStyle)in_main_thread   )	Formattercreate_default_formattersProgressBarSIGWINCHc                   ^  [        5       nUR                  S5      SS j5       nT b  UR                  S5      SU 4S jj5       nU$ )zi
Key bindings handled by the progress bar.
(The main thread is not supposed to handle any key bindings.)
zc-lc                L    U R                   R                  R                  5         g N)apprendererclear)events    d/home/james-whalen/.local/lib/python3.13/site-packages/prompt_toolkit/shortcuts/progress_bar/base.py_clear#create_key_bindings.<locals>._clearI   s    		  "    zc-cc                   > Tc   eT" 5         g)zMKill the 'body' of the progress bar, but only if we run from the main thread.N )r1   cancel_callbacks    r2   
_interrupt'create_key_bindings.<locals>._interruptO   s     #...r5   )r1   EreturnNone)r   add)r8   kbr3   r9   s   `   r2   create_key_bindingsr@   B   sO    
 
BVVE]# # "		 
	
 Ir5   _Tc                      \ rS rSrSr          S
                     SS jjrSS jrSS jr    S         SS jjrSS jr	S	r
g)r)   [   a  
Progress bar context manager.

Usage ::

    with ProgressBar(...) as pb:
        for item in pb(data):
            ...

:param title: Text to be displayed above the progress bars. This can be a
    callable or formatted text as well.
:param formatters: List of :class:`.Formatter` instances.
:param bottom_toolbar: Text to be displayed in the bottom toolbar. This
    can be a callable or formatted text.
:param style: :class:`prompt_toolkit.styles.BaseStyle` instance.
:param key_bindings: :class:`.KeyBindings` instance.
:param cancel_callback: Callback function that's called when control-c is
    pressed by the user. This can be used for instance to start "proper"
    cancellation if the wrapped code supports it.
:param file: The file object used for rendering, by default `sys.stderr` is used.

:param color_depth: `prompt_toolkit` `ColorDepth` instance.
:param output: :class:`~prompt_toolkit.output.Output` instance.
:param input: :class:`~prompt_toolkit.input.Input` instance.
Nc                   Xl         U=(       d
    [        5       U l        X0l        / U l        X@l        XPl        X`l        U R                  c  [        5       (       a  SS jnXl        Xl	        U	=(       d    [        5       R                  U l        U
=(       d    [        5       R                  U l        S U l        SU l        [        R                   " 5       U l        g )Nc                 t    [         R                  " [         R                  " 5       [        R                  5        g r-   )oskillgetpidsignalSIGINTr7   r5   r2   !keyboard_interrupt_to_main_thread?ProgressBar.__init__.<locals>.keyboard_interrupt_to_main_thread   s    		V]]3r5   Fr<   r=   )titler(   
formattersbottom_toolbarcountersstylekey_bindingsr8   r%   color_depthr   outputinput_thread_has_sigwinch	threadingEvent_app_started)selfrN   rO   rP   rR   rS   r8   filerT   rU   rV   rK   s               r2   __init__ProgressBar.__init__v   s     
$C(A(C,:<
(.
 'N,<,<4 $E  '8 1 8 85o/55
04"%OO-r5   c                &  ^  [        [        [        U 4S j5      SSS9[        U 4S j5      S9n[        [        [        U 4S jSS	9S
SS9[        ) [
        -  [        U 4S j5      -  S9nSU 4S jjnT R                   Vs/ s H6  n[        [        T UT R                  5      [        R                  " X45      S9PM8     nn[        S[        [        U[        UU 4S jS9[        5       U/5      5      T R                  T R                   ST R"                  T R$                  T R&                  S9T l        SU 4S jjn[*        R,                  " 5       n[.        R0                  " UR2                  U4S9T l        T R4                  R7                  5         T $ s  snf )Nc                    > T R                   $ r-   rN   r\   s   r2   <lambda>'ProgressBar.__enter__.<locals>.<lambda>   s	    TZZr5   r&   zclass:progressbar,title)heightrR   c                     > T R                   S L$ r-   rb   rc   s   r2   rd   re      s    TZZt%;r5   )filterc                    > T R                   $ r-   rP   rc   s   r2   rd   re      s    D//r5   zclass:bottom-toolbar.text)rR   zclass:bottom-toolbar)rR   rf   c                     > T R                   S L$ r-   rj   rc   s   r2   rd   re      s     3 34 ?r5   c                "   > U R                  TS9$ )N)progress_bar)	get_width)	formatterr\   s    r2   width_for_formatter2ProgressBar.__enter__.<locals>.width_for_formatter   s     &&D&99r5   )contentwidthg?c                 d   > [        [        T R                  5      [        T R                  5      S9$ )N)	preferredmax)r!   lenrQ   rc   s   r2   rd   re      s!    1*-dmm*<#dmmBT,r5   )rf   g333333?)min_redraw_intervallayoutrR   rS   refresh_intervalrT   rU   rV   c                    >  TR                   R                  TR                  R                  S9  g ! [         a*  n [
        R                  " 5         [        U 5         S n A g S n A ff = f)N)pre_run)r.   runr[   setBaseException	traceback	print_excprint)er\   s    r2   r}   "ProgressBar.__enter__.<locals>.run   sK    T%6%6%:%:;  ##%as   -1 
A% A  A%)targetargs)ro   r'   r<   r    rM   )r   r   r   r   r   r   rO   _ProgressControlr8   	functoolspartialr   r   r   r   rR   rS   rT   rU   rV   r.   contextvarscopy_contextrY   Threadr}   rW   start)r\   title_toolbarrP   rp   fprogress_controlsr}   ctxs   `       r2   	__enter__ProgressBar.__enter__   s   ,$%78/
 ;<
 .$/7R - 8&'?@A
	: __

 %	 (q$2F2FG''(;? % 	 
 '2 $%-$ &
 **** ((;;**-'
4	 $/#;#;#= ''swwcVD]
s    =Fc                ^   U R                   R                  5         U R                  R                  (       aP  U R                  R                  b9  U R                  R                  R                  U R                  R                  5        U R                  b  U R                  R                  5         g g r-   )	r[   waitr.   
is_runningloopcall_soon_threadsafeexitrW   join)r\   as     r2   __exit__ProgressBar.__exit__   so     	  88488==#<HHMM..txx}}=<<#LL $r5   c                R    [        XX#US9nU R                  R                  U5        U$ )a  
Start a new counter.

:param label: Title text or description for this progress. (This can be
    formatted text as well).
:param remove_when_done: When `True`, hide this progress bar.
:param total: Specify the maximum value if it can't be calculated by
    calling ``len``.
)labelremove_when_donetotal)ProgressBarCounterrQ   append)r\   datar   r   r   counters         r2   __call__ProgressBar.__call__   s.      %ee
 	W%r5   c                8    U R                   R                  5         g r-   )r.   
invalidaterc   s    r2   r   ProgressBar.invalidate  s    r5   )r[   rX   rW   r.   rP   r8   rT   rQ   rO   rV   rS   rU   rR   rN   )
NNNNNNNNNN)rN   r   rO   zSequence[Formatter] | NonerP   r   rR   zBaseStyle | NonerS   zKeyBindings | Noner8   Callable[[], None] | Noner]   zTextIO | NonerT   zColorDepth | NonerU   zOutput | NonerV   zInput | Noner<   r=   )r<   r)   )r   objectr<   r=   N FN)
r   zIterable[_T] | Noner   r   r   boolr   
int | Noner<   zProgressBarCounter[_T]rM   )__name__
__module____qualname____firstlineno____doc__r^   r   r   r   r   __static_attributes__r7   r5   r2   r)   r)   [   s    8 #'15+/"&+/59")- $"(.(. /(. )	(.
  (. )(. 3(. (. '(. (. (. 
(.TKZ  %)"$!& !   	
  
 ,r5   c                  P    \ rS rSrSr        S	S jrS
S jrSS jrSS jrSr	g)r   i  z$
User control for the progress bar.
c                <    Xl         X l        [        U5      U l        g r-   )rm   ro   r@   _key_bindings)r\   rm   ro   r8   s       r2   r^   _ProgressControl.__init__  s     )"0Ar5   c                J  ^ / mU R                   R                   HD  n U R                  R                  U R                   X15      nTR                  [        U5      5        MF     SU4S jjn[        U[        T5      SS9$ ! [         a    [
        R                  " 5         Sn N]f = f)NERRORc                   > TU    $ r-   r7   )iitemss    r2   get_line1_ProgressControl.create_content.<locals>.get_line/  s    8Or5   F)r   
line_countshow_cursor)r   intr<   r   )rm   rQ   ro   formatr   r   r   r   r   r   rw   )r\   rs   rf   prtextr   r   s         @r2   create_content_ProgressControl.create_content#  s    *,##,,B~~,,T->->J
 LL*401 -	 (s5zuUU ! ##%s   &A>>!B"!B"c                    g)NTr7   rc   s    r2   is_focusable_ProgressControl.is_focusable4  s    r5   c                    U R                   $ r-   )r   rc   s    r2   get_key_bindings!_ProgressControl.get_key_bindings7  s    !!!r5   )r   ro   rm   N)rm   r)   ro   r'   r8   r   r<   r=   )rs   r   rf   r   r<   r   r<   r   )r<   r   )
r   r   r   r   r   r^   r   r   r   r   r7   r5   r2   r   r     sG    B!B B 3	B
 
BV""r5   r   _CounterItemT)	covariantc                     \ rS rSrSr    S           SS jjrSS jrSS jr\SS j5       r	\	R                  SS j5       r	\SS	 j5       r\R                  SS
 j5       r\SS j5       r\SS j5       r\SS j5       rSrg)r   i>  zD
An individual counter (A progress bar can have multiple counters).
Nc                (   [         R                   R                  5       U l        S U l        Xl        X l        SU l        X0l        X@l        SU l	        U   Uc    [        [        [        U5      5      U l        g XPl        g ! [         a
    S U l         g f = f)Nr   F)datetimenow
start_time	stop_timerm   r   items_completedr   r   _donerw   r   r	   r   	TypeError)r\   rm   r   r   r   r   s         r2   r^   ProgressBarCounter.__init__C  s     #++//137(	 
 0
=" eT!23
 J  "!
"s   A= =BBc              #     #    U R                   b7   U R                    H  nUv   U R                  5         M     SU l        SU l        g [	        S5      e! SU l        f = f7f)NTz No data defined to iterate over.)r   item_completeddonestoppedNotImplementedError)r\   items     r2   __iter__ProgressBarCounter.__iter__]  s[     99 
$ IIDJ'') &
 !	  $%&HII  $s   A.A A	AAc                b    U =R                   S-  sl         U R                  R                  5         g)zm
Start handling the next item.

(Can be called manually in case we don't have a collection to loop through.)
r&   N)r   rm   r   rc   s    r2   r   !ProgressBarCounter.item_completedm  s'     	!$$&r5   c                    U R                   $ )a  Whether a counter has been completed.

Done counter have been stopped (see stopped) and removed depending on
remove_when_done value.

Contrast this with stopped. A stopped counter may be terminated before
100% completion. A done counter has reached its 100% completion.
)r   rc   s    r2   r   ProgressBarCounter.donev  s     zzr5   c                    Xl         Xl        U(       a8  U R                  (       a&  U R                  R                  R                  U 5        g g g r-   )r   r   r   rm   rQ   remover\   values     r2   r   r     s8    
T**&&--d3 +5r5   c                    U R                   SL$ )ay  Whether a counter has been stopped.

Stopped counters no longer have increasing time_elapsed. This distinction is
also used to prevent the Bar formatter with unknown totals from continuing to run.

A stopped counter (but not done) can be used to signal that a given counter has
encountered an error but allows other counters to continue
(e.g. download X of Y failed). Given how only done counters are removed
(see remove_when_done) this can help aggregate failures from a large number of
successes.

Contrast this with done. A done counter has reached its 100% completion.
A stopped counter may be terminated before 100% completion.
N)r   rc   s    r2   r   ProgressBarCounter.stopped  s      ~~T))r5   c                    U(       a6  U R                   (       d$  [        R                  R                  5       U l         g g S U l         g r-   )r   r   r   r   s     r2   r   r     s0    >>!)!2!2!6!6!8 " "DNr5   c                j    U R                   c  gU R                  S-  [        U R                   S5      -  $ )Nr   d   r&   )r   r   rv   rc   s    r2   
percentageProgressBarCounter.percentage  s0    ::''#-DJJ0BBBr5   c                    U R                   c+  [        R                  R                  5       U R                  -
  $ U R                   U R                  -
  $ )z8
Return how much time has been elapsed since the start.
)r   r   r   r   rc   s    r2   time_elapsedProgressBarCounter.time_elapsed  s?    
 >>!$$((*T__<<>>DOO33r5   c                   U R                   b  U R                  (       d  gU R                  (       d  U R                  (       a  [        R
                  " S5      $ U R                  SU R                  -
  -  U R                  -  $ )z'
Timedelta representing the time left.
Nr   r   )r   r   r   r   r   	timedeltar   rc   s    r2   	time_leftProgressBarCounter.time_left  sX    
 ::T__YY$,,%%a(($$doo(=>PPr5   )r   r   r   r   r   rm   r   r   r   r   r   r   )rm   r)   r   zIterable[_CounterItem] | Noner   r   r   r   r   r   r<   r=   )r<   zIterator[_CounterItem]rM   r   )r   r   r<   r=   )r<   float)r<   zdatetime.timedelta)r<   zdatetime.timedelta | None)r   r   r   r   r   r^   r   r   propertyr   setterr   r   r   r   r   r7   r5   r2   r   r   >  s     /3"$!& ! ,  	
   
4J ' 	 	 
[[4 4 * *" ^^" " C C 4 4 	Q 	Qr5   r   )r8   r   r<   r   )Gr   
__future__r   r   r   r   rF   rI   rY   r   typingr   r   r   r   r   r	   r
   r   r   prompt_toolkit.applicationr   "prompt_toolkit.application.currentr   prompt_toolkit.filtersr   r   r   prompt_toolkit.formatted_textr   r   r   prompt_toolkit.inputr   prompt_toolkit.key_bindingr   (prompt_toolkit.key_binding.key_processorr   prompt_toolkit.layoutr   r   r   r   r   r   prompt_toolkit.layout.controlsr   r   prompt_toolkit.layout.dimensionr    r!   prompt_toolkit.outputr"   r#   prompt_toolkit.stylesr$   prompt_toolkit.utilsr%   rO   r'   r(   __all__r;   getattr	_SIGWINCHr@   rA   r)   r   r   r   r7   r5   r2   <module>r     s    #    	   
 
 
 3 > O O 
 ' 2 B  @ ; 4 + / </FJ-	, T]v vr$"y $"N ~6CQ. CQr5   