Qc@sdZddlZddlmZmZmZmZmZddlm Z m Z ddl m Z dZ idd6d d 6d d 6d d6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06Zd1Zd2ZyddlZied3fd6ed4fd56ed6fd6ed7fd86ed7fd 6ed9fd96ed:fd:6edfd6ed;fd<6ed=fd6eejfd 6eejfd 6eejfd6eejfd6eejfd6eejfd6eejfd6eejfd6aWnek rBeanXi&d>d?6dd@6ddA6ddB6ddC6ddD6ddE6ddF6ddG6ddH6dIdJ6ddK6ddL6ddM6d dN6ddO6dPdQ6d>dR6dSdT6ddU6ddV6dWdX6d dY6ddZ6dd[6dd\6dSd]6d>d^6dSd_6dd`6dda6dbdc6dIdd6dedf6d>dg6dhdi6ddj6dIdk6ZdlZdmZ dnZ!doZ"dpejfdqYZ#drZ$dsZ%dtZ&ej'dukrdZ)n*ddl*Z*ddl+Z+e+j,j-Z.e+j/Z0dZ1dve+j2fdwYZ3dxe+j2fdyYZ4dze+j2fd{YZ5d|Z6d}Z7dZ8d~Z9dZ:dZ;dZ<d Z=dZ>dZ?dZ@dZAidd6dd 6e:d 6e9d6e:e9Bd6e8d6e8e:Bd6e8e9Bd6e:e9Be8Bd6e;d6dd"6e>d$6e=d&6e>e=Bd(6e<d*6e<e>Bd,6e<e=Bd.6e>e=Be<Bd06e?d6eAd6e@d 6Z)eBe;e?eAe@gZCe.jDe6ZEeEdkseEe1krdZ)nRe5ZFe.jGeEe+jHeFsdZ)n%eFjIZJe*jKde*jLe*jMBZNdZOdS(s colorize output from some commands This extension modifies the status and resolve commands to add color to their output to reflect file status, the qseries command to add color to reflect patch status (applied, unapplied, missing), and to diff-related commands to highlight additions, removals, diff headers, and trailing whitespace. Other effects in addition to color, like bold and underlined text, are also available. By default, the terminfo database is used to find the terminal codes used to change color and effect. If terminfo is not available, then effects are rendered with the ECMA-48 SGR control function (aka ANSI escape codes). Default effects may be overridden from your configuration file:: [color] status.modified = blue bold underline red_background status.added = green bold status.removed = red bold blue_background status.deleted = cyan bold underline status.unknown = magenta bold underline status.ignored = black bold # 'none' turns off all effects status.clean = none status.copied = none qseries.applied = blue bold underline qseries.unapplied = black bold qseries.missing = red bold diff.diffline = bold diff.extended = cyan bold diff.file_a = red bold diff.file_b = green bold diff.hunk = magenta diff.deleted = red diff.inserted = green diff.changed = white diff.trailingwhitespace = bold red_background resolve.unresolved = red bold resolve.resolved = green bold bookmarks.current = green branches.active = none branches.closed = black bold branches.current = green branches.inactive = none tags.normal = green tags.local = black bold The available effects in terminfo mode are 'blink', 'bold', 'dim', 'inverse', 'invisible', 'italic', 'standout', and 'underline'; in ECMA-48 mode, the options are 'bold', 'inverse', 'italic', and 'underline'. How each is rendered depends on the terminal emulator. Some may not be available for a given terminal type, and will be silently ignored. Note that on some systems, terminfo mode may cause problems when using color with the pager extension and less -R. less with the -R option will only display ECMA-48 color codes, and terminfo mode may sometimes emit codes that less doesn't understand. You can work around this by either using ansi mode (or auto mode), or by using less -r (which will pass through all terminal control codes, not just color control codes). Because there are only eight standard colors, this module allows you to define color names for other color slots which might be available for your terminal type, assuming terminfo mode. For instance:: color.brightblue = 12 color.pink = 207 color.orange = 202 to set 'brightblue' to color slot 12 (useful for 16 color terminals that have brighter colors defined in the upper eight) and, 'pink' and 'orange' to colors in 256-color xterm's default color cube. These defined colors may then be used as any of the pre-defined eight, including appending '_background' to set the background to that color. By default, the color extension will use ANSI mode (or win32 mode on Windows) if it detects a terminal. To override auto mode (to enable terminfo mode, for example), set the following configuration option:: [color] mode = terminfo Any value other than 'ansi', 'win32', 'terminfo', or 'auto' will disable color. iN(tcommandstdispatcht extensionstuitutil(t templaterterror(t_tinternalitnoneitblackitredi tgreeni!tyellowi"tbluei#tmagentai$tcyani%twhiteitboldititalicit underlineitinversei(tblack_backgroundi)tred_backgroundi*tgreen_backgroundi+tyellow_backgroundi,tblue_backgroundi-tpurple_backgroundi.tcyan_backgroundi/twhite_backgroundcCsts dS|d krdStjd|jdDytjWntjk rg}iadSXxVtjD]H\}\}}|squntj|su|jd|t|=ququWtjd stjd r |dkr|j t d niandS( sDInitialize terminfo data and the terminal if we're in terminfo mode.Ntautotterminfocss@|]6\}}|jdr|dtt|ffVqdS(scolor.iN(t startswithtFalsetint(t.0tkeytval((s//sys/lib/python2.7/site-packages/hgext/color.pys s tcolorsno terminfo entry for %s tsetaftsetabs>no terminfo entry for setab/setaf: reverting to ECMA-48 color (sautoR( t_terminfo_paramstupdatet configitemstcursest setuptermRtitemsttigetstrtdebugtwarnR(RtmodeteR$tb((s//sys/lib/python2.7/site-packages/hgext/color.pyt_terminfosetupxs*    cCs|d}|dk}| o)tj|}| r>| r>dS|petjjddkoe|j}|jddd}|}|dkrtjdkrdtjkrd}qd}n|dkria t s|dkr|j t d |ndSt jt nj|dkr&ia nU|d krwt||t s{|d krk|j t d |nd}q{ndS|s|r|r|SdS( NR&RtTERMtdumbR2tnttwin32tansis(warning: failed to set color mode to %s R(Rt parsebooltNonetostenvirontgett formattedtconfigtnameR)t w32effectsR1Rt_effectsR*R5(RtoptstcoloroptRtalwaysR@R2trealmode((s//sys/lib/python2.7/site-packages/hgext/color.pyt _modesetups>  *           tsgr0tsmsotstandouttsmultrevtreversetblinktdimtinvist invisibletsitmsred bolds grep.matchsgrep.linenumbersgrep.revs grep.changesgrep.seps grep.filenames grep.users grep.datesbookmarks.currentsbranches.actives black boldsbranches.closedsbranches.currentsbranches.inactives diff.changeds diff.deleteds diff.difflines cyan bolds diff.extendeds diff.file_as green bolds diff.file_bs diff.hunks diff.insertedsbold red_backgroundsdiff.trailingwhitespacesdiffstat.deletedsdiffstat.inserteds ui.prompts log.changesetsresolve.resolvedsresolve.unresolveds status.addeds status.cleans status.copiedscyan bold underlinesstatus.deletedsstatus.ignoreds blue boldsstatus.modifiedsstatus.removedsmagenta bold underlinesstatus.unknowns tags.normals tags.localcCst}|jdr(t}|d }nt|\}}|rKtj|S|rjtjtjd|Stjtjd|SdS(s%Helper function for render_effects().t _backgroundiR(R'N(R!tendswithtTrueR)R,R/ttparm(teffecttbgtattrR%((s//sys/lib/python2.7/site-packages/hgext/color.pyt _effect_str s  cCs|s |Stsrgdg|jD]}tt|^q$}ddj|d}dttdd}n2djddg|jD}td}dj|||gS(s-Wrap text in commands to turn on each effect.R s;tmtcss|]}t|VqdS(N(R\(R#RY((s//sys/lib/python2.7/site-packages/hgext/color.pys #s(R)tsplittstrRDtjoinR\(ttextteffectsR3tstarttstop((s//sys/lib/python2.7/site-packages/hgext/color.pytrender_effectss0  cCs:x3tjD]%\}}tjt|diq WdS(Nt colortable(Rt_stylesR*tgetattr(RBtext((s//sys/lib/python2.7/site-packages/hgext/color.pyt extstyles(sc Csx|jdD]\}}d|ks|jdr=qn|jd|}|rg}xz|D]r}t r|tkr|j|qb|tks|d tkr|j|qb|jtd||fqbWdj|t |Dscss|]\}}|VqdS(N((R#RwRv((s//sys/lib/python2.7/site-packages/hgext/color.pys Fs(t _colormodeR<tsuperRut popbufferRbt_bufferstpop(Rxtlabeled((Rxs//sys/lib/python2.7/site-packages/hgext/color.pyR{?s R:cOs|jdkr(tt|j||S|jdd}|jry|jdjg|D]}t||f^qWn}|jdkrxk|D]"}t |tt|j|qWn>tt|jg|D]}|j t||^q|SdS(NRvR_iR9( RyR<RzRutwriteR?R|textendRat win32printRv(RxtargsRERvRw((s//sys/lib/python2.7/site-packages/hgext/color.pyRIs 6 #cOs|jdkr(tt|j||S|jdd}|jdkryxk|D]"}t|tt|j|qPWn>tt|jg|D]}|jt||^q|SdS(NRvR_R9( RyR<RzRut write_errR?RRvRa(RxRRERvRw((s//sys/lib/python2.7/site-packages/hgext/color.pyRWs #cCs|jdkr(tt|j||Sg}x<|jD].}tj|d}|r;|j|q;q;Wdj |}|rdj g|jdD]}t ||^qS|S(NR_Rns ( RyR<RzRuRvR`RiR?RpRbRg(RxtmsgRvRdtlts((s//sys/lib/python2.7/site-packages/hgext/color.pyRvcs )(t__name__t __module__R!R{RyRRRv(((s//sys/lib/python2.7/site-packages/hgext/color.pyRu>s    cCst|dkr*tjtdntj|dd|||dd}tj||tj||}|jdd}t |t r|Stj|dd|||dd}tj||tj||}tj|}tj|}|j j ||S(Nislabel expects two argumentsiitrepoR_( tlenRt ParseErrorRRt stringifyt runtemplatetcompiletemplateR?t isinstanceRaRRv(tcontexttmappingRtthingRRv((s//sys/lib/python2.7/site-packages/hgext/color.pyt templatelabelrs+ + cCsj|jrdSt|jts=|jft_t|_nd}tjtd|tt j deZdejfdejfdejfdejfgZRS(tLefttToptRighttBottom(RRRRR(((s//sys/lib/python2.7/site-packages/hgext/color.pyRs   t_CONSOLE_SCREEN_BUFFER_INFOcBs;eZdefdefdefdefdefgZRS(tdwSizetdwCursorPositiont wAttributestsrWindowtdwMaximumWindowSize(RRRt_WORDRR(((s//sys/lib/python2.7/site-packages/hgext/color.pyRs     lliiii@ii@iitbold_backgrounds\[([^m]*)m([^]*)(.*)c KsM|jdd}t}d}xP|jD]B}tj|d}x'|jD]}|t||}qSWq.W|jdsd|}ntjt|} zx| r3x>| j djdD]$} | r|t | |}qqWt j t ||| j d|tjt| j d } qWWdt j t tXdS( NRvR_cSsT|dkrtS|tkr$||BS|dkr@|d@|d@BS|d@|d@BSdS(Niiipiii(torigattrt passthrough(R%R[((s//sys/lib/python2.7/site-packages/hgext/color.pytmapcolors   siR]ii(R?RR`RiRCR tretmatchtansiretgroupR"t _kernel32tSetConsoleTextAttributetstdout( RcRRERvR[RRtstyleRYR^tsattr((s//sys/lib/python2.7/site-packages/hgext/color.pyRs&   #(Pt__doc__R=t mercurialRRRRtuimodRRRtmercurial.i18nRt testedwithRDR5RIR,RWR!t COLOR_BLACKt COLOR_REDt COLOR_GREENt COLOR_YELLOWt COLOR_BLUEt COLOR_MAGENTAt COLOR_CYANt COLOR_WHITER)t ImportErrorRiR\RgRlRtRuRRRRBR<RCRRtwindlltkernel32Rtc_ushortRt_INVALID_HANDLE_VALUEt StructureRRRt_STD_OUTPUT_HANDLEt_STD_ERROR_HANDLEt_FOREGROUND_BLUEt_FOREGROUND_GREENt_FOREGROUND_REDt_FOREGROUND_INTENSITYt_BACKGROUND_BLUEt_BACKGROUND_GREENt_BACKGROUND_REDt_BACKGROUND_INTENSITYt_COMMON_LVB_REVERSE_VIDEOt_COMMON_LVB_UNDERSCOREtsetRt GetStdHandleRtcsbitGetConsoleScreenBufferInfotbyrefRRtcompilet MULTILINEtDOTALLRR(((s//sys/lib/python2.7/site-packages/hgext/color.pytes (&# % -                  4