fJc@sLdZddklZdgZdddYZdefdYZdS( 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-2009 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. i(t FormattertTerminal256FormattertEscapeSequencecBs8eZddeedZdZdZdZRS(cCs(||_||_||_||_dS(N(tfgtbgtboldt underline(tselfRRRR((sC/usr/lib/python2.6/site-packages/pygments/formatters/terminal256.pyt__init__"s   cCs't|oddi|dSdS(Ns;tmt(tlentjoin(Rtattrs((sC/usr/lib/python2.6/site-packages/pygments/formatters/terminal256.pytescape(s cCsg}|idj o!|iddd|ifn|idj o!|iddd|ifn|io|idn|io|idn|i|S(Nt38t5s%it48t01t04(RtNonetextendRRtappendRR(RR((sC/usr/lib/python2.6/site-packages/pygments/formatters/terminal256.pyt color_string-s!!  cCszg}|idj o|idn|idj o|idn|ip |io|idn|i|S(Nt39t49t00(RRRRRRR(RR((sC/usr/lib/python2.6/site-packages/pygments/formatters/terminal256.pyt reset_string9sN(t__name__t __module__RtFalseRRRR(((sC/usr/lib/python2.6/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 console256t256cKsati||g|_h|_h|_d|j|_d|j|_|i|idS(Ntnoboldt nounderline( RRt xterm_colorst best_matcht style_stringtuseboldt useunderlinet_build_color_tablet _setup_styles(Rtoptions((sC/usr/lib/python2.6/site-packages/pygments/formatters/terminal256.pyRYs    cCs|iid|iid|iid|iid|iid|iid|iid|iid|iid|iid|iid|iid|iid|iid |iid!|iid"d#}x_td D]Q}||d d}||dd}||d}|ii|||fqWx>tddD]-}d|d}|ii|||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((sC/usr/lib/python2.6/site-packages/pygments/formatters/terminal256.pyR+fs6 c Csd}d}xtddD]t}|i|}||d}||d} ||d} ||| | | | } | |jo|}| }qqW|S( Niiiiiiii(R.R&( RR1R2R3tdistancetmatchR0tvaluestrdtgdtbdtd((sC/usr/lib/python2.6/site-packages/pygments/formatters/terminal256.pyt_closest_colors  cCs|ii|d}|djoytt|d}Wntj o d}nX|d?d@}|d?d@}|d@}|i|||}||i|s  "