a
    xþdÿ*  ã                   @   sd   d dl Z d dlZd dlZdd„ ZG dd„ dƒZG dd„ dƒZG dd	„ d	ƒZd
d„ Zedkr`eƒ  dS )é    Nc                 C   s
   |   d¡S )Núutf-8)Úencode)Ústr© r   úX/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lit/ProgressBar.pyÚto_bytes   s    r   c                   @   sÞ   e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZdZdZdZdZd Z Z Z Z Z Z ZZd Z Z Z Z!d Z" Z# Z$Z%d &¡ Z'd &¡ Z(d &¡ Z)e*j+fdd„Z,d	d
„ Z-dd„ Z.dd„ Z/dd„ Z0dS )ÚTerminalControllera^  
    A class that can be used to portably generate formatted output to
    a terminal.  
    
    `TerminalController` defines a set of instance variables whose
    values are initialized to the control sequence necessary to
    perform a given action.  These can be simply included in normal
    output to the terminal:

        >>> term = TerminalController()
        >>> print('This is '+term.GREEN+'green'+term.NORMAL)

    Alternatively, the `render()` method can used, which replaces
    '${action}' with the string required to perform 'action':

        >>> term = TerminalController()
        >>> print(term.render('This is ${GREEN}green${NORMAL}'))

    If the terminal doesn't support a given action, then the value of
    the corresponding instance variable will be set to ''.  As a
    result, the above code will still work on terminals that do not
    support color, except that their output will not be colored.
    Also, this means that you can test whether the terminal supports a
    given action by simply testing the truth value of the
    corresponding instance variable:

        >>> term = TerminalController()
        >>> if term.CLEAR_SCREEN:
        ...     print('This terminal supports clearning the screen.')

    Finally, if the width and height of the terminal are known, then
    they will be stored in the `COLS` and `LINES` attributes.
    Ú Nzã
    BOL=cr UP=cuu1 DOWN=cud1 LEFT=cub1 RIGHT=cuf1
    CLEAR_SCREEN=clear CLEAR_EOL=el CLEAR_BOL=el1 CLEAR_EOS=ed BOLD=bold
    BLINK=blink DIM=dim REVERSE=rev UNDERLINE=smul NORMAL=sgr0
    HIDE_CURSOR=cinvis SHOW_CURSOR=cnormz.BLACK BLUE GREEN CYAN RED MAGENTA YELLOW WHITEz.BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITEc                 C   s¸  zddl }W n   Y dS 0 | ¡ s(dS z| ¡  W n   Y dS 0 | d¡| _| d¡| _| d¡| _| jD ](}| 	d¡\}}t
| ||  |¡p’dƒ qn|  d¡}|rÚttt| jƒƒ| jƒD ]\}}t
| ||  ||¡ƒ q¼|  d	¡}	|	r ttt| jƒƒ| jƒD ]\}}t
| ||  |	|¡ƒ q |  d
¡}
|
rjttt| jƒƒ| jƒD ]"\}}t
| d| |  |
|¡ƒ qF|  d¡}|r´ttt| jƒƒ| jƒD ]"\}}t
| d| |  ||¡ƒ qdS )aP  
        Create a `TerminalController` and initialize its attributes
        with appropriate values for the current terminal.
        `term_stream` is the stream that will be used for terminal
        output; if this stream is not a tty, then the terminal is
        assumed to be a dumb terminal (i.e., have no capabilities).
        r   NÚcolsÚlinesZxenlú=r	   ZsetfZsetafZsetbZBG_Zsetab)ÚcursesÚisattyZ	setuptermZtigetnumÚCOLSÚLINESZ	tigetflagÚXNÚ_STRING_CAPABILITIESÚsplitÚsetattrÚ	_tigetstrÚzipÚrangeÚlenÚ_COLORSÚ_tparmÚ_ANSICOLORS)ÚselfZterm_streamr   Z
capabilityÚattribÚcap_nameZset_fgÚiÚcolorZset_fg_ansiZset_bgZset_bg_ansir   r   r   Ú__init__Y   s6    	




zTerminalController.__init__c                 C   s"   dd l }| t|ƒ|¡ d¡p dS )Nr   r   r	   )r   Ztparmr   Údecode)r   ÚargÚindexr   r   r   r   r   ‰   s    zTerminalController._tparmc                 C   s8   dd l }| |¡}|d u r d}n
| d¡}t dd|¡S )Nr   r	   r   z\$<\d+>[/*]?)r   Ztigetstrr"   ÚreÚsub)r   r   r   Úcapr   r   r   r      s    

zTerminalController._tigetstrc                 C   s   t  d| j|¡S )z±
        Replace each $-substitutions in the given template string with
        the corresponding terminal control string (if it's defined) or
        '' (if it's not).
        z\$\$|\${\w+})r%   r&   Ú_render_sub)r   Útemplater   r   r   Úrender™   s    zTerminalController.renderc                 C   s*   |  ¡ }|dkr|S t| |dd… ƒS d S )Nz$$é   éÿÿÿÿ)ÚgroupÚgetattr)r   ÚmatchÚsr   r   r   r(   ¡   s    zTerminalController._render_sub)1Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚBOLÚUPÚDOWNÚLEFTÚRIGHTZCLEAR_SCREENÚ	CLEAR_EOLZ	CLEAR_BOLZ	CLEAR_EOSZBOLDZBLINKÚDIMZREVERSEÚNORMALÚHIDE_CURSORÚSHOW_CURSORr   r   ÚBLACKÚBLUEÚGREENÚCYANÚREDÚMAGENTAÚYELLOWÚWHITEZBG_BLACKZBG_BLUEZBG_GREENZBG_CYANZBG_REDZ
BG_MAGENTAZ	BG_YELLOWZBG_WHITEr   r   r   r   ÚsysÚstdoutr!   r   r   r*   r(   r   r   r   r   r      s<   " 0r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚSimpleProgressBarz•
    A simple progress bar which doesn't need any terminal support.

    This prints out a progress bar like:
      'Header:  0.. 10.. 20.. ...'
    c                 C   s   || _ d | _d S )N)ÚheaderÚatIndex)r   rJ   r   r   r   r!   ²   s    zSimpleProgressBar.__init__c                 C   s°   | j d u rtj | j¡ d| _ t|d ƒ}|| j kr8d S t| j |ƒD ]V}|d }|dkrntj d|d  ¡ qD|dkrxqD|dk rŽtj d¡ qDtj d	¡ qDtj ¡  || _ d S )
Nr   é2   é   z%2dr+   é   é   Ú.ú )rK   rG   rH   ÚwriterJ   Úintr   Úflush)r   ÚpercentÚmessageÚnextr   Úidxr   r   r   Úupdate¶   s"    


zSimpleProgressBar.updatec                 C   s.   | j d ur*|s*tj d¡ tj ¡  d | _ d S )NÚ
)rK   rG   rH   rR   rT   ©r   Úinterruptedr   r   r   ÚclearÌ   s    
zSimpleProgressBar.clearN)r1   r2   r3   r4   r!   rY   r]   r   r   r   r   rI   ª   s   rI   c                   @   s2   e Zd ZdZdZdZddd„Zdd„ Zd	d
„ ZdS )ÚProgressBara>  
    A 3-line progress bar, which looks like::
    
                                Header
        20% [===========----------------------------------]
                           progress message

    The progress bar is colored, if the terminal supports color
    output; and adjusts to the width of the terminal.
    z-%s${%s}[${BOLD}%s%s${NORMAL}${%s}]${NORMAL}%sz${BOLD}${CYAN}%s${NORMAL}

Tc                 C   s²   || _ | j jr| j jr| j js&tdƒ‚| j j| _d| _| j jrj| j j| _| j jsp| j j| j j | _d| _nd| _d| _	| j  
| j| | j¡ ¡| _d| _|| _| jr®t ¡ | _d S )NzKTerminal isn't capable enough -- you should use a simpler progress dispaly.rZ   r	   éK   rA   rN   )Útermr:   r6   r5   Ú
ValueErrorÚXNLr   Úwidthr   ÚbarColorr*   ÚHEADERÚcenterrJ   ÚclearedÚuseETAÚtimeÚ	startTime)r   r`   rJ   rh   r   r   r   r!   à   s"    

zProgressBar.__init__c                 C   sn  | j rtj | j¡ d| _ d|d f }d}| jrŠt ¡ | j }|dkrŠ|dkrŠ|| }|| }|d }|d d }	|d }
d	||	|
f }| jt	|ƒ t	|ƒ d
 }t
|| ƒ}t	|ƒ| jk rÖ|d| jt	|ƒ   }nd|| jd  d …  }| j}| j||d| d||  ||f }| j |¡}tj | j| jj | jj | | j | jj | ¡ | jjsjtj ¡  d S )Nr   z%3d%% éd   r	   g-Cëâ6?rN   g      ¬@é<   z ETA: %02d:%02d:%02dr+   rQ   z... rO   r   ú-)rg   rG   rH   rR   rJ   rh   ri   rj   rc   r   rS   rd   ÚBARr`   r*   r5   r6   r:   rb   r   rT   )r   rU   rV   ÚprefixÚsuffixÚelapsedÚtotalÚetaÚhÚmr0   ZbarWidthÚnZbcÚbarr   r   r   rY   ö   sF    "ÿþýýÿ
zProgressBar.updatec                 C   sx   | j sttj | j| jj | jj | jj | jj | jj ¡ |rdtj | jj| jj ¡ tj d¡ tj ¡  d| _ d S )Nz^CrN   )	rg   rG   rH   rR   r5   r`   r:   r6   rT   r[   r   r   r   r]     s    ÿÿþþ
zProgressBar.clearN)T)	r1   r2   r3   r4   rn   re   r!   rY   r]   r   r   r   r   r^   Ò   s   

 r^   c                  C   s@   t ƒ } t| dƒ}tdƒD ]"}| |d t|ƒ¡ t d¡ qd S )NZTestsée   g      Y@g333333Ó?)r   r^   r   rY   r   ri   Úsleep)ZtcÚpr   r   r   r   Útest!  s
    
r{   Ú__main__)	rG   r%   ri   r   r   rI   r^   r{   r1   r   r   r   r   Ú<module>   s    (O