U
    ouf                     @  s   d dl mZ d dlZejdks"td dlmZmZ d dlm	Z	m
Z
 d dlmZmZ d dlmZ d dlmZ d	d
lmZ d	dlmZ d	dlmZ d	dlmZ dgZd	ZdZG dd dZee ddddZdS )    )annotationsNwin32)byrefwindll)DWORDHANDLE)AnyTextIOSize)STD_OUTPUT_HANDLE   )Output)
ColorDepth)Vt100_Output)Win32OutputWindows10_Output   c                   @  sb   e Zd ZdZdddddddZdd	d
dZedd	ddZdddddZdd	ddZ	dS )r   zV
    Windows 10 output abstraction. This enables and uses vt100 escape sequences.
    Nr	   zColorDepth | NoneNone)stdoutdefault_color_depthreturnc                 C  s>   || _ t||d| _t|dd |d| _ttjt	| _
d S )N)r   c                   S  s
   t ddS )Nr   r
    r   r   C/tmp/pip-unpacked-wheel-8milen2s/prompt_toolkit/output/windows10.py<lambda>'       z+Windows10_Output.__init__.<locals>.<lambda>)r   r   win32_outputr   vt100_outputr   r   kernel32GetStdHandler   	_hconsole)selfr   r   r   r   r   __init__!   s      zWindows10_Output.__init__r   c              
   C  sZ   t d}tj| jt| tj| jt ttB  z| j	
  W 5 tj| j| X dS )z3
        Write to output stream and flush.
        r   N)r   r   r   GetConsoleModer    r   SetConsoleModeENABLE_PROCESSED_INPUT"ENABLE_VIRTUAL_TERMINAL_PROCESSINGr   flush)r!   original_moder   r   r   r(   +   s    
zWindows10_Output.flushboolc                 C  s   dS )NFr   r!   r   r   r   responds_to_cpr@   s    z Windows10_Output.responds_to_cprstrr   )namer   c                 C  s$   |dkrt | j|S t | j|S d S )N)get_sizeZget_rows_below_cursor_positionZenable_mouse_supportZdisable_mouse_supportZscroll_buffer_to_promptZget_win32_screen_buffer_infoZenable_bracketed_pasteZdisable_bracketed_paste)getattrr   r   )r!   r.   r   r   r   __getattr__D   s    
zWindows10_Output.__getattr__r   c                 C  s   | j dk	r| j S tjS )z
        Return the default color depth for a windows terminal.

        Contrary to the Vt100 implementation, this doesn't depend on a $TERM
        variable.
        N)r   r   Z
TRUE_COLORr+   r   r   r   get_default_color_depthS   s    
	z(Windows10_Output.get_default_color_depth)N)
__name__
__module____qualname____doc__r"   r(   propertyr,   r1   r2   r   r   r   r   r      s    
r*   r#   c               
   C  sp   t jdkrdS ttjt} td}tj| t	| z"tj
| tttB }|dkW S tj
| | X dS )z_
    Returns True when we're running Windows and VT100 escape sequences are
    supported.
    r   Fr   r   N)sysplatformr   r   r   r   r   r   r$   r   r%   r&   r'   )Zhconsoler)   resultr   r   r   is_win_vt100_enabledj   s    
 
r;   ) 
__future__r   r8   r9   AssertionErrorctypesr   r   Zctypes.wintypesr   r   typingr   r	   Zprompt_toolkit.data_structuresr   Zprompt_toolkit.win32_typesr   baser   Zcolor_depthr   Zvt100r   r   r   __all__r&   r'   r   registerr;   r   r   r   r   <module>   s$   K
