o )1_)@sddlZddlZddlZddlmZmZmZmZmZddl m Z m Z m Z ddl mZmZdZ edur5e 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)selfwrapped converterr6/usr/lib/python3/dist-packages/colorama/ansitowin32.py__init__s zStreamWrapper.__init__cCs t|j|Sr)getattrr)rnamerrr __getattr__s zStreamWrapper.__getattr__cO|jj|i|Sr)r __enter__rargskwargsrrrrszStreamWrapper.__enter__cOrr)r__exit__rrrrr%szStreamWrapper.__exit__cCs|j|dSr)rwritertextrrrr (szStreamWrapper.writecCsT|j}dtjvr|dur|tjus|tjurdSz|j}W|Sty)YdSw)NPYCHARM_HOSTEDTF)rosenvironsys __stdout__ __stderr__isattyAttributeError)rstream stream_isattyrrrr)+s  zStreamWrapper.isattycCs$|j}z|jWStyYdSwNT)rclosedr*)rr+rrrr.7s  zStreamWrapper.closedN) __name__ __module__ __qualname____doc__rrrrr r)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}|ot}|dur'|p&|jj o&|j }||_ |dur:|o9|jj o9|j}||_ | |_ |jt ju|_dS)Nnt)r autoresetr r+r$rr r.r)stripconvertget_win32_calls win32_callsr&stderr on_stderr)rrr8r7r6 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() )r8r7r6rrrr should_wrapjszAnsiToWin32.should_wrapc Cs|jrCtrCitjtjftjtjtjftjtjtj 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 jdfit 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 jdfiSt!Sr-)"r8wintermr RESET_ALL reset_allBRIGHTstyler DIMNORMALrBLACKforer REDGREENYELLOWBLUEMAGENTACYANWHITEGREYRESET LIGHTBLACK_EX LIGHTRED_EX LIGHTGREEN_EXLIGHTYELLOW_EX LIGHTBLUE_EXLIGHTMAGENTA_EX LIGHTCYAN_EX LIGHTWHITE_EXrbackdictr?rrrr9ts        !"#(zAnsiToWin32.get_win32_callscCsD|js|jr ||n |j||j|jr |dSdSr)r7r8write_and_convertrr flushr6rCr!rrrr s     zAnsiToWin32.writecCs>|jr |dddS|js|jjs|jtjdSdSdS)Nmr) r8 call_win32r7r+r.rr rrBr?rrrrCs zAnsiToWin32.reset_allcCsbd}||}|j|D]}|\}}|||||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||||jdSdSr)rr r^)rr"rlrmrrrrfszAnsiToWin32.write_plain_textcCs&|jr|||}|||dSdSr)r8extract_paramsra)r paramstringcommandparamsrrrrgs zAnsiToWin32.convert_ansicCs|dvr"tdd|dD}t|dkr |d}t|dks|Stdd|dD}t|dkrB|d vrs&z-AnsiToWin32.extract_params..;)rcss$|] }t|dkrt|VqdS)rNrsrurrrrxs"rJKmr`ABCD)tuplesplitri)rrprorqrrrrns    zAnsiToWin32.extract_paramsc Cs|dkr,|D]#}||jvr)|j|}|d}|dd}t|jd}||i|qdS|dvrs0