o
    	ȷe-                     @   sb   d 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-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )	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   V/var/www/ideatree/venv/lib/python3.10/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 ur1| j tv r&t| j dd }d|v rd| _||dd  n|ddd	| j  f | jd ur_| jtv rTt| jdd }|tt	|dd d
  n|ddd	| j f | jrg|d | j
ro|d | jrw|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_string/   s(   



 



zEscapeSequence.color_stringc              	   C   s   g }| j r|ddt| j d t| j d t| j d f | jr:|ddt| jd t| jd t| jd f | jrB|d | jrJ|d | jrR|d	 | |S )
Nr   2r      r   r    r!   r"   r#   )	r	   r&   r'   r
   r   r%   r   r   r   r   r   r   r   true_color_stringI   s   22



z EscapeSequence.true_color_stringc                 C   sR   g }| j d ur|d | jd ur|d | js| js| jr$|d | |S )N394900)r	   r%   r
   r   r   r   r   r   r   r   r   reset_stringW   s   





zEscapeSequence.reset_string)NNFFF)__name__
__module____qualname__r   r   r*   r-   r1   r   r   r   r   r   "   s    
r   c                   @   s`   e Zd ZdZdZg d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).
    Terminal256)terminal256
console256256c                 K   sj   t j| fi | g | _i | _i | _d|v| _d|v| _d|v| _|   | 	  |
dd| _d| _d S )NnoboldnounderlinenoitaliclinenosFr   )r   r   xterm_colors
best_matchstyle_stringusebolduseunderline	useitalic_build_color_table_setup_stylesgetr<   _lineno)r   optionsr   r   r   r      s   



zTerminal256Formatter.__init__c                 C   sB  | 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}tdD ]!}||d d  }||d d  }||d  }| j |||f qftddD ]}d|d  }| j |||f qd S )N)r   r   r   )   r   r   )r   rH   r   )rH   rH   r   )r   r      )rH   r   rH   )r   rH   rH   )   rJ   rJ   )   rK   rK   )   r   r   )r   rL   r   )rL   rL   r   )\   rM   rL   )rL   r   rL   )r   rL   rL   )rL   rL   rL   )r   _            rL      $      r,         r   )r=   r%   range)r   
valuerangeirgbvr   r   r   rC      s4   z'Terminal256Formatter._build_color_tablec                 C   sr   d}d}t ddD ]-}| j| }||d  }||d  }	||d  }
|| |	|	  |
|
  }||k r6|}|}q	|S )Ni r      r,   r   )rW   r=   )r   rZ   r[   r\   distancematchrY   valuesrdgdbddr   r   r   _closest_color   s   
z#Terminal256Formatter._closest_colorc                 C   s   | j |d }|tv r|}|| j |< |d u rGz	tt|d}W n ty*   d}Y nw |d? d@ }|d? d@ }|d@ }| |||}|| j |< |S )N   r   rL   rV   )r>   rE   r   r(   r'   
ValueErrorrf   )r   colorindexrgbrZ   r[   r\   r   r   r   _color_index   s    

z!Terminal256Formatter._color_indexc                 C   s   | j D ]d\}}t }|d r| |d |_n|d r#| |d |_|d r0| |d |_n|d r<| |d |_| jrF|d rFd|_| jrP|d rPd|_| j	rZ|d rZd|_
| | f| jt|< qd S )	N	ansicolorri   bgansicolorbgcolorr   Tr   r   )styler   rl   r	   r
   r@   r   rA   r   rB   r   r*   r1   r?   r'   r   ttypendefr   r   r   r   rD      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   )rF   write)r   outfiler   r   r   _write_lineno   s   &z"Terminal256Formatter._write_linenoc                 C   s   t | ||S r   )r   format)r   tokensourcerv   r   r   r   rx      s   zTerminal256Formatter.formatc           
   	   C   s   | j r| | |D ]e\}}d}|rh|rhzC| jt| \}}|d}|d d D ]}	|	r6|||	 |  | j r?| | q)|d q)|d rT|||d  |  d}W n tyc   |j}Y nw |rh|s|ro|| q
| j rz|d d S d S )NTrt   F)r<   rw   r?   r'   splitru   KeyErrorparent)
r   ry   rv   rr   value	not_foundonoffsplliner   r   r   format_unencoded   s6   



z%Terminal256Formatter.format_unencodedN)r2   r3   r4   __doc__namealiases	filenamesr   rC   rf   rl   rD   rw   rx   r   r   r   r   r   r   b   s     $c                   @   s8   e Zd ZdZdZg d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'``).
    TerminalTrueColor)terminal16m
console16m16mc                 C   s   d S r   r   )r   r   r   r   rC   7  s   z-TerminalTrueColorFormatter._build_color_tablec                 C   sR   z	t t|d}W n
 ty   Y d S w |d? d@ }|d? d@ }|d@ }|||fS )Nrg   rL   rV   )r(   r'   rh   )r   ri   rk   rZ   r[   r\   r   r   r   _color_tuple:  s   
z'TerminalTrueColorFormatter._color_tuplec                 C   s   | j D ]J\}}t }|d r| |d |_|d r"| |d |_| jr,|d r,d|_| jr6|d r6d|_| j	r@|d r@d|_
| | f| jt|< qd S )Nri   ro   r   Tr   r   )rp   r   r   r	   r
   r@   r   rA   r   rB   r   r-   r1   r?   r'   rq   r   r   r   rD   D  s    z(TerminalTrueColorFormatter._setup_stylesN)
r2   r3   r4   r   r   r   r   rC   r   rD   r   r   r   r   r   %  s    
N)r   pygments.formatterr   pygments.consoler   pygments.styler   __all__r   r   r   r   r   r   r   <module>   s    @ D