
    h;,                         S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  Sr
/ SQr Sr  " S	 S
\5      r " S S\5      rg)aY
  
Support for spinners that represent progress on interactive terminals.

The :class:`Spinner` class shows a "spinner" on the terminal to let the user
know that something is happening during long running operations that would
otherwise be silent (leaving the user to wonder what they're waiting for).
Below are some visual examples that should illustrate the point.

**Simple spinners:**

 Here's a screen capture that shows the simplest form of spinner:

  .. image:: images/spinner-basic.gif
     :alt: Animated screen capture of a simple spinner.

 The following code was used to create the spinner above:

 .. code-block:: python

    import itertools
    import time
    from humanfriendly import Spinner

    with Spinner(label="Downloading") as spinner:
        for i in itertools.count():
            # Do something useful here.
            time.sleep(0.1)
            # Advance the spinner.
            spinner.step()

**Spinners that show elapsed time:**

 Here's a spinner that shows the elapsed time since it started:

  .. image:: images/spinner-with-timer.gif
     :alt: Animated screen capture of a spinner showing elapsed time.

 The following code was used to create the spinner above:

 .. code-block:: python

    import itertools
    import time
    from humanfriendly import Spinner, Timer

    with Spinner(label="Downloading", timer=Timer()) as spinner:
        for i in itertools.count():
            # Do something useful here.
            time.sleep(0.1)
            # Advance the spinner.
            spinner.step()

**Spinners that show progress:**

 Here's a spinner that shows a progress percentage:

  .. image:: images/spinner-with-progress.gif
     :alt: Animated screen capture of spinner showing progress.

 The following code was used to create the spinner above:

 .. code-block:: python

    import itertools
    import random
    import time
    from humanfriendly import Spinner, Timer

    with Spinner(label="Downloading", total=100) as spinner:
        progress = 0
        while progress < 100:
            # Do something useful here.
            time.sleep(0.1)
            # Advance the spinner.
            spinner.step(progress)
            # Determine the new progress value.
            progress += random.random() * 5

If you want to provide user feedback during a long running operation but it's
not practical to periodically call the :func:`~Spinner.step()` method consider
using :class:`AutomaticSpinner` instead.

As you may already have noticed in the examples above, :class:`Spinner` objects
can be used as context managers to automatically call :func:`Spinner.clear()`
when the spinner ends.
    N)Timer)deprecated_args)ANSI_ERASE_LINE)AutomaticSpinnerGLYPHSMINIMUM_INTERVALSpinner)-\|/g?c                   b    \ rS rSrSr\" SSSSS5      S 5       rSS
 jrS rS r	S r
SS jrSrg	)r	   r   zIShow a spinner on the terminal as a simple means of feedback to the user.labeltotalstreaminteractivetimerc                    UR                  S5      U l        UR                  S[        5      U l        UR                  S5      U l        UR                  S[
        5      U l        UR                  S[        R                  5      U l	        UR                  S5      U l
        UR                  S5      U l        SU l        SU l        U R                  c!   U R                  R                  5       U l        g	g	! [         a
    S
U l         g	f = f)a  
Initialize a :class:`Spinner` object.

:param label:

  The label for the spinner (a string or :data:`None`, defaults to
  :data:`None`).

:param total:

  The expected number of steps (an integer or :data:`None`). If this is
  provided the spinner will show a progress percentage.

:param stream:

  The output stream to show the spinner on (a file-like object,
  defaults to :data:`sys.stderr`).

:param interactive:

  :data:`True` to enable rendering of the spinner, :data:`False` to
  disable (defaults to the result of ``stream.isatty()``).

:param timer:

  A :class:`.Timer` object (optional). If this is given the spinner
  will show the elapsed time according to the timer.

:param interval:

  The spinner will be updated at most once every this many seconds
  (a floating point number, defaults to :data:`MINIMUM_INTERVAL`).

:param glyphs:

  A list of strings with single characters that are drawn in the same
  place in succession to implement a simple animated effect (defaults
  to :data:`GLYPHS`).
r   intervalr   glyphsr   r   r   r   NF)getr   r   r   r   r   statessysstderrr   r   r   counterlast_updateisatty	Exception)selfoptionss     Y/var/www/fran/franai/venv/lib/python3.13/site-packages/humanfriendly/terminal/spinners.py__init__Spinner.__init__v   s    T #;;}5J0@A[[)
kk(F3kk(CJJ7[[)
[[)
 #)#';;#5#5#7  $  )#( )s   C1 1DDNc                    U R                   (       GaH  [        R                  " 5       nX0R                  -
  U R                  :  Ga  X0l        U R                  U R
                  [        U R                  5      -     nU=(       d    U R                  nU(       d  [        S5      eU R                  (       a  U(       a  SX!U R                  S-  -  4-  nOIU R                  (       a8  U R                  R                  S:  a  U< SU R                  R                  < S3nU R                  R                  [        < SU< SU< S35        U =R
                  S	-  sl        g
g
g
)a  
Advance the spinner by one step and redraw it.

:param progress: The number of the current step, relative to the total
                 given to the :class:`Spinner` constructor (an integer,
                 optional). If not provided the spinner will not show
                 progress.
:param label: The label to use while redrawing (a string, optional). If
              not provided the label given to the :class:`Spinner`
              constructor is used instead.

This method advances the spinner by one step without starting a new
line, causing an animated effect which is very simple but much nicer
than waiting for a prompt which is completely silent for a long time.

.. note:: This method uses time based rate limiting to avoid redrawing
          the spinner too frequently. If you know you're dealing with
          code that will call :func:`step()` at a high frequency,
          consider using :func:`sleep()` to avoid creating the
          equivalent of a busy loop that's rate limiting the spinner
          99% of the time.
zNo label set for spinner!z
%s: %.2f%%g      Y@   z () z ..   N)r   timer   r   r   r   lenr   r   r   r   elapsed_timeroundedr   writer   )r    progressr   time_nowstates        r"   stepSpinner.step   s    . yy{H***dmm;#+ DLL3t{{3C$CD+#$?@@ZZH(EtzzE?Q3R+SSEZZDJJ$;$;a$?).

0B0BCE!!_eU"ST! <     c                 8    [         R                  " [        5        g)a  
Sleep for a short period before redrawing the spinner.

This method is useful when you know you're dealing with code that will
call :func:`step()` at a high frequency. It will sleep for the interval
with which the spinner is redrawn (less than a second). This avoids
creating the equivalent of a busy loop that's rate limiting the
spinner 99% of the time.

This method doesn't redraw the spinner, you still have to call
:func:`step()` in order to do that.
N)r*   sleepr   r    s    r"   r6   Spinner.sleep   s     	

#$r4   c                 f    U R                   (       a   U R                  R                  [        5        gg)z
Clear the spinner.

The next line which is shown on the standard output or error stream
after calling this method will overwrite the line that used to show the
spinner.
N)r   r   r.   r   r7   s    r"   clearSpinner.clear   s$     KKo. r4   c                     U $ )zY
Enable the use of spinners as context managers.

:returns: The :class:`Spinner` object.
 r7   s    r"   	__enter__Spinner.__enter__   s	     r4   c                 $    U R                  5         g)z+Clear the spinner when leaving the context.N)r:   r    exc_type	exc_value	tracebacks       r"   __exit__Spinner.__exit__   s    

r4   )	r   r   r   r   r   r   r   r   r   )r   NNNN)__name__
__module____qualname____firstlineno____doc__r   r#   r2   r6   r:   r>   rE   __static_attributes__r=   r4   r"   r	   r	   r   s@    SWgxH9) I9)v$"L%	/r4   r	   c                   8    \ rS rSrSrS	S jrS rS
S jrS rSr	g)r      a  
Show a spinner on the terminal that automatically starts animating.

This class shows a spinner on the terminal (just like :class:`Spinner`
does) that automatically starts animating. This class should be used as a
context manager using the :keyword:`with` statement. The animation
continues for as long as the context is active.

:class:`AutomaticSpinner` provides an alternative to :class:`Spinner`
for situations where it is not practical for the caller to periodically
call :func:`~Spinner.step()` to advance the animation, e.g. because
you're performing a blocking call and don't fancy implementing threading or
subprocess handling just to provide some user feedback.

This works using the :mod:`multiprocessing` module by spawning a
subprocess to render the spinner while the main process is busy doing
something more useful. By using the :keyword:`with` statement you're
guaranteed that the subprocess is properly terminated at the appropriate
time.
c                     Xl         X l        [        R                  " 5       U l        [        R
                  " U R                  S9U l        g)z
Initialize an automatic spinner.

:param label: The label for the spinner (a string).
:param show_time: If this is :data:`True` (the default) then the spinner
                  shows elapsed time.
)targetN)r   	show_timemultiprocessingEventshutdown_eventProcess_target
subprocess)r    r   rR   s      r"   r#   AutomaticSpinner.__init__  s5     
"-335)11Fr4   c                 8    U R                   R                  5         gz9Enable the use of automatic spinners as context managers.N)rX   startr7   s    r"   r>   AutomaticSpinner.__enter__#  s    r4   Nc                 l    U R                   R                  5         U R                  R                  5         gr[   )rU   setrX   joinrA   s       r"   rE   AutomaticSpinner.__exit__'  s$    !r4   c                 |    U R                   (       a
  [        5       OS n[        U R                  US9 nU R                  R                  5       (       dA  UR                  5         UR                  5         U R                  R                  5       (       d  MA  S S S 5        g ! , (       d  f       g = f! [         a     g f = f)N)r   r   )	rR   r   r	   r   rU   is_setr2   r6   KeyboardInterrupt)r    r   spinners      r"   rW   AutomaticSpinner._target,  s    		#~~EG4Etzz77--4466LLNMMO --4466 877 ! 	 	s/   1B. ABB. 
B+'B. +B. .
B;:B;)r   rR   rU   rX   )TrG   )
rH   rI   rJ   rK   rL   r#   r>   rE   rW   rM   r=   r4   r"   r   r      s    *G 

r4   r   )rL   rS   r   r*   humanfriendlyr   humanfriendly.deprecationr   humanfriendly.terminalr   __all__r   r   objectr	   r   r=   r4   r"   <module>rl      sV   Up  
    5 2 H	 Q  lJf JZ7v 7r4   