Re(@sddlZddlZddlZddlmZmZmZmZddlm Z m Z m Z ddl m Z mZdZe dk re ZGdddeZGdd d eZdS) N)AnsiForeAnsiBack AnsiStyleStyle)WinTermWinColorWinStyle)windll winapi_testc@speZdZdZddZddZddZdd 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||_||_dS)N)_StreamWrapper__wrapped_StreamWrapper__convertor)selfwrapped converterr/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/colorama/ansitowin32.py__init__s zStreamWrapper.__init__cCst|j|S)N)getattrr )rnamerrr __getattr__szStreamWrapper.__getattr__cOs|jj||S)N)r __enter__)rargskwargsrrrrszStreamWrapper.__enter__cOs|jj||S)N)r __exit__)rrrrrrr%szStreamWrapper.__exit__cCs|jj|dS)N)rwrite)rtextrrrr(szStreamWrapper.writec Csw|j}dtjkrF|dk rF|tjksB|tjkrFdSy |j}Wntk rkdSYnX|SdS)NPYCHARM_HOSTEDTF)r osenvironsys __stdout__ __stderr__isattyAttributeError)rstream stream_isattyrrrr$+s *   zStreamWrapper.isattyc Cs1|j}y |jSWntk r,dSYnXdS)NT)r closedr%)rr&rrrr(7s    zStreamWrapper.closedN) __name__ __module__ __qualname____doc__rrrrrr$propertyr(rrrrr s       r c@seZdZdZejdZejdZdddddZdd 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}|dkrq|pn|jj on|jj }||_ |dkr|o|jj o|jj}||_ |j |_ |jt jk|_dS)Nnt)r autoresetr r&rrr r(r$stripconvertget_win32_calls win32_callsr!stderr on_stderr)rrr2r1r0 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() )r2r1r0)rrrr should_wrapjszAnsiToWin32.should_wrapcNCsV|jrOtrOtjtjftjtjtjftjtjtj 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!S)NT)"r2wintermr RESET_ALL reset_allBRIGHTstyler DIMNORMALrBLACKforerREDGREENYELLOWBLUEMAGENTACYANWHITEGREYRESET LIGHTBLACK_EX LIGHTRED_EX LIGHTGREEN_EXLIGHTYELLOW_EX LIGHTBLUE_EXLIGHTMAGENTA_EX LIGHTCYAN_EX LIGHTWHITE_EXrbackdict)rrrrr3tsPzAnsiToWin32.get_win32_callscCsV|js|jr"|j|n|jj||jj|jrR|jdS)N)r1r2write_and_convertrrflushr0r<)rrrrrrs   zAnsiToWin32.writecCsJ|jr|jddn*|j rF|jj rF|jjtjdS)Nmr)r) r2 call_win32r1r&r(rrrr;)rrrrr<s zAnsiToWin32.reset_allcCsd}|j|}xX|jj|D]D}|j\}}|j||||j|j|}q(W|j||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)rrcursormatchstartendrrrrVs zAnsiToWin32.write_and_convertcCs7||kr3|jj||||jjdS)N)rrrW)rrrdrerrrr^s zAnsiToWin32.write_plain_textcCs/|jr+|j||}|j||dS)N)r2extract_paramsrY)r paramstringcommandparamsrrrr_s zAnsiToWin32.convert_ansicCs|dkrTtdd|jdD}x~t|dkrP|d }q1Wn[tdd|jdD}t|dkr|d krd }n|d krd }|S)NHfcss3|])}t|dkr't|ndVqdS)rrN)raint).0prrr sz-AnsiToWin32.extract_params..;rcss-|]#}t|dkrt|VqdS)rN)rark)rlrmrrrrnsrJKmABCD)r)r)r)tuplesplitra)rrhrgrirrrrfs ""   zAnsiToWin32.extract_paramsc Csa|dkruxN|D][}||jkr|j|}|d}|dd}td|j}|||qWn|dkrtj|dd|jn|dkrtj|dd|jn|dkrtj|d|jnq|dkr]|d}d d| fd d|fd |dfd | dfi|\} } tj| | d|jdS) NrXrrr6JKrjrrABCD)r4rUr6r: erase_screen erase_lineset_cursor_position cursor_adjust) rrhriparam func_argsfuncrrnxyrrrrYs$         BzAnsiToWin32.call_win32cCsx|jj|D]}|j\}}|d|||d}|j\}}|dkr|jd}|ddkrtj|dqW|S)Nror02r) ANSI_OSC_REr\r]r`rtr: set_title)rrrcrdrergrhrirrrrZs zAnsiToWin32.convert_osc)r)r*r+r,recompiler[rrr9r3rr<rVr^r_rfrYrZrrrrr.@s ! ,      r.)rr!ransirrrrr:rrr win32r r objectr r.rrrrs   "  0