
    Mh-                         d Z ddlmZ ddlmZ ddlmZ ddgZ G d d          Z G d	 de          Z	 G 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-2025 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )	Formatter)codes)
ansicolorsTerminal256FormatterTerminalTrueColorFormatterc                   .    e Zd ZddZd Zd Zd Zd ZdS )	EscapeSequenceNFc                 L    || _         || _        || _        || _        || _        d S N)fgbgbold	underlineitalic)selfr   r   r   r   r   s         _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pygments/formatters/terminal256.py__init__zEscapeSequence.__init__#   s)    	"    c                 Z    t          |          rdd                    |          z   dz   S dS )Nz[;m )lenjoinr   attrss     r   escapezEscapeSequence.escape*   s/    u:: 	3SXXe__,s22rr   c           	         g }| j         }| j         t          v rOt          | j                             dd                   }d|v rd| _        |                    |dd                    n |                    ddd	| j         z  f           | j        | j        t          v rat          | j                            dd                   }|                    t          t          |dd                   d
z                        n |                    ddd	| j        z  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   escs      r   color_stringzEscapeSequence.color_string/   sf   7w*$$DGOOF2667S== $DIS1X&&&&dC89997w*$$DGOOF2667SS1Xr!1223333dC89999 	LL> 	LL; 	LL{{5!!!r   c           
      |   g }| j         rb|                    ddt          | j         d                   t          | j         d                   t          | j         d                   f           | j        rb|                    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   s     r   true_color_stringz EscapeSequence.true_color_stringI   s   7 	YLL$S__c$'!*oos47ST:WXXX7 	YLL$S__c$'!*oos47ST:WXXX9 	LL> 	LL; 	LL{{5!!!r   c                     g }| j         |                    d           | j        |                    d           | j        s| j        s| j        r|                    d           |                     |          S )N394900)r   r*   r   r   r   r   r   r   s     r   reset_stringzEscapeSequence.reset_stringW   s{    7LL7LL9 	 	$+ 	LL{{5!!!r   )NNFFF)__name__
__module____qualname__r   r   r/   r3   r8    r   r   r	   r	   "   sd             
" " "4" " "" " " " "r   r	   c                   R    e Zd ZdZdZg dZg Zd Zd Zd Z	d Z
d Zd	 Zd
 Z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                    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getrF   _lineno)r   optionss     r   r   zTerminal256Formatter.__init__   s    4++7+++w.)8#72!!!{{9e44r   c                 f   | 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 ]F}||dz  dz           }||dz  dz           }||dz           }| j                             |||f           Gt          dd          D ]'}d|dz  z   }| j                             |||f           (d S )N)r   r   r   )   r   r   )r   rS   r   )rS   rS   r   )r   r      )rS   r   rS   )r   rS   rS   )   rU   rU   )   rV   rV   )   r   r   )r   rW   r   )rW   rW   r   )\   rX   rW   )rW   r   rW   )r   rW   rW   )rW   rW   rW   )r   _            rW      $      r2         r$   )rG   r*   range)r   
valuerangeirgbvs          r   rM   z'Terminal256Formatter._build_color_table   sB    	  !3444  !3444  !3444  !3444  !3444  !3444  !3444  !3444  !3444  !3444  !3444  !3444  !3444  !3444  !3444  !3444 :
s 	0 	0AAGq=)AAFa<(A1q5!A$$aAY//// q" 	0 	0AAF
A$$aAY////	0 	0r   c                     d}d}t          dd          D ]K}| j        |         }||d         z
  }||d         z
  }	||d         z
  }
||z  |	|	z  z   |
|
z  z   }||k     r|}|}L|S )Ni r      r2   r    )rb   rG   )r   re   rf   rg   distancematchrd   valuesrdgdbdds               r   _closest_colorz#Terminal256Formatter._closest_color   s    q# 
	 
	A&q)FVAYBVAYBVAYB222%A8||r   c                 8   | j                             |d           }|t          v r|}|| j         |<   |g	 t          t	          |          d          }n# t
          $ r d}Y nw xY w|dz	  dz  }|dz	  dz  }|dz  }|                     |||          }|| j         |<   |S )N   r   rW   ra   )rH   rO   r   r-   r,   
ValueErrorrr   )r   colorindexrgbre   rf   rg   s          r   _color_indexz!Terminal256Formatter._color_index   s    ##E400JE%*DOE"=#e**b))    d"AT!Ad
A''1a00E%*DOE"s   A A! A!c                    | j         D ]5\  }}t                      }|d         r!|                     |d                   |_        n(|d         r |                     |d                   |_        |d         r!|                     |d                   |_        n(|d         r |                     |d                   |_        | j        r|d         rd|_        | j        r|d         rd|_        | j	        r|d         rd|_
        |                                |                                f| j        t          |          <   7d S )	N	ansicolorrv   bgansicolorbgcolorr   Tr   r   )styler	   ry   r   r   rJ   r   rK   r   rL   r   r/   r8   rI   r,   r   ttypendefr   s       r   rN   z"Terminal256Formatter._setup_styles   sZ   : 	D 	DKE4#%%FK  = --d;.?@@		g = --d7m<<	M" ? --d=.ABB		i ? --d9o>>	| #V #"  (T+%6 (#' ~ %$x. % $-3-@-@-B-B-3-@-@-B-B-DDc%jj))#	D 	Dr   c                 ~    | xj         dz  c_         |                    d| j         dk    rdpd| j         fz             d S )Nr2   z%s%04d: 
r   )rP   write)r   outfiles     r   _write_linenoz"Terminal256Formatter._write_lineno   sG    jDLA$5$>$$D"dl#SSTTTTTr   c                 .    t          j        | ||          S r   )r   format)r   tokensourcer   s      r   r   zTerminal256Formatter.format   s    k7;;;r   c                 p   | j         r|                     |           |D ]\  }}d}|r|r	 | j        t          |                   \  }}|                    d          }|d d         D ]Q}	|	r|                    ||	z   |z              | j         r|                     |           <|                    d           R|d         r!|                    ||d         z   |z              d}n# t          $ r
 |j        }Y nw xY w|r||r|                    |           | j         r|                    d           d S d S )NTr   F)rF   r   rI   r,   splitr   KeyErrorparent)
r   r   r   r   value	not_foundonoffspllines
             r   format_unencodedz%Terminal256Formatter.format_unencoded   s   < 	(w'''' 	% 	%LE5I )I ))"/E

;GB  ++d++C #CRC 0 0 ;#MM"t)c/:::< 0 ..w7777#MM$////2w :b3r7lS&8999 %II   ) ) )!LEEE)-  )I )6  %e$$$< 	 MM$	  	 s   B9C%%C98C9N)r9   r:   r;   __doc__namealiases	filenamesr   rM   rr   ry   rN   r   r   r   r<   r   r   r   r   b   s         @ D222GI  ""0 "0 "0H  "  &D D D*U U U< < <%  %  %  %  % r   c                   4    e Zd ZdZdZg dZg Zd Zd Z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                     d S r   r<   )r   s    r   rM   z-TerminalTrueColorFormatter._build_color_table7  s    r   c                     	 t          t          |          d          }n# t          $ r Y d S w xY w|dz	  dz  }|dz	  dz  }|dz  }|||fS )Nrt   rW   ra   )r-   r,   ru   )r   rv   rx   re   rf   rg   s         r   _color_tuplez'TerminalTrueColorFormatter._color_tuple:  sq    	c%jj"%%CC 	 	 	44	BY$AX$J1ays     
..c                    | j         D ]\  }}t                      }|d         r |                     |d                   |_        |d         r |                     |d                   |_        | j        r|d         rd|_        | j        r|d         rd|_        | j	        r|d         rd|_
        |                                |                                f| j        t          |          <   d S )Nrv   r}   r   Tr   r   )r~   r	   r   r   r   rJ   r   rK   r   rL   r   r3   r8   rI   r,   r   s       r   rN   z(TerminalTrueColorFormatter._setup_stylesD  s   : 	D 	DKE4#%%FG} = --d7m<<	I ? --d9o>>	| #V #"  (T+%6 (#' ~ %$x. % $-3-E-E-G-G-3-@-@-B-B-DDc%jj))	D 	Dr   N)
r9   r:   r;   r   r   r   r   rM   r   rN   r<   r   r   r   r   %  sg          D222GI    D D D D Dr   N)r   pygments.formatterr   pygments.consoler   pygments.styler   __all__r	   r   r   r<   r   r   <module>r      s    2 ) ( ( ( ( ( " " " " " " % % % % % % "#?
@=" =" =" =" =" =" =" ="@         9      F-D -D -D -D -D!5 -D -D -D -D -Dr   