U o a(@sddlZddlZddlZddlmZmZmZmZddlm Z m Z m Z ddl m Z mZdZe dk rfe ZGdddeZGdd d eZdS) N)AnsiForeAnsiBack AnsiStyleStyle)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)selfwrapped converterraC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_vendor\colorama\ansitowin32.py__init__szStreamWrapper.__init__cCs t|j|Sr )getattrr)rnamerrr __getattr__szStreamWrapper.__getattr__cOs|jj||Sr )r __enter__rargskwargsrrrrszStreamWrapper.__enter__cOs|jj||Sr )r__exit__rrrrr%szStreamWrapper.__exit__cCs|j|dSr )rwritertextrrrr(szStreamWrapper.writecCs\|j}dtjkr0|dk r0|tjks,|tjkr0dSz |j}Wntk rPYdSX|SdS)NPYCHARM_HOSTEDTF)rosenvironsys __stdout__ __stderr__isattyAttributeError)rstream stream_isattyrrrr'+s  zStreamWrapper.isattycCs*|j}z|jWStk r$YdSXdSNT)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}|dkrN|pL|jj oL|j }||_ |dkrt|or|jj or|j}||_ | |_ |jt jk|_dS)Nnt)r autoresetr r)r"rr r,r'stripconvertget_win32_calls win32_callsr$stderr on_stderr)rrr6r5r4 on_windowsconversion_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() )r6r5r4rrrr 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+)"r6wintermr RESET_ALL reset_allBRIGHTstyler DIMNORMALrBLACKforerREDGREENYELLOWBLUEMAGENTACYANWHITEGREYRESET LIGHTBLACK_EX LIGHTRED_EX LIGHTGREEN_EXLIGHTYELLOW_EX LIGHTBLUE_EXLIGHTMAGENTA_EX LIGHTCYAN_EX LIGHTWHITE_EXrbackdictr=rrrr7ts                                   (zAnsiToWin32.get_win32_callscCs@|js |jr||n|j||j|jr<|dSr )r5r6write_and_convertrrflushr4rArrrrrs     zAnsiToWin32.writecCs4|jr|ddn|js0|jjs0|jtjdS)Nmr) r6 call_win32r5r)r,rrrr@r=rrrrAszAnsiToWin32.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 cursormatchstartendrrrr[s  zAnsiToWin32.write_and_convertcCs*||kr&|j||||jdSr )rrr\)rr rjrkrrrrdszAnsiToWin32.write_plain_textcCs"|jr|||}|||dSr )r6extract_paramsr_)r paramstringcommandparamsrrrres zAnsiToWin32.convert_ansicCsz|dkr8tdd|dD}t|dkrv|d}q n>tdd|dD}t|dkrv|d krjd }n |d krvd}|S) NHfcss&|]}t|dkrt|ndVqdS)rrNrgint.0prrr sz-AnsiToWin32.extract_params..;)rcss"|]}t|dkrt|VqdS)rNrqrsrrrrvs rJKmr^ABCD)tuplesplitrg)rrnrmrorrrrls   zAnsiToWin32.extract_paramsc Cs|dkrR|D]B}||jkr |j|}|d}|dd}t|jd}|||q n|dkrptj|d|jdn|dkrtj|d|jdnf|dkrtj||jdnL|dkr|d}d| fd|f|df| dfd |\} } tj| | |jddS) Nr]rr)r:JKrprz)ABCD)r8rZr:r? erase_screen erase_lineset_cursor_position cursor_adjust) rrnroparam func_argsfuncrrnxyrrrr_s$    *zAnsiToWin32.call_win32cCsr|j|D]`}|\}}|d|||d}|\}}|dkr |d}|ddkr t|dq |S)Nrwr02r) ANSI_OSC_RErbrcrfr|r? set_title)rr rirjrkrmrnrorrrr`s    zAnsiToWin32.convert_osc)NNF)r-r.r/r0recompilerarrr>r7rrAr[rdrerlr_r`rrrrr2@s   ! , r2)rr$r"ansirrrrr?rrr win32r r objectr r2rrrrs0