U
    Íø.e¶  ã                   @   sÞ   d Z ddlZddlZddlZddlZddlZddlmZ d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ršdndZer¦dndZdd„ ZG dd„ dƒZ dd„ Z!dd„ Z"ddd„Z#dS )zTerminals and colors.é    N)Úreduce)Úcoloredé   z[%dmz[0mz[1;%dmÚWindowsÚITERM_PROFILEÚTERMZscreenz
Ptmux;]z]z\úc                 C   s   t |  S ©N)Ú	COLOR_SEQ)Ús© r   ú5/tmp/pip-unpacked-wheel-f4liivr4/celery/utils/term.pyÚfg   s    r   c                   @   s   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>S )?r   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 ')))
    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   Úkwargsr   r   r   Ú__init__,   s    øzcolored.__init__c                 C   s   t |ƒt |ƒ S r	   ©Ústr)r   ÚaÚbr   r   r   Ú_add;   s    zcolored._addc                 C   sj   z|  ¡ }W n tk
r(   t|ƒ}Y nX z|  ¡ }W n tk
rR   t|ƒ}Y nX d t|ƒt|ƒf¡S ©Nr   )Úno_colorÚAttributeErrorr!   Újoin)r   r"   r#   ÚAÚBr   r   r   Ú_fold_no_color>   s    zcolored._fold_no_colorc                 C   s   | j rtt| j| j ƒƒS dS r%   )r   r!   r   r+   ©r   r   r   r   r&   J   s    zcolored.no_colorc                 C   s0   d}| j r| j}d t|ƒtt| j| jƒƒf¡S r%   )r   r   r(   r!   r   r$   r   )r   Úprefixr   r   r   ÚembedO   s    zcolored.embedc                 C   s(   d}| j rt}td |  ¡ t|ƒf¡ƒS r%   )r   Ú	RESET_SEQr!   r(   r.   )r   Úsuffixr   r   r   Ú__str__U   s    zcolored.__str__c                 C   s   | j || j|dœŽS )N)r   r   )Ú	__class__r   )r   r   r   r   r   r   Únode[   s    zcolored.nodec                 G   s   |   |tdt ƒ¡S ©Né   )r3   r   ÚBLACK©r   r   r   r   r   r   ^   s    zcolored.blackc                 G   s   |   |tdt ƒ¡S r4   ©r3   r   ÚREDr7   r   r   r   r   a   s    zcolored.redc                 G   s   |   |tdt ƒ¡S r4   ©r3   r   ÚGREENr7   r   r   r   r   d   s    zcolored.greenc                 G   s   |   |tdt ƒ¡S r4   ©r3   r   ÚYELLOWr7   r   r   r   r   g   s    zcolored.yellowc                 G   s   |   |tdt ƒ¡S r4   ©r3   r   ÚBLUEr7   r   r   r   r   j   s    zcolored.bluec                 G   s   |   |tdt ƒ¡S r4   ©r3   r   ÚMAGENTAr7   r   r   r   r   m   s    zcolored.magentac                 G   s   |   |tdt ƒ¡S r4   ©r3   r   ÚCYANr7   r   r   r   r   p   s    zcolored.cyanc                 G   s   |   |tdt ƒ¡S r4   ©r3   r   ÚWHITEr7   r   r   r   r   s   s    zcolored.whitec                 C   s   t |  ¡ ƒS r	   )Úreprr&   r,   r   r   r   Ú__repr__v   s    zcolored.__repr__c                 G   s   |   |td ¡S )Né   ©r3   ÚOP_SEQr7   r   r   r   Úboldy   s    zcolored.boldc                 G   s   |   |td ¡S )Né   rI   r7   r   r   r   Ú	underline|   s    zcolored.underlinec                 G   s   |   |td ¡S )Né   rI   r7   r   r   r   Úblink   s    zcolored.blinkc                 G   s   |   |td ¡S )Né   rI   r7   r   r   r   Úreverse‚   s    zcolored.reversec                 G   s   |   |td ¡S )Nr   rI   r7   r   r   r   Úbright…   s    zcolored.brightc                 G   s   |   |tdt ƒ¡S ©Né(   r8   r7   r   r   r   Úiredˆ   s    zcolored.iredc                 G   s   |   |tdt ƒ¡S rS   r:   r7   r   r   r   Úigreen‹   s    zcolored.igreenc                 G   s   |   |tdt ƒ¡S rS   r<   r7   r   r   r   ÚiyellowŽ   s    zcolored.iyellowc                 G   s   |   |tdt ƒ¡S rS   r>   r7   r   r   r   Úiblue‘   s    zcolored.ibluec                 G   s   |   |tdt ƒ¡S rS   r@   r7   r   r   r   Úimagenta”   s    zcolored.imagentac                 G   s   |   |tdt ƒ¡S rS   rB   r7   r   r   r   Úicyan—   s    zcolored.icyanc                 G   s   |   |tdt ƒ¡S rS   rD   r7   r   r   r   Úiwhiteš   s    zcolored.iwhitec                 G   s   |   |pdgt¡S r%   )r3   r/   r7   r   r   r   Úreset   s    zcolored.resetc                 C   s   t | ƒt |ƒ S r	   r    )r   Úotherr   r   r   Ú__add__    s    zcolored.__add__N)"Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   r+   r&   r.   r1   r3   r   r   r   r   r   r   r   r   rG   rK   rM   rO   rQ   rR   rU   rV   rW   rX   rY   rZ   r[   r\   r^   r   r   r   r   r   !   s>   
r   c                   C   s   t j ¡ otS r	   )ÚsysÚstdinÚisattyr   r   r   r   r   Úsupports_images¤   s    rf   c              
   C   sL   t j| dd4}t | ¡ ¡}t|tƒr,|n| d¡W  5 Q R £ S Q R X d S )NÚrb)ÚmodeÚascii)ÚcodecsÚopenÚbase64Ú	b64encodeÚreadÚ
isinstancer!   Údecode)ÚpathÚfhÚencodedr   r   r   Ú_read_as_base64¨   s    rt   rH   c                 K   s   dt ||t| ƒtf S )Nz2
%s1337;File=inline=%d;preserveAspectRatio=%d:%s%s)Ú_IMG_PRErt   Ú	_IMG_POST)rq   ÚinlineZpreserve_aspect_ratior   r   r   r   Úimgcat®   s       þrx   )rH   r   )$rb   rl   rj   ÚosÚplatformrc   Ú	functoolsr   Ú__all__Úranger6   r9   r;   r=   r?   rA   rC   rE   rJ   r/   r
   Úsystemr   Úenvironr   r   r   Ú
startswithZTERM_IS_SCREENru   rv   r   r   rf   rt   rx   r   r   r   r   Ú<module>   s.    