o a-@sbdZddlmZddlmZddlmZddgZGdddZGd ddeZ Gd dde 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) ansicolorsTerminal256FormatterTerminalTrueColorFormatterc@s6eZdZd ddZddZddZd d Zd d ZdS)EscapeSequenceNFcCs"||_||_||_||_||_dSN)fgbgbold underlineitalic)selfr r r r r rA/usr/lib/python3/dist-packages/pygments/formatters/terminal256.py__init__#s  zEscapeSequence.__init__cCst|r dd|dSdS)Nz[;m)lenjoinrattrsrrrescape*szEscapeSequence.escapecCsg}|jdur1|jtvr&t|jdd}d|vrd|_||ddn |ddd |jf|jdur_|jtvrTt|jdd}|tt |ddd n |d dd |jf|jrg|d |j ro|d |j rw|d| |S)Nansirz;01mT385z%i 48010403) r rrreplacer appendextendr strintr r r)rrescrrr color_string/s(         zEscapeSequence.color_stringc Csg}|jr|ddt|jdt|jdt|jdf|jr:|ddt|jdt|jdt|jdf|jrB|d|jrJ|d|jrR|d ||S) Nr2rrr r!r"r#) r r&r'r r r%r r rrrrrtrue_color_stringIs22    z EscapeSequence.true_color_stringcCsRg}|jdur |d|jdur|d|js|js|jr$|d||S)N394900)r r%r r r r rrrrr reset_stringWs      zEscapeSequence.reset_string)NNFFF)__name__ __module__ __qualname__rrr*r-r1rrrrr"s   rc@s`eZdZdZdZgdZgZddZddZdd Z d d Z d d Z ddZ ddZ ddZdS)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 console256256cKsjtj|fi|g|_i|_i|_d|v|_d|v|_d|v|_|| | dd|_ d|_ dS)Nnobold nounderlinenoitaliclinenosFr) rr xterm_colors best_match style_stringusebold useunderline useitalic_build_color_table _setup_stylesgetr<_lineno)roptionsrrrrs    zTerminal256Formatter.__init__cCsB|jd|jd|jd|jd|jd|jd|jd|jd|jd |jd |jd |jd |jd |jd|jd|jdd}tdD]!}||dd}||dd}||d}|j|||fqftddD]}d|d}|j|||fqdS)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 valuerangeirgbvrrrrCs4                   z'Terminal256Formatter._build_color_tablec Csrd}d}tddD]-}|j|}||d}||d} ||d} ||| | | | } | |kr6|}| }q |S)Nirr,r)rWr=) rrZr[r\distancematchrYvaluesrdgdbddrrr_closest_colors    z#Terminal256Formatter._closest_colorcCs|j|d}|tvr|}||j|<|durGz tt|d}Wn ty*d}Ynw|d?d@}|d?d@}|d@}||||}||j|<|S)NrrLrV)r>rErr(r' ValueErrorrf)rcolorindexrgbrZr[r\rrr _color_indexs      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 bgansicolorbgcolorr Tr r )stylerrlr r r@r rAr rBr r*r1r?r'rttypendefrrrrrDs(z"Terminal256Formatter._setup_stylescCs4|jd7_|d|jdkrdpd|jfdS)Nr,z%s%04d:  r)rFwrite)routfilerrr _write_linenos&z"Terminal256Formatter._write_linenocCst|||Sr)rformat)r tokensourcervrrrrxszTerminal256Formatter.formatc Cs|jr|||D]e\}}d}|rh|rhzC|jt|\}}|d}|ddD]} | r6||| ||jr?||q)|dq)|drT|||d|d}Wn tyc|j}Ynw|rh|s|ro||q |jrz|ddSdS)NTrtF)r<rwr?r'splitruKeyErrorparent) rryrvrrvalue not_foundonoffspllinerrrformat_unencodeds6        z%Terminal256Formatter.format_unencodedN)r2r3r4__doc__namealiases filenamesrrCrfrlrDrwrxrrrrrrbs $ c@s8eZdZdZdZgdZgZddZddZdd 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 console16m16mcCsdSrr)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) r2r3r4rrrrrCrrDrrrrr%s  N) rpygments.formatterrpygments.consolerpygments.styler__all__rrrrrrrs   @D