
    STh,                         d dl Z d dlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZ ddlmZmZmZmZmZmZ d Zdd	d	d	d
ddZdd	d	d
ddZd	ddZdddZdd	ddZy)    N)chain   )spinner_controller)combinationsoverlay_sliding_window
round_evenspinner_playersplit_optionsspread_weightedstatic_sliding_window   )combine_cells	fix_cellshas_widemark_graphemesstrip_marksto_cellsc                       d  D         t        d  D               t        t        d  D                    d fd	       S )u  Create a factory of a spinner that delivers frames in sequence, split by cycles.
    Supports unicode grapheme clusters and emoji chars (those that has length one but when on
    screen occupies two cells), as well as all other spinners.

    Args:
        frames (Union[str, Tuple[str, ...]): the frames to be displayed, split by cycles
            if sent only a string, it is interpreted as frames of a single char each.

    Returns:
        a styled spinner factory

    Examples:
        To define one cycle:
        >>> frame_spinner_factory(('cool',))  # only one frame.
        >>> frame_spinner_factory(('ooo', '---'))  # two frames.
        >>> frame_spinner_factory('|/_')  # three frames of one char each, same as below.
        >>> frame_spinner_factory(('|', '/', '_'))

        To define two cycles:
        >>> frame_spinner_factory(('super',), ('cool',))  # one frame each.
        >>> frame_spinner_factory(('ooo', '-'), ('vvv', '^'))  # two frames each.
        >>> frame_spinner_factory('|/_', '▁▄█')  # three frames each, same as below.
        >>> frame_spinner_factory(('|', '/', '_'), ('▁', '▄', '█'))

        Mix and match at will:
        >>> frame_spinner_factory(('oo', '-'), 'cool', ('it', 'is', 'alive!'))

    c              3   V   K   | ]!  }t        |t              rt        |      n| # y wN)
isinstancestrtuple.0cycles     g/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/alive_progress/animations/spinners.py	<genexpr>z(frame_spinner_factory.<locals>.<genexpr>(   s"     TEj4eEl%?Ts   ')c              3   @   K   | ]  }t        d  |D                yw)c              3   2   K   | ]  }t        |        y wr   )r   )r   frames     r   r   z2frame_spinner_factory.<locals>.<genexpr>.<genexpr>+   s     <U%<s   N)r   r   s     r   r   z(frame_spinner_factory.<locals>.<genexpr>+   s     Q5<e<<Q   c              3   @   K   | ]  }|D ]  }t        |         y wr   lenr   r   r!   s      r   r   z(frame_spinner_factory.<locals>.<genexpr>-   s!     #V5PU#VuCJ#VJ#Vr"   naturalc                       xs j                    t        j                   t        d D              z         fdfdD        S )Nc              3   @   K   | ]  }|D ]  }t        |         y wr   r$   r&   s      r   r   zGframe_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>0   s1      2F?D2F6; 36e* 2F* 2Fr"   c              3   0   K   | D ]  }|z  d    y wr    )r   r!   actual_length	max_ratios     r   
frame_datazHframe_spinner_factory.<locals>.inner_spinner_factory.<locals>.frame_data3   s(      :y(.=99:s   c              3   .   K   | ]  } |        y wr   r,   )r   r   r/   s     r   r   zGframe_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>8   s     6e
5!6   )r(   mathceilmin)r-   r/   r.   framesinner_spinner_factorys   `@@r   r6   z4frame_spinner_factory.<locals>.inner_spinner_factory-   sS    %F)>)F)FIImc 2F& 2F /F F G		:
 7v66    r   )r   r   max)r5   r6   s   `@r   frame_spinner_factoryr9   
   sM    < UVTF Q&QQF#VF#V VW
7 X
7 ! r7   TFrighthidewrapoverlayc                   	 r	sJ d       rt              rJ d       t               t               rt        nt        j                  c 	t        |xs t                     d 	f	d	       S )a  Create a factory of a spinner that scrolls characters from one side to
    the other, configurable with various constraints.
    Supports unicode grapheme clusters and emoji chars, those that has length one but when on
    screen occupies two cells.

    Args:
        chars (str): the characters to be scrolled, either together or split in blocks
        length (Optional[int]): the natural length that should be used in the style
        block (Optional[int]): if defined, split chars in blocks with this size
        background (Optional[str]): the pattern to be used besides or underneath the animations
        right (bool): the scroll direction to animate
        hide (bool): controls whether the animation goes through the borders or not
        wrap (bool): makes the animation wrap borders or stop when not hiding.
        overlay (bool): fixes the background in place if overlay, scrolls it otherwise

    Returns:
        a styled spinner factory

    zoverlay needs a backgroundz,unsupported overlay with grapheme backgroundr'   c                 .  		
 | xs j                   } | j                   z  }d xs d|z        xs t              c}r| 	n$t        d| z
        	rr nt        | z
        }r(fd}t	        |t        rt              n            }nf}rt        nt        } |t        xs d      	|| |      
	
fdsr	z   nt        | z
        rt        t        t                          nd}fdt        |      D        S )Nr   c                 :    t        t        | f      z  d        S r   )r   r   )g
block_sizes    r   	get_blockzKscrolling_spinner_factory.<locals>.inner_spinner_factory.<locals>.get_blockd   s!     .!"6"C[j!QRRr7    c               3   b   K   t        t        z               D ]  \  } }| k  s|  y wr   )ziprange)ifillrC   gapinfinite_ribbonsizes     r   r/   zLscrolling_spinner_factory.<locals>.inner_spinner_factory.<locals>.frame_datao   s7     uS:%56H 49Js   $//r   c              3   ,   K   | ]  }          y wr   r,   )r   _r/   s     r   r   zKscrolling_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>v   s     4
4s   )r(   r%   r8   absmapr   reversedr   r   r   r   rH   )r-   ratioinitialrD   contentswindow_implcyclesrC   r/   rK   rL   rM   
backgroundblockcharsr<   r6   r>   r;   rounderr=   s          @@@@@r   r6   z8scrolling_spinner_factory.<locals>.inner_spinner_factoryV   s   %F)>)F)F 5 = ==%*1)=!>!L#e*Ca34C).:+C
8R4SS 9kU(5/PU&VWHxH07,=R%hz/@S&A&)8]E7T	
 $(4sZS9S5T38U;u-./a4eFm44r7   r   )r   r   r   r2   r3   r   r%   )
rZ   lengthrY   rX   r;   r<   r=   r>   r6   r[   s
   ` ``````@@r   scrolling_spinner_factoryr]   =   sv    * 
I-II+HZ0a3aa1e_HUOjNE7 4#e*55 5 65B ! r7   )r;   r<   r>   c          
          t        |       \  }}t        |      \  }	}
t        |||	|||d|      }t        |||
|| |d|      }t        ||      S )a  Create a factory of a spinner that scrolls characters from one side to
    the other and bounce back, configurable with various constraints.
    Supports unicode grapheme clusters and emoji chars, those that has length one but when on
    screen occupies two cells.

    Args:
        chars (Union[str, Tuple[str, str]]): the characters to be scrolled, either
            together or split in blocks. Also accepts a tuple of two strings,
            which are used one in each direction.
        length (Optional[int]): the natural length that should be used in the style
        block (Union[int, Tuple[int, int], None]): if defined, split chars in blocks
        background (Optional[str]): the pattern to be used besides or underneath the animations
        right (bool): the scroll direction to start the animation
        hide (bool): controls whether the animation goes through the borders or not
        overlay (bool): fixes the background in place if overlay, scrolls it otherwise

    Returns:
        a styled spinner factory

    Fr:   )r
   r]   sequential_spinner_factory)rZ   r\   rY   rX   r;   r<   r>   chars_1chars_2block_1block_2scroll_1scroll_2s                r   bouncing_spinner_factoryrf   {   sl    , %U+GW$U+GW(&':UZ.2QH(&':Y^U^.2QH%h99r7   )intermixc                 Z     t        t        d D                    d fd	       S )a  Create a factory of a spinner that combines other spinners together, playing them
    one at a time sequentially, either intermixing their cycles or until depletion.

    Args:
        spinner_factories (spinner): the spinners to be combined
        intermix (bool): intermixes the cycles if True, generating all possible combinations;
            runs each one until depletion otherwise.

    Returns:
        a styled spinner factory

    c              3   4   K   | ]  }|j                     y wr   r'   r   factorys     r   r   z-sequential_spinner_factory.<locals>.<genexpr>        #UGOO#U   r'   c                    | xs j                   } D cg c]
  } ||        c}d r(t        d D              }fdt        |      D        }nfdD        }d t        j                  |      D        S c c}w )Nc              3   .   K    |        E d {    y 7 wr   r,   )spinners    r   r/   zMsequential_spinner_factory.<locals>.inner_spinner_factory.<locals>.frame_data   s     y  s   c              3   4   K   | ]  }|j                     y wr   )rW   r   rp   s     r   r   zLsequential_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>   s     !IW'..!Irm   c              3   4   K   | ]  }fd D          yw)c              3   .   K   | ]  } |        y wr   r,   r   rp   r/   s     r   r   zVsequential_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>.<genexpr>   s     @GJw'@r1   Nr,   )r   rO   r/   spinnerss     r   r   zLsequential_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>   s"      + Ax@@ +s   c              3   ^   K   | ]#  fd t        j                        D         % yw)c              3   .   K   | ]  }         y wr   r,   )r   rO   r/   rp   s     r   r   zVsequential_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>.<genexpr>   s     GAJw'Gr1   N)rH   rW   ru   s    @r   r   zLsequential_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>   s+      , Hw~~1FGG ,s   )-c              3       K   | ]  }|  y wr   r,   )r   cs     r   r   zLsequential_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>   s     4a4s   )r(   r   rH   r   from_iterable)	r-   rk   rW   genr/   rv   r6   rg   spinner_factoriess	       @@r   r6   z9sequential_spinner_factory.<locals>.inner_spinner_factory   s    %F)>)F)F:KLwGM*L	! !!I!IIF+!&M+C,"*,C 55..s344 Ms   A>r   )r   r8   )rg   r}   r6   s   ``@r   r_   r_      s1     #UCT#U UV5 W5" ! r7   )pivotc                 V     t        t        d D                    d fd	       }|S )a  Create a factory of a spinner that combines other spinners together, playing them
    alongside simultaneously. Each one uses its own natural length, which is spread weighted
    to the available space.

    Args:
        spinner_factories (spinner): the spinners to be combined
        pivot (Optional[int]): the index of the spinner to dictate the animation cycles
            if None, the whole animation will be compiled into a unique cycle.

    Returns:
        a styled spinner factory

    c              3   4   K   | ]  }|j                     y wr   r'   rj   s     r   r   z,alongside_spinner_factory.<locals>.<genexpr>   rl   rm   r'   c                    | rct        | D cg c]  }|j                   c}      }|   sd n    |         t        |      D cg c]  \  }}|r ||       c}}n#d n	           D cg c]	  } |        c}d t        d D              D cg c]  }t	        |       c}t              D 	cg c]*  \  }}t        ||z        D 	cg c]  }	t        |       c}	, c}	}} 	fddc}
n"fdj                  z  j                  z  c}
fdt        |
      D        S c c}w c c}}w c c}w c c}w c c}	w c c}	}}w )Nc              3   2   K   d | D        E d {    y 7 w)Nc              3   0   K   | ]  ^}}t        |   y wr   )r   )r   rO   	fragmentss      r   r   z_alongside_spinner_factory.<locals>.inner_spinner_factory.<locals>.frame_data.<locals>.<genexpr>   s     Qma)y1Qs   r,   )	cycle_gens    r   r/   zLalongside_spinner_factory.<locals>.inner_spinner_factory.<locals>.frame_data   s     QyQQQs   c              3   4   K   | ]  }|j                     y wr   )total_framesrr   s     r   r   zKalongside_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>   s     Kwg22Krm   c                      t               S r   )rH   )r5   s   r   <lambda>zJalongside_spinner_factory.<locals>.inner_spinner_factory.<locals>.<lambda>   s    eFm r7   r   c                               S r   r,   )actual_pivots   r   r   zJalongside_spinner_factory.<locals>.inner_spinner_factory.<locals>.<lambda>   s	    ln r7   c              3   L   K   | ]  } t                g         y wr   )rG   )r   rO   breakerr/   rv   s     r   r   zKalongside_spinner_factory.<locals>.inner_spinner_factory.<locals>.<genexpr>   s"     M!
3wy4845Ms   !$)
r   r(   rG   r   r	   	enumeraterH   nextr   rW   )r-   offsetflengthsrk   r\   rp   rI   playerrO   rW   r   r   r/   r5   rv   r~   r}   s              @@@@@r   r6   z8alongside_spinner_factory.<locals>.inner_spinner_factory   sc   %mIZ5[Aaii5[\G#(=4-&u-gen=  -w7COGV;A   CH $)=46N6G6N6PL1BCg	CH	R K(KK;CDN7+DDMhDWXXyq&a&j 1	21$v,	2X3QOGV4,333l6I6II GVMuV}MM+ 6\C D E	2Xs/   E
E>E(EE$E6EE)Nr   )r   sum)r~   r}   r6   s   `` r   alongside_spinner_factoryr      s3     #UCT#U UVN WN2 ! r7   dynamicc                     |s! fz  }t        |ddij                        S t         j                  z  d      d fd	       }|S )a  Create a factory of a spinner that combines itself several times alongside,
    with an increasing iteration offset on each one.

    Args:
        spinner_factory (spinner): the source spinner
        copies (int): the number of copies
        offset (int): the offset to be applied incrementally to each copy
        dynamic (bool): dynamically changes the number of copies based on available space

    Returns:
        a styled spinner factory

    r~   r   )r   T)r(   skip_compilerc                 z    | r"t        j                  | j                  z        n} t        |d      |       S )NFr   )r2   r3   r(   delayed_spinner_factory)r-   ncopiesr   spinner_factorys     r   r6   z6delayed_spinner_factory.<locals>.inner_spinner_factory   s;    BODIImo&=&==>U[Q&65QR_``r7   r   )r   opr   r(   )r   r   r   r   	factoriesr6   s   ```   r   r   r      sc     $&/	()=1=@@@OO 7 7& @PTUa Va ! r7   )NNN)r   )r2   	itertoolsr   spinner_compilerr   utilsr   r   r   r	   r
   r   r   utils.cellsr   r   r   r   r   r   r9   r]   rf   r_   r   r   r,   r7   r   <module>r      sq      0: : : c c0!f;!$(t$;!|:#'dE:> =A  !F 9= )!X!$ !r7   