o ‡ÎÖaÅ-ã@sbdZddlmZddlmZddlmZddgZGdd„dƒZGd d„deƒZ Gd d„de ƒ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. é)Ú Formatter)Úcodes)Ú ansicolorsÚTerminal256FormatterÚTerminalTrueColorFormatterc@s6eZdZd dd„Zdd„Zdd„Zd d „Zd d „ZdS)ÚEscapeSequenceNFcCs"||_||_||_||_||_dS©N)ÚfgÚbgÚboldÚ underlineÚitalic)Úselfr r r r r ©rúA/usr/lib/python3/dist-packages/pygments/formatters/terminal256.pyÚ__init__#s  zEscapeSequence.__init__cCst|ƒr dd |¡dSdS)Nz[ú;ÚmÚ)ÚlenÚjoin©rÚattrsrrrÚescape*szEscapeSequence.escapecCsøg}|jdur1|jtvr&t|j dd¡}d|vrd|_| |dd…¡n | ddd |jf¡|jdur_|jtvrTt|j dd¡}| tt |dd…ƒd ƒ¡n | d dd |jf¡|jrg| d ¡|j ro| d ¡|j rw| d¡|  |¡S)NÚansirz;01mTééÚ38Ú5z%ié Ú48Ú01Ú04Ú03) r rrÚreplacer ÚappendÚextendr ÚstrÚintr r r)rrÚescrrrÚ color_string/s(         zEscapeSequence.color_stringc Cs®g}|jr| ddt|jdƒt|jdƒt|jdƒf¡|jr:| ddt|jdƒt|jdƒt|jdƒf¡|jrB| d¡|jrJ| d¡|jrR| d ¡| |¡S) NrÚ2rérr r!r"r#) r r&r'r r r%r r rrrrrÚtrue_color_stringIs22    z EscapeSequence.true_color_stringcCsRg}|jdur | d¡|jdur| d¡|js|js|jr$| d¡| |¡S)NÚ39Ú49Ú00)r r%r r r r rrrrrÚ reset_stringWs      zEscapeSequence.reset_string)NNFFF)Ú__name__Ú __module__Ú __qualname__rrr*r-r1rrrrr"s   rc@s`eZdZdZdZgd¢ZgZdd„Zdd„Zdd „Z d d „Z d d „Z dd„Z dd„Z dd„ZdS)raÛ 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 ` 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Ú256cKsjtj|fi|¤Žg|_i|_i|_d|v|_d|v|_d|v|_| ¡|  ¡|  dd¡|_ d|_ dS)NÚnoboldÚ nounderlineÚnoitalicÚlinenosFr) rrÚ xterm_colorsÚ best_matchÚ style_stringÚuseboldÚ useunderlineÚ useitalicÚ_build_color_tableÚ _setup_stylesÚgetr<Ú_lineno)rÚoptionsrrrr‡s    zTerminal256Formatter.__init__cCsB|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}tdƒD]!}||dd}||dd}||d}|j |||f¡qftddƒD]}d|d}|j |||f¡qdS)N)rrr)éÍrr)rrHr)rHrHr)rréî)rHrrH)rrHrH)éårJrJ)érKrK)éÿrr)rrLr)rLrLr)é\rMrL)rLrrL)rrLrL)rLrLrL)ré_é‡é¯é×rLéÙé$ér,éér)r=r%Úrange)rÚ valuerangeÚiÚrÚgÚbÚvrrrrC˜s4                   þz'Terminal256Formatter._build_color_tablec Csrd}d}tddƒD]-}|j|}||d}||d} ||d} ||| | | | } | |kr6|}| }q |S)Niréþr,r)rWr=) rrZr[r\ÚdistanceÚmatchrYÚvaluesÚrdÚgdÚbdÚdrrrÚ_closest_color¼s    €z#Terminal256Formatter._closest_colorcCs’|j |d¡}|tvr|}||j|<|durGz tt|ƒdƒ}Wn ty*d}Ynw|d?d@}|d?d@}|d@}| |||¡}||j|<|S)NérrLrV)r>rErr(r'Ú ValueErrorrf)rÚcolorÚindexÚrgbrZr[r\rrrÚ _color_indexÍs   ÿ   z!Terminal256Formatter._color_indexcCsÔ|jD]d\}}tƒ}|dr| |d¡|_n |dr#| |d¡|_|dr0| |d¡|_n |dr<| |d¡|_|jrF|drFd|_|jrP|drPd|_|j rZ|drZd|_ |  ¡|  ¡f|j t|ƒ<qdS) NÚ ansicolorriÚ bgansicolorÚbgcolorr Tr r )Ústylerrlr r r@r rAr rBr r*r1r?r'©rÚttypeÚndefrrrrrDàs(ÿïz"Terminal256Formatter._setup_stylescCs4|jd7_| d|jdkrdpd|jf¡dS)Nr,z%s%04d: Ú r)rFÚwrite)rÚoutfilerrrÚ _write_linenoõs&z"Terminal256Formatter._write_linenocCst |||¡Sr)rÚformat)rÚ tokensourcervrrrrxùszTerminal256Formatter.formatc Csø|jr| |¡|D]e\}}d}|rh|rhzC|jt|ƒ\}}| d¡}|dd…D]} | r6| || |¡|jr?| |¡q)| d¡q)|drT| ||d|¡d}Wn tyc|j}Ynw|rh|s|ro| |¡q |jrz| d¡dSdS)NTrtéÿÿÿÿF)r<rwr?r'ÚsplitruÚKeyErrorÚparent) rryrvrrÚvalueÚ not_foundÚonÚoffÚsplÚlinerrrÚformat_unencodedüs6       þê €ÿz%Terminal256Formatter.format_unencodedN)r2r3r4Ú__doc__ÚnameÚaliasesÚ filenamesrrCrfrlrDrwrxr„rrrrrbs $ c@s8eZdZdZdZgd¢ZgZdd„Zdd„Zdd „Z d S) ra} 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Ú16mcCsdSrr)rrrrrC7sz-TerminalTrueColorFormatter._build_color_tablecCsRz tt|ƒdƒ}Wn tyYdSw|d?d@}|d?d@}|d@}|||fS)NrgrLrV)r(r'rh)rrirkrZr[r\rrrÚ _color_tuple:s ÿ   z'TerminalTrueColorFormatter._color_tuplecCs |jD]J\}}tƒ}|dr| |d¡|_|dr"| |d¡|_|jr,|dr,d|_|jr6|dr6d|_|j r@|dr@d|_ |  ¡|  ¡f|j t|ƒ<qdS)Nriror Tr r )rprrr r r@r rAr rBr r-r1r?r'rqrrrrDDs ÿôz(TerminalTrueColorFormatter._setup_stylesN) r2r3r4r…r†r‡rˆrCrrDrrrrr%s  N) r…Úpygments.formatterrÚpygments.consolerÚpygments.stylerÚ__all__rrrrrrrÚs   @D