Y-Qc@sXdZddlZddlmZdgZdddYZdefdYZdS( s 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-2013 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. iN(t FormattertTerminal256FormattertEscapeSequencecBs8eZddeedZdZdZdZRS(cCs(||_||_||_||_dS(N(tfgtbgtboldt underline(tselfRRRR((sI/usr/local/lib/python2.7/site-packages/pygments/formatters/terminal256.pyt__init__$s   cCs%t|r!ddj|dSdS(Ns;tmt(tlentjoin(Rtattrs((sI/usr/local/lib/python2.7/site-packages/pygments/formatters/terminal256.pytescape*s cCsg}|jdk r5|jddd|jfn|jdk rd|jddd|jfn|jr}|jdn|jr|jdn|j|S(Nt38t5s%it48t01t04(RtNonetextendRRtappendRR(RR((sI/usr/local/lib/python2.7/site-packages/pygments/formatters/terminal256.pyt color_string/s    cCssg}|jdk r%|jdn|jdk rD|jdn|jsV|jrf|jdn|j|S(Nt39t49t00(RRRRRRR(RR((sI/usr/local/lib/python2.7/site-packages/pygments/formatters/terminal256.pyt reset_string;sN(t__name__t __module__RtFalseRRRR(((sI/usr/local/lib/python2.7/site-packages/pygments/formatters/terminal256.pyR#s  cBsheZdZdZdddgZgZdZdZdZdZ d Z d Z d Z RS( sY 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). *New in Pygments 0.9.* Options accepted: `style` The style to use, can be a string or a Style subclass (default: ``'default'``). t Terminal256t terminal256t console256t256cKsatj||g|_i|_i|_d|k|_d|k|_|j|jdS(Ntnoboldt nounderline( RRt xterm_colorst best_matcht style_stringtuseboldt useunderlinet_build_color_tablet _setup_styles(Rtoptions((sI/usr/local/lib/python2.7/site-packages/pygments/formatters/terminal256.pyR[s    cCs|jjd|jjd|jjd|jjd|jjd|jjd|jjd|jjd|jjd|jjd|jjd|jjd|jjd|jjd |jjd!|jjd"d#}x_td D]Q}||d d}||dd}||d}|jj|||fqWx>tddD]-}d|d}|jj|||fqxWdS($Niiiiiii\i_iiiii$iiiii (iii(iii(iii(iii(iii(iii(iii(iii(iii(iii(iii(iii(i\i\i(iii(iii(iii(ii_iiii(R&Rtrange(Rt valuerangetitrtgtbtv((sI/usr/local/lib/python2.7/site-packages/pygments/formatters/terminal256.pyR+hs2c Csd}d}xtddD]r}|j|}||d}||d} ||d} ||| | | | } | |kr|}| }qqW|S( Niiiiiiii(R.R&( RR1R2R3tdistancetmatchR0tvaluestrdtgdtbdtd((sI/usr/local/lib/python2.7/site-packages/pygments/formatters/terminal256.pyt_closest_colors   cCs|jj|d}|dkrytt|d}Wntk rSd}nX|d?d@}|d?d@}|d@}|j|||}||j|s   "