|e-tdZddlmZddlmZddlmZddgZGddZGd deZ Gd de Z y ) 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-2023 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. ) Formatter)codes) ansicolorsTerminal256FormatterTerminalTrueColorFormatterc,eZdZddZdZdZdZdZy)EscapeSequenceNcJ||_||_||_||_||_yN)fgbgbold underlineitalic)selfr r rrrs A/usr/lib/python3/dist-packages/pygments/formatters/terminal256.py__init__zEscapeSequence.__init__#s% " cHt|rddj|zdzSy)Nz[;m)lenjoinrattrss rescapezEscapeSequence.escape*s$ u:SXXe_,s2 2rc g}|jv|jtvrCt|jjdd}d|vrd|_|j |ddn!|j ddd |jzf|j|jtvrMt|jjdd}|j tt|ddd zn!|j d dd |jzf|jr|j d |jr|j d |jr|j d|j|S)Nansirz;01mT385z%i 48010403) r rrreplacerappendextendr strintrrr)rrescs r color_stringzEscapeSequence.color_string/s# 77 ww*$DGGOOF267S= $DI S1X& dC89 77 ww*$DGGOOF267 SS1Xr!123 dC89 99 LL  >> LL  ;; LL {{5!!rc fg}|jrX|jddt|jdt|jdt|jdf|jrX|jddt|jdt|jdt|jdf|jr|j d|j r|j d|jr|j d |j|S) Nr"2rr r%r&r'r() r r+r,r rr*rrrrs rtrue_color_stringz EscapeSequence.true_color_stringIs 77 LL$S_c$''!*os477ST:W X 77 LL$S_c$''!*os477ST:W X 99 LL  >> LL  ;; LL {{5!!rcg}|j|jd|j|jd|js|js |j r|jd|j |S)N394900)r r*r rrrrrs r reset_stringzEscapeSequence.reset_stringWsa 77  LL  77  LL  99$++ LL {{5!!r)NNFFF)__name__ __module__ __qualname__rrr/r3r8rrr r "s "4 ""rr cPeZdZdZdZgdZgZdZdZdZ dZ dZ d Z d Z d Zy ) 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 console256256c tj|fi|g|_i|_i|_d|v|_d|v|_d|v|_|j|j|jdd|_ d|_ y)Nnobold nounderlinenoitaliclinenosFr) rr xterm_colors best_match style_stringusebold useunderline useitalic_build_color_table _setup_stylesgetrF_lineno)roptionss rrzTerminal256Formatter.__init__s4+7+w. )8#72 ! {{9e4  rcn|jjd|jjd|jjd|jjd|jjd|jjd|jjd|jjd|jjd |jjd |jjd |jjd |jjd |jjd|jjd|jjdd}tdD]>}||dzdz}||dzdz}||dz}|jj|||f@tddD](}d|dzz}|jj|||f*y)N)rrr)rr)rrSr)rSrSr)rr)rSrrS)rrSrS)rUrU)rVrV)rr)rrWr)rWrWr)\rXrW)rWrrW)rrWrW)rWrWrW)r_rW$r2r$)rGr*range)r valuerangeirgbvs rrMz'Terminal256Formatter._build_color_tables   !34   !34   !34   !34   !34   !34   !34   !34   !34   !34   !34   !34   !34   !34   !34   !34: s 0AAGq=)AAFa<(A1q5!A    $ $aAY /  0q" 0AAF A    $ $aAY / 0rcd}d}tddD]D}|j|}||dz }||dz } ||dz } ||z| | zz| | zz} | |ksA|}| }F|S)Nirr2r )rbrG) rrerfrgdistancematchrdvaluesrdgdbdds r_closest_colorz#Terminal256Formatter._closest_colorsq# A&&q)FVAYBVAYBVAYB22 2%A8|  rc0|jj|d}|tvr|}||j|<|M tt |d}|dz dz}|dz dz}|dz}|j |||}||j|<|S#t $rd}YFwxYw)NrrWra)rHrOrr-r, ValueErrorrr)rcolorindexrgbrerfrgs r _color_indexz!Terminal256Formatter._color_indexs##E40 J E%*DOOE " = #e*b)d"AT!Ad A''1a0E%*DOOE "   sB BBc4|jD]\}}t}|dr|j|d|_n|dr|j|d|_|dr|j|d|_n|dr|j|d|_|j r |drd|_|jr |drd|_|jr |drd|_ |j|jf|jt|< y) N ansicolorrv bgansicolorbgcolorrTrr)styler ryr r rJrrKrrLrr/r8rIr,rttypendefrs rrNz"Terminal256Formatter._setup_styless :: DKE4#%FK  --d;.?@ g --d7m< M" --d=.AB i --d9o> ||V "   T+%6#' ~~$x. $ -3-@-@-B-3-@-@-B-DD  c%j )# Drc|xjdz c_|jd|jdk7xrdxsd|jfzy)Nr2z%s%04d:  r)rPwrite)routfiles r _write_linenoz"Terminal256Formatter._write_linenos=   jDLLA$5$>$$D"dll#SSTrc0tj|||Sr )rformat)r tokensourcers rrzTerminal256Formatter.formatsk7;;rcB|jr|j||D]\}}d}|r|r |jt|\}}|j d}|ddD]J} | r|j || z|z|jr|j|:|j dL|dr|j ||dz|zd}|r|r|s|j ||jr|j dyy#t $r|j}YQwxYw)NTrF)rFrrIr,splitrKeyErrorparent) rrrrvalue not_foundonoffspllines rformat_unencodedz%Terminal256Formatter.format_unencodeds" <<   w '' %LE5II)"//E ;GB ++d+C #CR0#MM"t)c/:<< ..w7#MM$/ 02w b3r7lS&89 %I'I6 e$= %@ << MM$   )!LLE)sBDDDN)r9r:r;__doc__namealiases filenamesrrMrrryrNrrrr<rrrrbsD@ D2GI""0H"&D*U<% rc2eZdZdZdZgdZgZdZdZdZ y)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 console16m16mcyr r<)rs rrMz-TerminalTrueColorFormatter._build_color_table7s rc tt|d}|dz dz}|dz dz}|dz}|||fS#t$rYywxYw)NrtrWra)r-r,ru)rrvrxrerfrgs r _color_tuplez'TerminalTrueColorFormatter._color_tuple:s^ c%j"%CBY$  AX  $J1ay   s 1 ==c|jD]\}}t}|dr|j|d|_|dr|j|d|_|j r |drd|_|jr |drd|_|jr |drd|_ |j|jf|jt|<y)Nrvr}rTrr)r~r rr r rJrrKrrLrr3r8rIr,rs rrNz(TerminalTrueColorFormatter._setup_stylesDs:: DKE4#%FG} --d7m< I --d9o> ||V "   T+%6#' ~~$x. $ -3-E-E-G-3-@-@-B-DD  c%j ) DrN) r9r:r;rrrrrMrrNr<rrrr%s(  D2GI DrN) rpygments.formatterrpygments.consolerpygments.styler__all__r rrr<rrrsK2)"% "#? @="="@ 9 F-D!5-Dr