3 >\|@sdZddlmZmZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z dZdZd Zd d d d dddddddddddddddZdZejdkrejjejddZnd Zefd!d"Zed#fd$d%ZGd&d'd'eZGd(d)d)eZGd*d+d+eZGd,d-d-eZGd.d/d/eZGd0d1d1e Z!e"d2j#d3j$d3Z%Gd4d5d5e%Z&Gd6d7d7e Z'Gd8d9d9e Z(Gd:d;d;e Z)Gdd?Z+d@dAZ,dBdCZ-e.dDkrej/e-dS)Ez Python FIGlet adaption )print_functionunicode_literalsN) OptionParser) __version__zPeter Waller u The MIT License (MIT) Copyright © 2007-2018 Christopher Jones Stefano Rivera Peter Waller And various contributors (see git history). Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. standard !"#$%'Z[\]^_`a)BLACKREDGREENYELLOWBLUEMAGENTACYANZ LIGHT_GRAYDEFAULTZ DARK_GRAYZ LIGHT_REDZ LIGHT_GREENZ LIGHT_YELLOWZ LIGHT_BLUEZ LIGHT_MAGENTAZ LIGHT_CYANWHITERESETswin32APPDATApyfigletz/usr/local/share/pyfiglet/cKst|f|}|j|S)N)Figlet renderText)textfontkwargsZfigr+k/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/pyfiglet/pyfiglet/__init__.py figlet_format@s r-:cKsPt|}|rtjj|tt||f||rLtjjtjddtjjdS)NzUTF-8replace) parse_colorsysstdoutwriteprintr- RESET_COLORSdecodeflush)r(r)colorsr* ansiColorsr+r+r, print_figletEs r:c@seZdZddZddZdS) FigletErrorcCs ||_dS)N)error)selfr<r+r+r,__init__RszFigletError.__init__cCs|jS)N)r<)r=r+r+r,__str__UszFigletError.__str__N)__name__ __module__ __qualname__r>r?r+r+r+r,r;Qsr;c@seZdZdZdS)CharNotPrintedzF Raised when the width is not sufficient to print a character N)r@rArB__doc__r+r+r+r,rCXsrCc@seZdZdZdS) FontNotFoundz- Raised when a font can't be located N)r@rArBrDr+r+r+r,rE]srEc@seZdZdZdS) FontErrorz< Raised when there is a problem parsing a font file N)r@rArBrDr+r+r+r,rFcsrFc@seZdZdZdS) InvalidColorz1 Raised when the color passed is invalid N)r@rArBrDr+r+r+r,rGisrGc@s~eZdZdZejdZejdZefddZ e ddZ e dd Z e d d Z e dd dZeddZddZddZdS) FigletFontz~ This class represents the currently loaded font, including meta-data about how it should be displayed by default z ^[tf]lf2.z(.)\s*$cCs0||_d|_i|_i|_|j||_|jdS)N)r)commentcharswidth preloadFontdataloadFont)r=r)r+r+r,r>xs  zFigletFont.__init__c Csxd D]}d||f}tjd|r>tjd|}|jdd}|SxLdtfD]@}tjj||}tjj|rHt |d}|j jddSQRXqHWqWt |d S) z) Load font data if exist tlfflfz%s.%szpyfiglet.fontszUTF-8r/z./rbN)rPrQ) pkg_resourcesresource_existsresource_stringr6SHARED_DIRECTORYospathjoinisfileopenreadrE)clsr) extensionfnrNlocationZ full_namefr+r+r,rMs       zFigletFont.preloadFontcCs|jdsdSd}tjjt|}tjj|r8t|d}n$tjj|rPt|d}n tjd|}|j j dd}|j |j j |S) N.flf.tlfFrRzpyfiglet.fontszUTF-8r/)rbrc)endswithrWrXrYrVrZr[rSresource_streamreadliner6close reMagicNumbersearch)r]r)raZ full_fileheaderr+r+r, isValidFonts      zFigletFont.isValidFontcs8tjdd}tjjtr&|tjt7}fdd|DS)Nr%fontscs&g|]}j|r|jdddqS).r)rkrsplit).0r))r]r+r, sz'FigletFont.getFonts..)rSresource_listdirrWrXisdirrVlistdir)r] all_filesr+)r]r,getFontss    zFigletFont.getFontsFcCstj|}g}tjdtj}tjd}xN|jddD]:}|jj|dkr8|j|dkr8|j|dkr8|j|q8W|sdj |S|dS)z* Get informations of font al ^(FONT|COMMENT|FONTNAME_REGISTRY|FAMILY_NAME|FOUNDRY|WEIGHT_NAME| SETWIDTH_NAME|SLANT|ADD_STYLE_NAME|PIXEL_SIZE|POINT_SIZE| RESOLUTION_X|RESOLUTION_Y|SPACING|AVERAGE_WIDTH|COMMENT| FONT_DESCENT|FONT_ASCENT|CAP_HEIGHT|X_HEIGHT|FACE_NAME|FULL_NAME| COPYRIGHT|_DEC_|DEFAULT_CHAR|NOTICE|RELATIVE_).*z ^.*[@#$]$rdN ) rHrMrecompileVERBOSE splitlinesrhriappendrY)r]r)shortrNZinfosZ reStartMarker reEndMarkerliner+r+r,infoFonts   zFigletFont.infoFontcCsttjdtjrt}n tjdd}tdj||tj j |sJtj |tj j |dj dkrtj|l}xd|jD]X}tj j|}|sqx|j|2}ttj j||d}tj||WdQRXWdQRXqxWWdQRXn tj||dS)zA Install the specified font file to this system. r%rlzInstalling {} to {}rz.zipwbN) isinstancerS get_provider ZipProviderrVresource_filenamer4formatrWrXexistsmakedirssplitextlowerzipfileZipFilenamelistbasenamer[rYshutil copyfileobjcopy) file_namer`zip_filer)Z font_filesrcdestr+r+r, installFontss       0zFigletFont.installFontscsTyjj}|jd}jj|dkr6tdjjjd|}|j}t |dkrftdj|d}t t |dd\}}}}d}} t |dkrt |d}t |dkrt |d} | dkr|dkrd } n|dkrd} n |d @d B} _ |_ |_| _x(td|D]} j|jd7_qWfd d } xDtddD]6} | |\} } dj| dkrN| j| <| j| <qNWx|r|jdj}|jddd} | dkrqtjd| tj}|dk rt | d} | |\} } dj| dkr| j| <| j| <qWWn6tk rN}ztdj|fWYdd}~XnXdS)zL Parse loaded font data for the rendering engine to consume rNz%s is not a valid figlet fontrIzmalformed header for %sr@r csd}d}g}xttdD]f}|jd}|dkrTjj|jd}tjtj|d}|jd|}t ||krtt |}|j |qW||fS)z{ Function loads one character in the internal array from font file content Nrrz{1,2}$rI) rangepoprrigroupryrzescapesublenr})rNendrLrKjr)heightr=r+r,Z__chars   z#FigletFont.loadFont..__charr  z^0xzproblem parsing %s font: %s)rNr|rrhrirFr)rsplitrmapintr hardBlankprintDirection smushModerrJrYrKrLstripry IGNORECASE Exception)r=rNrjrZbaseLineZ maxLengthZ oldLayoutZ commentLinesrZ fullLayoutiZ_FigletFont__charrLletterrZ hex_matcher+)rr=r,rOsb               zFigletFont.loadFontcCs d|jS)Nz)r))r=r+r+r,r?BszFigletFont.__str__N)F)r@rArBrDryrzrhr DEFAULT_FONTr> classmethodrMrkrvr staticmethodrrOr?r+r+r+r,rHos       _rHrIasciic@s0eZdZdZdZdZddZddZdd Zd S) FigletStringz Rendered figlet font u  !"#$%&')(*+,-.\0123456789:;>=?@VBCDEFGHIJKLWNObQbSTUAMXYZ[/]v-`aPcdefghijklwnopqrstu^mxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿcCs<g}x,|jD] }|j|j|jdddqW|j|S)Nr)r|r} translate__reverse_map__ newFromList)r=outrowr+r+r,reversets zFigletString.reversecCs<g}x,|jdddD]}|j|j|jqW|j|S)Nrr)r|r}r __flip_map__r)r=rrr+r+r,flip{szFigletString.flipcCstdj|dS)Nrx)rrY)r=listr+r+r,rszFigletString.newFromListN) r@rArBrDrrrrrr+r+r+r,rIs rc@s"eZdZdZdddZddZdS)FigletRenderingEnginezr This class handles the rendering of a FigletFont, including smushing/kerning/justification/direction NcCs ||_dS)N)base)r=rr+r+r,r>szFigletRenderingEngine.__init__cCsFt||jj|jj|jj|jj}x|jr<|j|jq"W|j S)z7 Render an ASCII text string in figlet ) FigletBuilderrFont directionrLjustify isNotFinishedaddCharToProduct goToNextChar returnProduct)r=r(builderr+r+r,renders   zFigletRenderingEngine.render)N)r@rArBrDr>rr+r+r+r,rs rc@s(eZdZdZddZddZddZdS) FigletProductzR This class stores the internal build part of the ascii output string cCst|_d|_dS)NrI)rqueue buffer_string)r=r+r+r,r>szFigletProduct.__init__cCs|jj|dS)N)rr})r=bufferr+r+r,r}szFigletProduct.appendcCs t|jS)N)rr)r=r+r+r, getStringszFigletProduct.getStringN)r@rArBrDr>r}rr+r+r+r,rsrc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zggfd2d3Zd8d5d6Zd7S)9rz6 Represent the internals of the build process cCstttt||_||_||_||_||_d|_d|_ d|_ d|_ d|_ d|_ t|_t|_ddt|jjD|_d|_d|_d|_d|_d |_d |_d |_d |_dS) NrFcSsg|]}dqS)rIr+)rprr+r+r,rqsz*FigletBuilder.__init__..rrnrr rr)rrordr(rrLr)riteratormaxSmushZnewBlankRegistered curCharWidth prevCharWidthcurrentTotalWidth blankMarkersrproductrrrSM_EQUAL SM_LOWLINE SM_HIERARCHYSM_PAIRSM_BIGX SM_HARDBLANKSM_KERNSM_SMUSH)r=r(r)rrLrr+r+r,r>s,zFigletBuilder.__init__cCsR|j}|j|jtdkrF|jjdd|jD|jf|jdS|dkrRdS|j|j krht d|j |_ |j ||_ t|jd|j |j |_|j|jtdkr|jjdd|jD|jf|j|jtdkr|jjdd|jD|jf|j|j|jkr |jn&x$td|jjD]}|j||q0W|j |_dS) NrxcSsg|]}|qSr+r+)rprr+r+r,rqsz2FigletBuilder.addCharToProduct..z+Width is not enough to print this characterrrcSsg|]}|qSr+r+)rprr+r+r,rqscSsg|]}|qSr+r+)rprr+r+r,rqs) getCurCharr(rrrr}r handleNewLinerL getCurWidthrCrcurrentSmushAmountrrrrr)raddCurCharRowToBufferRowr)r=curCharrr+r+r,rs,   zFigletBuilder.addCharToProductcCs|jd7_dS)Nr)r)r=r+r+r,rszFigletBuilder.goToNextCharcCs(|jddkr|j|j|jjS)zD Returns the output string created by formatProduct rrI)rflushLastBuffer formatProductrr)r=r+r+r,rszFigletBuilder.returnProductcCs|jt|jk}|S)N)rrr()r=retr+r+r,rszFigletBuilder.isNotFinishedcCs|jj|jdS)N)rr}r)r=r+r+r,rszFigletBuilder.flushLastBuffercCs>d}x,|jjD] }|j|j|}||j|7}qW||j_dS)zv This create the output string representation from the internal representation of the product rIN)rr justifyStringrreplaceHardblanksr)r=Z string_accrr+r+r,r s zFigletBuilder.formatProductcCsH|dks|tt|jkrdS|j|}||jjkr8dS|jj|SdS)Nr)rrr(r)rK)r=rcr+r+r, getCharAts   zFigletBuilder.getCharAtcCsD|dks|t|jkrdS|j|}||jjkr4dS|jj|SdS)Nr)rr(r)rKrL)r=rrr+r+r,getCharWidthAts   zFigletBuilder.getCharWidthAtcCs |j|jS)N)rr)r=r+r+r,r(szFigletBuilder.getCurCharcCs |j|jS)N)rr)r=r+r+r,r+szFigletBuilder.getCurWidthcCs<t||j|}|dkr0|t|kr0||}nd}||fS)NrrI)rr)r=raddLeftidxleftr+r+r,getLeftSmushedChar.s  z FigletBuilder.getLeftSmushedCharcCs|j|j|S)N) smushAmountr)r=rr+r+r,r6sz FigletBuilder.currentSmushAmountcCs6t|}|dks|t|kr |S|||<dj|}|S)NrrI)rrrY)r=rrsmushedlr+r+r,updateSmushedCharInLeftBuffer9s  z+FigletBuilder.updateSmushedCharInLeftBufferc Csx|j|}||}|jdkr&||}}xHtd|jD]8}|j||\}}||}|j||d} |j||| }q4W||fS)Nz right-to-leftr)rright)rrrrr smushCharsr) r=rrraddRightrrrrrr+r+r,smushRowAs   zFigletBuilder.smushRowcCs,|j||\}}|||jd|j|<dS)N)rrr)r=rrrrr+r+r,rOsz&FigletBuilder.addCurCharRowToBufferRowcCsZt|jd|_ddt|jjD|_t|_d|_|j }|dkrJdS|j ||_ dS)NrcSsg|]}dqS)rIr+)rprr+r+r,rqUsz1FigletBuilder.cutBufferCommon..) rrrrr)rrrrrrr)r=rr+r+r,cutBufferCommonSszFigletBuilder.cutBufferCommoncCs|jj|||_|jdS)N)rr}rr)r= saved_buffersaved_iteratorr+r+r,cutBufferAtLastBlank]s z"FigletBuilder.cutBufferAtLastBlankcCs(|jj|j|jd8_|jdS)Nr)rr}rrr)r=r+r+r,cutBufferAtLastCharbsz!FigletBuilder.cutBufferAtLastCharcCs|dkS)Nrrr+)r=Z last_blankr+r+r, blankExistgszFigletBuilder.blankExistc Cs0y|jj\}}Wntk r&dSX||fS)Nrrr)rr)rr IndexError)r=rrr+r+r, getLastBlankjs zFigletBuilder.getLastBlankcCs0|j\}}|j|r$|j||n|jdS)N)rrrr)r=rrr+r+r,rqs  zFigletBuilder.handleNewLinecCs|dkrHxtd|jjD]*}d|jt||d||||<qWnJ|dkrx@td|jjD].}dt|jt||d||||<q`W|S)Nrrrrcenterrn)rr)rrLrr)r=rrrr+r+r,rxszFigletBuilder.justifyStringcCs"dj|d}|j|jjd}|S)Nrxr)rYr/r)r)r=rstringr+r+r,rszFigletBuilder.replaceHardblanksc Cs4|jj|j|jB@dkrdS|j}x td|jjD]}||}||}|jdkr\||}}t|j d}|dkrxd}|t|kr||}nd}d}t|t|j } | t|kr|| } n t|} d} | t|d|} |dks|dkr| d7} n&| dkr |j || ddk r | d7} | |kr4| }q4W|S)ac Calculate the amount of smushing we can do between this char and the last If this is the first char it will throw a series of exceptions which are caught and cause appropriate values to be set for later. This differs from C figlet which will just get bogus values from memory and then discard them after. rz right-to-leftrrIr)rrN) r)rrrrrrrrrstriplstripr) r=rrrrZlineLeftZ lineRightZlinebdZch1ZcharbdZch2amtr+r+r,rs:         zFigletBuilder.smushAmountrIcCs|jdkr|S|jdkr |S|jdks4|jdkr8dS|jj|j@dkrNdS|jjd@dkr||jjkrn|S||jjkr~|S|jdkr|S|S|jj|j@r||jjkr||jjkr|S||jjks||jjkrdS|jj|j @r||kr|Sf}|jj|j @r |d7}|jj|j @r$|d7}xB|D]:\}}||krJ||krJ|S||kr*||kr*|Sq*W|jj|j @rx(||||gD]}|d krd SqW|jj|j @r|dkr|dkrd S|dkr|dkrdS|dkr|dkrdSdS)!z Given 2 characters which represent the edges rendered figlet fonts where they would touch, see if they can be smushed together. Returns None if this cannot or should not be done. TrnNr?z right-to-left_ |/\[]{}()<>|\/[]{}()<>[]{}()<>{}()<>()<>/\Y><Xrr)rrrrrrrrrrr)r r!r"r#r$)rrr)isspacerrr)rrrrrrrrrr)r=rrZsmushesabpairr+r+r,rsj            zFigletBuilder.smushCharsN)rIrI)r@rArBrDr>rrrrrrrrrrrrrrrrrrrrrrrrrr+r+r+r,rs6 "      1rc@sZeZdZdZedddfddZddZdd ZeeZ d d Z ee Z d d Z ddZ dS)r&z Main figlet class. autoPcCs0||_||_||_||_|jt|d|_dS)N)r)r) _direction_justifyrLsetFontrengine)r=r)rrrLr+r+r,r>s zFiglet.__init__cKs$d|kr|d|_t|jd|_dS)Nr))r))r)rHr)r=r*r+r+r,r-s zFiglet.setFontcCs:|jdkr0|jj}|dkrdS|dkr*dSdSn|jSdS)Nr)rz left-to-rightrz right-to-left)r+rr)r=rr+r+r, getDirection#s zFiglet.getDirectioncCs2|jdkr(|jdkrdS|jdkr.dSn|jSdS)Nr)z left-to-rightrz right-to-leftr)r,r)r=r+r+r, getJustify2s    zFiglet.getJustifycCs |jj|S)N)r.r)r=r(r+r+r,r'>szFiglet.renderTextcCs |jjS)N)rrv)r=r+r+r,rvBszFiglet.getFontsN)r@rArBrDrr>r-r/propertyrr0rr'rvr+r+r+r,r&s   r&cCs|sdS|jddkr.|jddkr.tdn$|jddkrR|tkrRtdj||tkrpt|}|r|d7}n|rxdnd }d j||}d j|S) NrI;rrnz6Specified color '{}' not a valid color in R;G;B formatz7Specified color '{}' not found in ANSI COLOR_CODES list 0&z{};2;{}z[{}m)countrG COLOR_CODESr)color isBackgroundZansiCoder+r+r, color_to_ansiFs    r:cCs0|jd\}}}t|dd}t|dd}||S)Nr.F)r9T) partitionr:)r8Z foregroundrZ backgroundZansiForegroundZansiBackgroundr+r+r,r0Zs  r0c Csdttdd}|jddtddd|jdd d dBd ddd|jddd dCd ddd|jddddddd|jdd d!d"d#d$|jd%d&d!d"d'd$|jd(d)d!d"d*d$|jd+d,d!d"d-d$|jd.d/dd0d1|jd2d3d4d5d1|j\}}|jr td6jtt j t d7|j d8kr:td9d6jtt jt d7|jrZtt j|jt d7|jrvt j|jt d7t|d7kr|jd:StjdDkrdj|}t|j|j|j|jd?}|j|}|jr|j}|jr|j}tjdEkrtjj t_t!|j }|r0tjj"|j#d@tjj"|j#d@tjj"dA|r`tjj"t$d7S)FNz%prog [options] [text..])versionusagez-fz--fontz'font to render with (default: %default)ZFONT)defaulthelpmetavarz-Dz --directionchoicer) left-to-right right-to-leftZ DIRECTIONz;set direction text will be formatted in (default: %default))typechoicesr>r@r?z-jz --justifyrrrZSIDEz.set justification, defaults to print directionz-wz--widthrr*ZCOLSzAset terminal width for wrapping/justification (default: %default))rDr>r@r?z-rz --reverse store_trueFz!shows mirror image of output text)actionr>r?z-Fz--flipzflips rendered output text overz-lz --list_fontszshow installed fonts listz-iz --info_fontz)show font's information, use with -f FONTz-Lz--loadz.load and install the specified font definition)r>r?z-cz--colorr.aprints text with passed foreground color, --color=foreground:background --color=:background # only background --color=foreground | foreground: # only foreground --color=list # list all colors COLOR = list[COLOR] | [0-255];[0-255];[0-255] (RGB)rxrrz[0-255];[0-255];[0-255] # RGB rcSsg|]}|jdqS)zUTF-8)r6)rpargr+r+r,rqszmain..r)r)rrrLzUTF-8 )r)rBrC)r)rrr)rH)rH)%rr add_optionr parse_argsZ list_fontsr4rYsortedrHrvexitr8r7keysZ info_fontrr)loadrr print_helpr1 version_infor&rrrLr'rrr2detachr0r3encoder5)parseroptsargsr(rarr9r+r+r,mainas                    rY__main__)0rD __future__rrrWrSryrr1roptparserr<r __author__ __copyright__rr7r5platformrXrYenvironrVr-r:rr;rCrErFrGobjectrHrDrTr6Zunicode_stringrrrrr&r:r0rYr@rNr+r+r+r,sR      X=b7Z