B
    ë¹`Ï-  ã               @   sj   d Z ddlZddlmZ ddlmZ ddlmZ ddgZG dd	„ d	ƒZ	G d
d„ deƒZ
G dd„ de
ƒZdS )a¿  
    pygments.formatters.terminal256
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Formatter for 256-color terminal output with ANSI sequences.

    RGB-to-XTERM color conversion routines adapted from xterm256-conv
    tool (http://frexx.de/xterm-256-notes/data/xterm256-conv2.tar.bz2)
    by Wolfgang Frisch.

    Formatter version 1.

    :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    N)Ú	Formatter)Úcodes)Ú
ansicolorsÚTerminal256FormatterÚTerminalTrueColorFormatterc               @   s6   e Zd Zddd„Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚEscapeSequenceNFc             C   s"   || _ || _|| _|| _|| _d S )N)ÚfgÚbgÚboldÚ	underlineÚitalic)Úselfr   r	   r
   r   r   © r   úg/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/pygments/formatters/terminal256.pyÚ__init__%   s
    zEscapeSequence.__init__c             C   s   t |ƒrdd |¡ d S dS )Nz[ú;ÚmÚ )ÚlenÚjoin)r   Úattrsr   r   r   Úescape,   s    zEscapeSequence.escapec             C   sø   g }| j d k	rb| j tkrLt| j  dd¡ }d|kr8d| _| |dd… ¡ n| ddd	| j  f¡ | jd k	r¾| jtkr¨t| j dd¡ }| tt	|dd… ƒd
 ƒ¡ n| ddd	| j f¡ | jrÎ| d¡ | j
rÞ| d¡ | jrî| d¡ |  |¡S )NÚansir   z;01mTé   é   Ú38Ú5z%ié
   Ú48Ú01Ú04Ú03)r   r   r   Úreplacer
   ÚappendÚextendr	   ÚstrÚintr   r   r   )r   r   Úescr   r   r   Úcolor_string1   s(    



 


zEscapeSequence.color_stringc          	   C   s®   g }| j r<| ddt| j d ƒt| j d ƒt| j d ƒf¡ | jrt| ddt| jd ƒt| jd ƒt| jd ƒf¡ | jr„| d¡ | jr”| d¡ | jr¤| d	¡ |  |¡S )
Nr   Ú2r   é   r   r   r   r    r!   )	r   r$   r%   r	   r
   r#   r   r   r   )r   r   r   r   r   Útrue_color_stringK   s    22


z EscapeSequence.true_color_stringc             C   sR   g }| j d k	r| d¡ | jd k	r,| d¡ | js>| js>| jrH| d¡ |  |¡S )NZ39Z49Z00)r   r#   r	   r
   r   r   r   )r   r   r   r   r   Úreset_stringY   s    




zEscapeSequence.reset_string)NNFFF)Ú__name__Ú
__module__Ú__qualname__r   r   r(   r+   r,   r   r   r   r   r   $   s
   
r   c               @   sb   e Zd ZdZdZdddgZg 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S )r   aÛ  
    Format tokens with ANSI color sequences, for output in a 256-color
    terminal or console.  Like in `TerminalFormatter` color sequences
    are terminated at newlines, so that paging the output works correctly.

    The formatter takes colors from a style defined by the `style` option
    and converts them to nearest ANSI 256-color escape sequences. Bold and
    underline attributes from the style are preserved (and displayed).

    .. versionadded:: 0.9

    .. versionchanged:: 2.2
       If the used style defines foreground colors in the form ``#ansi*``, then
       `Terminal256Formatter` will map these to non extended foreground color.
       See :ref:`AnsiTerminalStyle` for more information.

    .. versionchanged:: 2.4
       The ANSI color names have been updated with names that are easier to
       understand and align with colornames of other projects and terminals.
       See :ref:`this table <new-ansi-color-names>` for more information.


    Options accepted:

    `style`
        The style to use, can be a string or a Style subclass (default:
        ``'default'``).

    `linenos`
        Set to ``True`` to have line numbers on the terminal output as well
        (default: ``False`` = no line numbers).
    ZTerminal256Zterminal256Z
console256Z256c             K   sf   t j| f|Ž g | _i | _i | _d|k| _d|k| _d|k| _|  ¡  |  	¡  | 
dd¡| _d| _d S )NZnoboldZnounderlineZnoitalicÚlinenosFr   )r   r   Úxterm_colorsÚ
best_matchÚstyle_stringÚuseboldÚuseunderlineÚ	useitalicÚ_build_color_tableÚ_setup_stylesÚgetr0   Ú_lineno)r   Úoptionsr   r   r   r   ‰   s    


zTerminal256Formatter.__init__c             C   sL  | j  d¡ | j  d¡ | j  d¡ | j  d¡ | j  d¡ | j  d¡ | j  d¡ | j  d¡ | j  d	¡ | j  d
¡ | j  d¡ | j  d¡ | j  d¡ | j  d¡ | j  d¡ | j  d¡ d}xNtdƒD ]B}||d d  }||d d  }||d  }| j  |||f¡ qÎW x2tddƒD ]$}d|d  }| j  |||f¡ q W d S )N)r   r   r   )éÍ   r   r   )r   r<   r   )r<   r<   r   )r   r   éî   )r<   r   r<   )r   r<   r<   )éå   r>   r>   )é   r?   r?   )éÿ   r   r   )r   r@   r   )r@   r@   r   )é\   rA   r@   )r@   r   r@   )r   r@   r@   )r@   r@   r@   )r   é_   é‡   é¯   é×   r@   éÙ   é$   é   r*   é   é   r   )r1   r#   Úrange)r   Z
valuerangeÚiÚrÚgÚbÚvr   r   r   r7   š   s2    z'Terminal256Formatter._build_color_tablec             C   sv   d}d}xht ddƒD ]Z}| j| }||d  }||d  }	||d  }
|| |	|	  |
|
  }||k r|}|}qW |S )Ni r   éþ   r*   r   )rK   r1   )r   rM   rN   rO   ZdistanceÚmatchrL   ÚvaluesÚrdÚgdZbdÚdr   r   r   Ú_closest_color¾   s    
z#Terminal256Formatter._closest_colorc             C   s”   | j  |d ¡}|tkr$|}|| j |< |d krytt|ƒdƒ}W n tk
rV   d}Y nX |d? d@ }|d? d@ }|d@ }|  |||¡}|| j |< |S )Né   r   r@   rJ   )r2   r9   r   r&   r%   Ú
ValueErrorrW   )r   ÚcolorÚindexÚrgbrM   rN   rO   r   r   r   Ú_color_indexÏ   s    


z!Terminal256Formatter._color_indexc             C   sØ   xÒ| j D ]È\}}tƒ }|d r0|  |d ¡|_n|d rH|  |d ¡|_|d rb|  |d ¡|_n|d rz|  |d ¡|_| jrŽ|d rŽd|_| jr¢|d r¢d|_| j	r¶|d r¶d|_
| ¡ | ¡ f| jt|ƒ< qW d S )	NZ	ansicolorrZ   ZbgansicolorÚbgcolorr
   Tr   r   )Ústyler   r]   r   r	   r4   r
   r5   r   r6   r   r(   r,   r3   r%   )r   ÚttypeÚndefr   r   r   r   r8   â   s$    z"Terminal256Formatter._setup_stylesc             C   s4   |  j d7  _ | d| j dkr"dp$d| j f ¡ d S )Nr*   z%s%04d: Ú
r   )r:   Úwrite)r   Úoutfiler   r   r   Ú_write_lineno÷   s    z"Terminal256Formatter._write_linenoc             C   s   t  | ||¡S )N)r   Úformat)r   Útokensourcerd   r   r   r   rf   û   s    zTerminal256Formatter.formatc       
   	   C   s  | j r|  |¡ xÜ|D ]Ô\}}d}x¸|rÚ|rÚyŠ| jt|ƒ \}}| d¡}xF|d d… D ]6}	|	rr| ||	 | ¡ | j r„|  |¡ qX| d¡ qXW |d r°| ||d  | ¡ d}W q$ tk
rÖ   |d d… }Y q$X q$W |r| |¡ qW | j rþ| d¡ d S )NTrb   éÿÿÿÿF)r0   re   r3   r%   Úsplitrc   ÚKeyError)
r   rg   rd   r`   ÚvalueÚ	not_foundÚonÚoffZsplÚliner   r   r   Úformat_unencodedþ   s.    


z%Terminal256Formatter.format_unencodedN)r-   r.   r/   Ú__doc__ÚnameÚaliasesÚ	filenamesr   r7   rW   r]   r8   re   rf   rp   r   r   r   r   r   d   s    
$c               @   s:   e Zd ZdZdZdddgZg Zdd„ Zdd	„ Zd
d„ Z	dS )r   a}  
    Format tokens with ANSI color sequences, for output in a true-color
    terminal or console.  Like in `TerminalFormatter` color sequences
    are terminated at newlines, so that paging the output works correctly.

    .. versionadded:: 2.1

    Options accepted:

    `style`
        The style to use, can be a string or a Style subclass (default:
        ``'default'``).
    ZTerminalTrueColorZterminal16mZ
console16mZ16mc             C   s   d S )Nr   )r   r   r   r   r7   9  s    z-TerminalTrueColorFormatter._build_color_tablec             C   sR   yt t|ƒdƒ}W n tk
r&   d S X |d? d@ }|d? d@ }|d@ }|||fS )NrX   r@   rJ   )r&   r%   rY   )r   rZ   r\   rM   rN   rO   r   r   r   Ú_color_tuple<  s    z'TerminalTrueColorFormatter._color_tuplec             C   s¤   xž| j D ]”\}}tƒ }|d r.|  |d ¡|_|d rF|  |d ¡|_| jrZ|d rZd|_| jrn|d rnd|_| j	r‚|d r‚d|_
| ¡ | ¡ f| jt|ƒ< qW d S )NrZ   r^   r
   Tr   r   )r_   r   ru   r   r	   r4   r
   r5   r   r6   r   r+   r,   r3   r%   )r   r`   ra   r   r   r   r   r8   F  s    z(TerminalTrueColorFormatter._setup_stylesN)
r-   r.   r/   rq   rr   rs   rt   r7   ru   r8   r   r   r   r   r   '  s   

)rq   ÚsysZpygments.formatterr   Zpygments.consoler   Zpygments.styler   Ú__all__r   r   r   r   r   r   r   Ú<module>   s   @ D