
    hx+                         d dl Z d dlZd dlZddlmZmZmZmZmZ ddl	m
Z
mZmZmZ ddlmZmZ dZ	e e       Z	 G d de      Z G d d	e      Zy)
    N   )AnsiForeAnsiBack	AnsiStyleStyleBEL)enable_vt_processingWinTermWinColorWinStyle)windllwinapi_testc                   P    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zed
        Zy)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.
    c                      || _         || _        y N)_StreamWrapper__wrapped_StreamWrapper__convertor)selfwrapped	converters      =D:\EasyAligner\venv\Lib\site-packages\colorama/ansitowin32.py__init__zStreamWrapper.__init__   s     !$    c                 .    t        | j                  |      S r   )getattrr   )r   names     r   __getattr__zStreamWrapper.__getattr__   s    t~~t,,r   c                 :     | j                   j                  |i |S r   )r   	__enter__r   argskwargss      r   r    zStreamWrapper.__enter__   s      (t~~''888r   c                 :     | j                   j                  |i |S r   )r   __exit__r!   s      r   r%   zStreamWrapper.__exit__%   s    &t~~&&777r   c                     || _         y r   __dict__)r   states     r   __setstate__zStreamWrapper.__setstate__(   s	    r   c                     | j                   S r   r'   r   s    r   __getstate__zStreamWrapper.__getstate__+   s    }}r   c                 :    | j                   j                  |       y r   )r   writer   texts     r   r/   zStreamWrapper.write.   s    t$r   c                     | j                   }dt        j                  v r'|%|t        j                  u s|t        j
                  u ry	 |j                  } |       S # t        $ r Y yw xY w)NPYCHARM_HOSTEDTF)r   osenvironsys
__stdout__
__stderr__isattyAttributeError)r   streamstream_isattys      r   r9   zStreamWrapper.isatty1   sb    rzz)!v'?6S^^C[	#"MMM !?"  		s   A 	A&%A&c                 ^    | j                   }	 |j                  S # t        t        f$ r Y yw xY wNT)r   closedr:   
ValueError)r   r;   s     r   r?   zStreamWrapper.closed=   s3    	==  
+ 		s    ,,N)__name__
__module____qualname____doc__r   r   r    r%   r*   r-   r/   r9   propertyr?    r   r   r   r      sC    
%-98%
#  r   r   c                       e Zd ZdZ ej
                  d      Z ej
                  d      ZddZd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zy)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?\]([^]*)()?Nc                    || _         || _        t        ||       | _        t        j
                  dk(  }|xr
 t               }	 |j                         }| xs t        |      }| j                  j                   xr | j                  j                         }	|xr | }
||
xs |	 }|| _        ||
xr |	}|| _        | j                         | _        | j                   t         j"                  u | _        y # t        $ r d}Y w xY w)Nnt)r   	autoresetr   r;   r4   r   r   fileno	Exceptionr	   r?   r9   stripconvertget_win32_callswin32_callsr6   stderr	on_stderr)r   r   rP   rO   rL   
on_windowsconversion_supportedfdsystem_has_native_ansihave_ttyneed_conversions              r   r   zAnsiToWin32.__init__Q   s    # $GT2WW_

  *;km	!B &0!K3G3K{{)))Bdkk.@.@.B.M7M3M =#38|E
 ?%2(G  //1 3)  	B	s   C2 2D ?D c                 R    | j                   xs | j                  xs | j                  S )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()
        )rP   rO   rL   r,   s    r   should_wrapzAnsiToWin32.should_wrapy   s      ||;tzz;T^^;r   c                    | j                   rt        ri t        j                  t        j                  ft        j
                  t        j                  t        j
                  ft        j                  t        j                  t        j                  ft        j                  t        j                  t        j                  ft        j                  t        j                  t        j                  ft        j                  t        j                  t        j                  ft        j                  t        j                  t        j                  ft        j                   t        j                  t        j                   ft        j"                  t        j                  t        j"                  ft        j$                  t        j                  t        j$                  ft        j&                  t        j                  t        j&                  ft        j(                  t        j                  t        j*                  ft        j,                  t        j                  ft        j.                  t        j                  t        j                  dft        j0                  t        j                  t        j                  dft        j2                  t        j                  t        j                  dft        j4                  t        j                  t        j                   dfi t        j6                  t        j                  t        j"                  dft        j8                  t        j                  t        j$                  dft        j:                  t        j                  t        j&                  dft        j<                  t        j                  t        j*                  dft>        j                  t        j@                  t        j                  ft>        j                  t        j@                  t        j                  ft>        j                  t        j@                  t        j                  ft>        j                   t        j@                  t        j                   ft>        j"                  t        j@                  t        j"                  ft>        j$                  t        j@                  t        j$                  ft>        j&                  t        j@                  t        j&                  ft>        j(                  t        j@                  t        j*                  ft>        j,                  t        j@                  ft>        j.                  t        j@                  t        j                  dft>        j0                  t        j@                  t        j                  dft>        j2                  t        j@                  t        j                  dft>        j4                  t        j@                  t        j                   dft>        j6                  t        j@                  t        j"                  dft>        j8                  t        j@                  t        j$                  dft>        j:                  t        j@                  t        j&                  dft>        j<                  t        j@                  t        j*                  dfiS tC               S r>   )"rP   wintermr   	RESET_ALL	reset_allBRIGHTstyler   DIMNORMALr   BLACKforer   REDGREENYELLOWBLUEMAGENTACYANWHITEGREYRESETLIGHTBLACK_EXLIGHTRED_EXLIGHTGREEN_EXLIGHTYELLOW_EXLIGHTBLUE_EXLIGHTMAGENTA_EXLIGHTCYAN_EXLIGHTWHITE_EXr   backdictr,   s    r   rQ   zAnsiToWin32.get_win32_calls   s   <<G'##g&7&7%:'  7==(//"B' x?'   7==(//"B	'
 x~~ >' w||X\\:' x~~ >' ',,!@' hmm<'   7<<1A1A"B' hmm<' x}} ='  0' &&x~~t(L' $$w||X\\4&H'  &&x~~t(L!'" ''',,)N#'$ %%hmmT'J%'& ((7<<9I9I4*P''( %%hmmT'J)'* &&x}}d(K+', x~~ >-'. w||X\\:/'0 x~~ >1'2 ',,!@3'4 hmm<5'6   7<<1A1A"B7'8 hmm<9': x}} =;'<  0='> &&x~~t(L?'@ $$w||X\\4&HA'B &&x~~t(LC'D ''',,)NE'F %%hmmT'J((7<<9I9I4*P%%hmmT'J&&x}}d(KM' 'P vr   c                     | j                   s| j                  r| j                  |       n5| j                  j	                  |       | j                  j                          | j                  r| j                          y y r   )rO   rP   write_and_convertr   r/   flushrL   r`   r0   s     r   r/   zAnsiToWin32.write   sU    ::""4(LLt$LL >>NN r   c                     | j                   r| j                  dd       y | j                  sA| j                  j                  s*| j
                  j                  t        j                         y y y )Nmr   )	rP   
call_win32rO   r;   r?   r   r/   r   r_   r,   s    r   r`   zAnsiToWin32.reset_all   sG    <<OOC&DKK$6$6LLu/ %7r   c                 ,   d}| j                  |      }| j                  j                  |      D ]G  }|j                         \  }}| j	                  |||        | j
                  |j                           |}I | j	                  ||t        |             y)z
        Write the given text to our wrapped stream, stripping any ANSI
        sequences from the text, and optionally converting them into win32
        calls.
        r   N)convert_oscANSI_CSI_REfinditerspanwrite_plain_textconvert_ansigroupslen)r   r1   cursormatchstartends         r   r{   zAnsiToWin32.write_and_convert   s     %%%..t4EJE3!!$6Du||~.F	 5
 	dFCI6r   c                     ||k  r9| j                   j                  |||        | j                   j                          y y r   )r   r/   r|   )r   r1   r   r   s       r   r   zAnsiToWin32.write_plain_text   s6    3;LLtE#/LL  r   c                 f    | j                   r%| j                  ||      }| j                  ||       y y r   )rP   extract_paramsr   )r   paramstringcommandparamss       r   r   zAnsiToWin32.convert_ansi   s.    <<((+>FOOGV, r   c                    |dv rEt        d |j                  d      D              }t        |      dk  r|dz   }t        |      dk  r|S t        d |j                  d      D              }t        |      dk(  r|dv rd	}|S |d
v rd}|S )NHfc              3   R   K   | ]  }t        |      d k7  rt        |      nd ! yw)r   r   Nr   int.0ps     r   	<genexpr>z-AnsiToWin32.extract_params.<locals>.<genexpr>   s&     XAWASVq[3q6a7AWs   %';   )r   c              3   P   K   | ]  }t        |      d k7  st        |         yw)r   Nr   r   s     r   r   z-AnsiToWin32.extract_params.<locals>.<genexpr>   s!     Q+AaSVq[3q6+As   &&r   JKmr   ABCD)tuplesplitr   )r   r   r   r   s       r   r   zAnsiToWin32.extract_params   s    d?XARARSVAWXXFf+/$ f+/  Q;+<+<S+AQQF6{ae#!F  &!Fr   c                     |dk(  rN|D ]H  }|| j                   v s| j                   |   }|d   }|dd  }t        | j                        } ||i | J y |dv r%t        j	                  |d   | j                         y |dv r%t        j                  |d   | j                         y |dv r"t        j                  || j                         y |dv r?|d   }d| fd|f|df| dfd	|   \  }	}
t        j                  |	|
| j                         y y )
Nr~   r   r   )rT   JKr   r   )ABCD)rR   ry   rT   r^   erase_screen
erase_lineset_cursor_positioncursor_adjust)r   r   r   param	func_argsfuncr"   r#   nxys              r   r   zAnsiToWin32.call_win32   s   c>D,,, $ 0 0 7I$Q<D$QR=D!DNN;F$)&)   ^  dnn E^vayDNNC_''$..'Iq	AaR1vQF1"aI'RDAq!!!Q$..!A	 r   c                 H   | j                   j                  |      D ]  }|j                         \  }}|d | ||d  z   }|j                         \  }}|t        k(  s>|j                  d      dk(  sS|j                  d      }|d   dv slt        j                  |d           |S )Nr   r   r   02)	ANSI_OSC_REr   r   r   r   countr   r^   	set_title)r   r1   r   r   r   r   r   r   s           r   r   zAnsiToWin32.convert_osc  s    %%..t4EJE3<$st*,D#(<<> K#~$$S)Q.(..s3F ayD())&)4 5 r   c                 8    | j                   j                          y r   )r   r|   r,   s    r   r|   zAnsiToWin32.flush  s    r   )NNF)rA   rB   rC   rD   recompiler   r   r   r\   rQ   r/   r`   r{   r   r   r   r   r   r|   rF   r   r   rH   rH   H   sj    
 "**FGK"**<=K&4P<*X07 !-$B, r   rH   )r   r6   r4   ansir   r   r   r   r   r^   r	   r
   r   r   win32r   r   objectr   rH   rF   r   r   <module>r      sL    	 
 	 ; ; F F & 	iG5F 5pM& Mr   