U
    Z+d                     @   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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rdndZerd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)isatty)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-ucduq0nd/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'   L   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   embedQ   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__W   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   )r4   r   BLACKr   r   r   r   r   r   `   s    zcolored.blackc                 G   s   |  |tdt S r5   r4   r   REDr8   r   r   r   r   c   s    zcolored.redc                 G   s   |  |tdt S r5   r4   r   GREENr8   r   r   r   r   f   s    zcolored.greenc                 G   s   |  |tdt S r5   r4   r   YELLOWr8   r   r   r   r   i   s    zcolored.yellowc                 G   s   |  |tdt S r5   r4   r   BLUEr8   r   r   r   r   l   s    zcolored.bluec                 G   s   |  |tdt S r5   r4   r   MAGENTAr8   r   r   r   r   o   s    zcolored.magentac                 G   s   |  |tdt S r5   r4   r   CYANr8   r   r   r   r   r   s    zcolored.cyanc                 G   s   |  |tdt S r5   r4   r   WHITEr8   r   r   r   r   u   s    zcolored.whitec                 C   s   t |  S r
   )reprr'   r-   r   r   r   __repr__x   s    zcolored.__repr__c                 G   s   |  |td S )N   r4   OP_SEQr8   r   r   r   bold{   s    zcolored.boldc                 G   s   |  |td S )N   rJ   r8   r   r   r   	underline~   s    zcolored.underlinec                 G   s   |  |td S )N   rJ   r8   r   r   r   blink   s    zcolored.blinkc                 G   s   |  |td S )N   rJ   r8   r   r   r   reverse   s    zcolored.reversec                 G   s   |  |td S )Nr   rJ   r8   r   r   r   bright   s    zcolored.brightc                 G   s   |  |tdt S N(   r9   r8   r   r   r   ired   s    zcolored.iredc                 G   s   |  |tdt S rT   r;   r8   r   r   r   igreen   s    zcolored.igreenc                 G   s   |  |tdt S rT   r=   r8   r   r   r   iyellow   s    zcolored.iyellowc                 G   s   |  |tdt S rT   r?   r8   r   r   r   iblue   s    zcolored.ibluec                 G   s   |  |tdt S rT   rA   r8   r   r   r   imagenta   s    zcolored.imagentac                 G   s   |  |tdt S rT   rC   r8   r   r   r   icyan   s    zcolored.icyanc                 G   s   |  |tdt S rT   rE   r8   r   r   r   iwhite   s    zcolored.iwhitec                 G   s   |  |pdgtS r&   )r4   r0   r8   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/   r2   r4   r   r   r   r   r   r   r   r   rH   rL   rN   rP   rR   rS   rV   rW   rX   rY   rZ   r[   r\   r]   r_   r   r   r   r   r   #   s>   
r   c                   C   s   t tjotS r
   )r   sysstdinr   r   r   r   r   supports_images   s    rf   c              
   C   sN   t j| dd6}t| }t|dkr.|n|dW  5 Q R  S Q R X d S )Nrb)moder"   ascii)codecsopenbase64	b64encodereadtypedecode)pathfhencodedr   r   r   _read_as_base64   s    rt   rI   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   )rI   r   )&rc   rl   rj   osplatformrd   	functoolsr   Zcelery.platformsr   __all__ranger7   r:   r<   r>   r@   rB   rD   rF   rK   r0   r   systemr   environr   r   r   
startswithZTERM_IS_SCREENru   rv   r   r   rf   rt   rx   r   r   r   r   <module>   s0    