a [f)@sddlZddlZddlZddlmZmZmZmZmZddl m Z m Z m Z ddl mZmZdZ edurje Z GdddeZGdd d eZdS) N)AnsiForeAnsiBack AnsiStyleStyleBEL)WinTermWinColorWinStyle)windll winapi_testc@sLeZdZdZddZddZddZdd Zd d Zd d Z e ddZ dS) StreamWrapperz Wraps a stream (such as stdout), acting as a transparent proxy for all attribute access apart from method 'write()', which is delegated to our Converter instance. cCs||_||_dSN)_StreamWrapper__wrapped_StreamWrapper__convertor)selfwrappedZ converterrD/usr/lib/python3.9/site-packages/pip/_vendor/colorama/ansitowin32.py__init__szStreamWrapper.__init__cCs t|j|Sr)getattrr)rnamerrr __getattr__szStreamWrapper.__getattr__cOs|jj|i|Sr)r __enter__rargskwargsrrrrszStreamWrapper.__enter__cOs|jj|i|Sr)r__exit__rrrrr%szStreamWrapper.__exit__cCs|j|dSr)rwritertextrrrr(szStreamWrapper.writecCsZ|j}dtjvr0|dur0|tjus,|tjur0dSz |j}WntyNYdS0|SdS)NZPYCHARM_HOSTEDTF)rosenvironsys __stdout__ __stderr__isattyAttributeError)rstreamZ stream_isattyrrrr&+s   zStreamWrapper.isattycCs(|j}z|jWSty"YdS0dSNT)rclosedr')rr(rrrr*7s  zStreamWrapper.closedN) __name__ __module__ __qualname____doc__rrrrrr&propertyr*rrrrr s r c@s~eZdZdZedZedZdddZdd Z d d Z d d Z ddZ ddZ ddZddZddZddZddZdS) AnsiToWin32z Implements a 'write()' method which, on Windows, will strip ANSI character sequences from the text, and if outputting to a tty, will convert them into win32 function calls. z?\[((?:\d|;)*)([a-zA-Z])?z?\]([^]*)()?NFcCs||_||_t|||_tjdk}|o*t}|durN|pL|jj oL|j }||_ |durt|or|jj or|j}||_ | |_ |jt ju|_dS)Nnt)r autoresetr r(r!rr r*r&stripconvertget_win32_calls win32_callsr#stderr on_stderr)rrr4r3r2Z on_windowsZconversion_supportedrrrrIs    zAnsiToWin32.__init__cCs|jp|jp|jS)aj True if this class is actually needed. If false, then the output stream will not be affected, nor will win32 calls be issued, so wrapping stdout is not actually required. This will generally be False on non-Windows platforms, unless optional functionality like autoreset has been requested using kwargs to init() )r4r3r2rrrr should_wrapjszAnsiToWin32.should_wrapcNCs@|jr:tr:tjtjftjtjtjftjtjtj ftj tjtj ft j tj t j ft jtj t jft jtj t jft jtj t jft jtj t jft jtj t jft jtj t jft jtj t jft jtj ft jtj t j dft jtj t jdft jtj t jdft jtj t jdft jtj t jdft jtj t jdft jtj t jdft jtj t jdftj tj t j ftjtj t jftjtj t jftjtj t jftjtj t jftjtj t jftjtj t jftjtj t jftjtj ftjtj t j dftjtj t jdftjtj t jdftjtj t jdftjtj t jdftjtj t jdftjtj t jdftjtj t jdfi&St!Sr))"r4wintermr RESET_ALL reset_allZBRIGHTZstyler ZDIMZNORMALrZBLACKZforer ZREDZGREENZYELLOWZBLUEZMAGENTAZCYANZWHITEZGREYZRESETZ LIGHTBLACK_EXZ LIGHTRED_EXZ LIGHTGREEN_EXZLIGHTYELLOW_EXZ LIGHTBLUE_EXZLIGHTMAGENTA_EXZ LIGHTCYAN_EXZ LIGHTWHITE_EXrZbackdictr9rrrr5tsR   (zAnsiToWin32.get_win32_callscCs@|js |jr||n|j||j|jr<|dSr)r3r4write_and_convertrrflushr2r=rrrrrs     zAnsiToWin32.writecCs4|jr|ddn|js0|jjs0|jtjdS)Nmr) r4 call_win32r3r(r*rrrr<r9rrrr=szAnsiToWin32.reset_allcCsbd}||}|j|D]0}|\}}|||||j||}q|||t|dS)z Write the given text to our wrapped stream, stripping any ANSI sequences from the text, and optionally converting them into win32 calls. rN) convert_osc ANSI_CSI_REfinditerspanwrite_plain_text convert_ansigroupslen)rr Zcursormatchstartendrrrr?s  zAnsiToWin32.write_and_convertcCs*||kr&|j||||jdSr)rrr@)rr rMrNrrrrHszAnsiToWin32.write_plain_textcCs"|jr|||}|||dSr)r4extract_paramsrC)r paramstringcommandparamsrrrrIs zAnsiToWin32.convert_ansicCsz|dvr8tdd|dD}t|dkrv|d}q n>tdd|dD}t|dkrv|d vrjd }n |d vrvd}|S) NHfcss&|]}t|dkrt|ndVqdS)rrNrKint.0prrr z-AnsiToWin32.extract_params..;)rcss"|]}t|dkrt|VqdS)rNrTrVrrrrYrZrZJKmrBABCD)tuplesplitrK)rrQrPrRrrrrOs   zAnsiToWin32.extract_paramsc Cs|dkrV|D]F}||jvr |j|}|d}|dd}t|jd}||i|q n|dvrttj|d|jdn|dvrtj|d|jdnf|dvrtj||jdnL|dvr|d}d| fd|f|df| dfd |\} } tj| | |jddS) NrArr)r8JKrSr])ABCD)r6r>r8r;Z erase_screenZ erase_lineZset_cursor_positionZ cursor_adjust) rrQrRZparamZ func_argsfuncrrnxyrrrrCs$    *zAnsiToWin32.call_win32cCs|j|D]n}|\}}|d|||d}|\}}|tkr |ddkr |d}|ddvr t|dq |S)Nr[rrZ02) ANSI_OSC_RErFrGrJrcountr_r;Z set_title)rr rLrMrNrPrQrRrrrrDs    zAnsiToWin32.convert_osc)NNF)r+r,r-r.recompilerErjrr:r5rr=r?rHrIrOrCrDrrrrr0@s   ! , r0)rlr#r!ansirrrrrr;rr r win32r r objectr r0rrrrs0