U
    bhY                     @  s  d Z ddlmZ ddlZddlZddlZddlZddlmZ dZ	ddl
mZ ed\ZZZZZZZZdZd	Zd
Ze dkZejdZejdZeoedZerdndZ erdndZ!dddddZ"G dd dZ#ddddZ$ddddd Z%d&dddd"dd#d$d%Z&dS )'zTerminals and colors.    )annotationsN)reduce)colored)Any   z[%dmz[0mz[1;%dmWindowsITERM_PROFILETERMZscreenz
Ptmux;]z]z\intstrsreturnc                 C  s   t |  S N)	COLOR_SEQ)r    r   5/tmp/pip-unpacked-wheel-kcem4wq5/celery/utils/term.pyfg    s    r   c                   @  s  e Zd ZdZddddddZdddd	d
dZdddd	ddZddddZddddZddddZ	ddd dddZ
dd dddZdd dddZdd dddZdd dd d!Zdd dd"d#Zdd dd$d%Zdd dd&d'Zdd dd(d)Zddd*d+Zdd dd,d-Zdd dd.d/Zdd dd0d1Zdd dd2d3Zdd dd4d5Zdd dd6d7Zdd dd8d9Zdd dd:d;Zd d dd<d=Zdd dd>d?Zdd dd@dAZdd ddBdCZdd ddDdEZ dddFdGdHZ!dIS )Jr   a"  Terminal colored text.

    Example:
        >>> c = colored(enabled=True)
        >>> print(str(c.red('the quick '), c.blue('brown ', c.bold('fox ')),
        ...       c.magenta(c.underline('jumps over')),
        ...       c.yellow(' the lazy '),
        ...       c.green('dog ')))
    objectr   None)r   kwargsr   c              	   O  sT   || _ t o|dd| _|dd| _| j| j| j| j| j	| j
| j| jd| _d S )NenabledTop )blackredgreenyellowbluemagentacyanwhite)r   
IS_WINDOWSgetr   r   r   r   r   r   r   r    r!   r"   names)selfr   r   r   r   r   __init__/   s    zcolored.__init__r   )abr   c                 C  s   | | S r   r   )r&   r(   r)   r   r   r   _add>   s    zcolored._addc                 C  s`   z|  }W n tk
r(   t|}Y nX z|  }W n tk
rR   t|}Y nX | | S r   )no_colorAttributeErrorr   )r&   r(   r)   ABr   r   r   _fold_no_colorA   s    zcolored._fold_no_colorr   c                 C  s   | j rtt| j| j S dS Nr   )r   r   r   r/   r&   r   r   r   r+   M   s    zcolored.no_colorc                 C  s&   d}| j r| j}| t| j| j S r1   )r   r   r   r*   r   )r&   prefixr   r   r   embedR   s    zcolored.embedc                 C  s   d}| j rt}|   | S r1   )r   	RESET_SEQr4   )r&   suffixr   r   r   __str__X   s    zcolored.__str__ztuple[object, ...])r   r   r   c                 C  s   | j || j|dS )N)r   r   )	__class__r   )r&   r   r   r   r   r   node^   s    zcolored.noder   c                 G  s   |  |tdt S N   )r9   r   BLACKr&   r   r   r   r   r   a   s    zcolored.blackc                 G  s   |  |tdt S r:   r9   r   REDr=   r   r   r   r   d   s    zcolored.redc                 G  s   |  |tdt S r:   r9   r   GREENr=   r   r   r   r   g   s    zcolored.greenc                 G  s   |  |tdt S r:   r9   r   YELLOWr=   r   r   r   r   j   s    zcolored.yellowc                 G  s   |  |tdt S r:   r9   r   BLUEr=   r   r   r   r   m   s    zcolored.bluec                 G  s   |  |tdt S r:   r9   r   MAGENTAr=   r   r   r   r    p   s    zcolored.magentac                 G  s   |  |tdt S r:   r9   r   CYANr=   r   r   r   r!   s   s    zcolored.cyanc                 G  s   |  |tdt S r:   r9   r   WHITEr=   r   r   r   r"   v   s    zcolored.whitec                 C  s   t |  S r   )reprr+   r2   r   r   r   __repr__y   s    zcolored.__repr__c                 G  s   |  |td S )N   r9   OP_SEQr=   r   r   r   bold|   s    zcolored.boldc                 G  s   |  |td S )N   rO   r=   r   r   r   	underline   s    zcolored.underlinec                 G  s   |  |td S )N   rO   r=   r   r   r   blink   s    zcolored.blinkc                 G  s   |  |td S )N   rO   r=   r   r   r   reverse   s    zcolored.reversec                 G  s   |  |td S )Nr   rO   r=   r   r   r   bright   s    zcolored.brightc                 G  s   |  |tdt S N(   r>   r=   r   r   r   ired   s    zcolored.iredc                 G  s   |  |tdt S rY   r@   r=   r   r   r   igreen   s    zcolored.igreenc                 G  s   |  |tdt S rY   rB   r=   r   r   r   iyellow   s    zcolored.iyellowc                 G  s   |  |tdt S rY   rD   r=   r   r   r   iblue   s    zcolored.ibluec                 G  s   |  |tdt S rY   rF   r=   r   r   r   imagenta   s    zcolored.imagentac                 G  s   |  |tdt S rY   rH   r=   r   r   r   icyan   s    zcolored.icyanc                 G  s   |  |tdt S rY   rJ   r=   r   r   r   iwhite   s    zcolored.iwhitec                 G  s   |  |p
dtS )N)r   )r9   r5   r=   r   r   r   reset   s    zcolored.reset)otherr   c                 C  s   |  | S r   r   )r&   rc   r   r   r   __add__   s    zcolored.__add__N)"__name__
__module____qualname____doc__r'   r*   r/   r+   r4   r7   r9   r   r   r   r   r   r    r!   r"   rM   rQ   rS   rU   rW   rX   r[   r\   r]   r^   r_   r`   ra   rb   rd   r   r   r   r   r   $   s>   
r   boolr0   c                   C  s8   zt j ottjdW S  tk
r2   Y dS X d S )Nr   F)sysstdinisattyri   osenvironr$   r,   r   r   r   r   supports_images   s    ro   )pathr   c              
   C  s<   t | dd&}t| }|dW  5 Q R  S Q R X d S )Nrb)modeascii)openbase64	b64encodereaddecode)rp   fhencodedr   r   r   _read_as_base64   s    r{   rN   r   )rp   inlinepreserve_aspect_ratior   r   c                 K  s   dt ||t| tf S )Nz2
%s1337;File=inline=%d;preserveAspectRatio=%d:%s%s)_IMG_PREr{   	_IMG_POST)rp   r|   r}   r   r   r   r   imgcat   s       r   )rN   r   )'rh   
__future__r   ru   rm   platformrj   	functoolsr   __all__typingr   ranger<   r?   rA   rC   rE   rG   rI   rK   rP   r5   r   systemr#   rn   r$   r   r	   
startswithZTERM_IS_SCREENr~   r   r   r   ro   r{   r   r   r   r   r   <module>   s0    