3 &[@sddlZddlZddlZddlZddlZddlZddlZejdkZddZ ej e ej dZ d%Z Gd d d eZd&ddZddZedkrejedS)'NcCstjjdtjjdS)Nz)sysstdoutwriteflushrr,/Users/gilbertstawny/Scripts/Timer/lolcat.pyresets r z\x1b\[(\d+)(;\d+)?(;\d+)?[m|K]\c@s\eZdZdejfddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ dS)LolCatcCs||_||_dS)N)modeoutput)selfrrrrr__init__(szLolCat.__init__cCsttddt||S)NcSs|d|ddS)Nrr)crrr-sz"LolCat._distance..)summapzip)rZrgb1Zrgb2rrr _distance,s zLolCat._distancec s\}}}jdkrXtdj}fddt|D}|j|dd}d|fSd}d } xD|r|| ks~|| ks~|| kr|| ko|| ko|| k} d }| d 7} qbW| rd tttd }n$tdgddtdddgD}d|fSdS)Ncs&g|]\}}j|tt|fqSr)rrint).0ir)rgbrrr 5szLolCat.ansi..rrz3%dTg@Fg@E@g@@cSs(g|] \}}tdt|d|qS)r)r float)r!valmodrrrr$Hs$r&z38;5;%d)rr)r COLOR_ANSI enumeratesortr r'rr) rr#rgbZcolorsZmatchesZcolorZ gray_possiblesepZgrayr)r#rransi0s&      z LolCat.ansicGsddj|fS)Nz[%sm)join)rZcodesrrrwrapMsz LolCat.wrapcCshtj||dd}tj||dtjddd}tj||dtjddd}|||gS)Nr rr)mathZsinZpi)rfreqr"r.r/r0rrrrainbowPs$$zLolCat.rainbowcCsP|jr|jjdx&|D]}|jd7_|j||qW|jrL|jjddS)Nz[?25lrz[?25h)animaterrosprintln)rfdoptionslinerrrcatVs  z LolCat.catcCs^|j}|js|jjr$tjd|}|jr8|j||n |j|||jj d|jj dS)Nr3 ) rstripZforcerisatty STRIP_ANSIsubr; println_ani println_plainrr)rsr?rrrr=as   zLolCat.printlncCsn|sdSx`td|jD]P}|jjdt|f|jj|j|j7_|j||t j d|j qWdS)Nrz[%dDg?) rangeZdurationrrlenrr<spreadrHtimesleepZspeed)rrIr?r"rrrrGns  zLolCat.println_anicCszxtttr |n |j|jdD]V\}}|j|j|j||j}|jj dj |j |j |tr^|n |j |jdgqWdS)Nreplacer3)r,PY3decodeZ charset_py2r:r9r<rLrrr4r5r2encode)rrIr?r"rr#rrrrHys $ zLolCat.println_plainN)__name__ __module__ __qualname__rrrrr2r5r:rAr=rGrHrrrrr's   rxterm-256colorcCsfdtjkrdStjjdddkr$dStjjd|}|jdsD|dkrHdS|jd sZ|dkr^dSdSd S)z) Poor-mans color mode detection. ZANSICONrZ ConEmuANSIZOFFZONrZTERMz -256colorxtermscreenz-colorrxvtN)rWrX)rY)r<environgetendswith)Z term_hintZtermrrr detect_modes r]cCsddl}|jdd}|jddddd d |jd d dd dd |jdddddd |jdddddd|jdddddd |jddddd d |jd!d"ddd#d|jd$d%d&d'd(d)|jd*d%d&d+d,d)|jd-d%d&d.d/d)|jd0d1d2d3d4|j\}}|jdkrtjdd.n|j|_|jp&t |_t |jd5}|sBd6g}x|D]}|d6krf|j t j |n`y&t|d7}|j ||WdQRXWn8tk r}zt jjt|d8WYdd}~XnXqHWdS)9zMain entry point.rNz%prog [] [file ...])Zusagez-pz--spreadr'g@zRainbow spread)typedefaulthelpz-Fz--freqg?zRainbow frequencyz-Sz--seedr z Rainbow seedz-az --animateZ store_trueFzEnable psychedelics)actionr_r`z-dz --duration zAnimation durationz-sz--speedg4@zAnimation speedz-fz--forcez*Force colour even when stdout is not a ttyz-3Z store_constrrzForce 3 bit colour mode)raZdestZconstr`z-4rzForce 4 bit colour modez-8rzForce 8 bit colour modez-cz --charset-py2zutf-8z6Manually set a charset to convert from, for python 2.7)r_r`)r-r.rB)optparseZ OptionParserZ add_optionZ parse_argsZseedrandomZrandintr<rr]rrArstdinopenIOErrorstderrrstr)rdZparserr?argslolcatfilenameZhandleerrorrrrrunsL                  ro__main__)rrrrr rrrr rr r rrrr r rr rr r r r r r r r rrrrrrrrrrrrrrrrrrrrr)rqrrrsrtrurvrwrxryrzr{r|r}r~rr)rV)atexitr8r<rererrM version_inforPr registercompilerEr+objectrr]rorSexitrrrr s.   [ 1