§
    xÅjÔ  ã                   óæ  — d Z ddlmZ ddlmZmZmZmZ ddlZddl	Z	ddl
Z
ddlmZmZ e
j        dk    Z	 e
j        dk    r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 nddlZddlZddlZddlZe
j        dk    rd
eee         ee         f         fd„Z nd
eee         ee         f         fd„Z d
eeef         fd„Z!ded
e"fd„Z#ded
e"fd„Z$eded
ed         fd„¦   «         Z%ded
e"fd„Z&ded
efd„Z'dS )zî
Utility functions surrounding terminal devices & I/O.

Much of this code performs platform-sensitive branching, e.g. Windows support.

This is its own module to abstract away what would otherwise be distracting
logic-flow interruptions.
é    )Úcontextmanager)Ú	GeneratorÚIOÚOptionalÚTupleNé   )Ú
has_filenoÚisattyÚwin32)Ú	StructureÚc_ushortÚwindllÚPOINTERÚbyref)ÚHANDLEÚ_COORDÚ_SMALL_RECTÚreturnc                  ó–  —  G d„ dt           ¦  «        } t          j        j        }t          j        j        }t
          |_        t
          t          | ¦  «        g|_         |d¦  «        } | ¦   «         } ||t          |¦  «        ¦  «        }|r<|j
        j        |j
        j        z
  dz   }|j
        j        |j
        j        z
  dz   }||fS dS )Nc                   ó0   — e Zd ZdefdefdefdefdefgZdS )ú-_pty_size.<locals>.CONSOLE_SCREEN_BUFFER_INFOÚdwSizeÚdwCursorPositionÚwAttributesÚsrWindowÚdwMaximumWindowSizeN)Ú__name__Ú
__module__Ú__qualname__r   r   r   Ú_fields_© ó    úAC:\Projects\Historical\venv\Lib\site-packages\invoke/terminals.pyÚCONSOLE_SCREEN_BUFFER_INFOr   3   s=   € € € € € à˜6Ð"Ø# VÐ,Ø Ð)Ø˜[Ð)Ø&¨Ð/ðˆHˆHˆHr"   r$   iõÿÿÿr   ©NN)r   r   Úkernel32ÚGetStdHandleÚGetConsoleScreenBufferInfor   Úrestyper   Úargtypesr   r   ÚRightÚLeftÚBottomÚTop)r$   r'   r(   ÚhstdÚcsbiÚretÚsizexÚsizeys           r#   Ú	_pty_sizer4   2   så   € ð	ð 	ð 	ð 	ð 	­ñ 	ô 	ð 	õ ”Ô3ˆÝ%+¤_Ô%OÐ"Ý%ˆÔåÝÐ.Ñ/Ô/ð/
Ð"Ô+ð
 ˆ|˜CÑ Ô ˆØ)Ð)Ñ+Ô+ˆØ(Ð(¨­u°T©{¬{Ñ;Ô;ˆàð 	 Ø”MÔ'¨$¬-Ô*<Ñ<¸qÑ@ˆEØ”MÔ(¨4¬=Ô+<Ñ<¸qÑ@ˆEØ˜%�<Ðà�<r"   c                  ó  — d} d}t          j        |dddd¦  «        }	 t          j        t          j        t          j        |¦  «        }t          j        ||¦  «        ^}}}||fS # t           j	        t          t          t          f$ r Y nw xY w| S )zS
        Suitable for most POSIX platforms.

        .. versionadded:: 1.0
        r%   ÚHHHHr   )ÚstructÚpackÚfcntlÚioctlÚsysÚstdoutÚtermiosÚ
TIOCGWINSZÚunpackÚerrorÚ	TypeErrorÚIOErrorÚAttributeError)ÚsizeÚfmtÚbufÚresultÚrowsÚcolsÚ_s          r#   r4   r4   Q   s™   € ð ˆð ˆåŒk˜#˜q ! Q¨Ñ*Ô*ˆð	Ý”[¥¤­WÔ-?ÀÑEÔEˆFõ $œ]¨3°Ñ7Ô7ˆNˆD�$˜Ø˜$�<Ðøõ ”�i­µ.ÐAð 	ð 	ð 	ØˆDð	øøøàˆs   žAA$ Á$"B	ÂB	c                  ó4   — t          ¦   «         \  } }| pd|pdfS )zù
    Determine current local pseudoterminal dimensions.

    :returns:
        A ``(num_cols, num_rows)`` two-tuple describing PTY size. Defaults to
        ``(80, 24)`` if unable to get a sensible result dynamically.

    .. versionadded:: 1.0
    éP   é   )r4   )rI   rH   s     r#   Úpty_sizerN   t   s$   € õ ‘”�J€Dˆ$àˆJ�B˜˜
 Ð#Ð#r"   Ústreamc                 óš   — t          | ¦  «        sdS t          j        ¦   «         t          j        |                      ¦   «         ¦  «        k    S )aë  
    Detect if given stdin ``stream`` seems to be in the foreground of a TTY.

    Specifically, compares the current Python process group ID to that of the
    stream's file descriptor to see if they match; if they do not match, it is
    likely that the process has been placed in the background.

    This is used as a test to determine whether we should manipulate an active
    stdin so it runs in a character-buffered mode; touching the terminal in
    this way when the process is backgrounded, causes most shells to pause
    execution.

    .. note::
        Processes that aren't attached to a terminal to begin with, will always
        fail this test, as it starts with "do you have a real ``fileno``?".

    .. versionadded:: 1.0
    F)r	   ÚosÚgetpgrpÚ	tcgetpgrpÚfileno)rO   s    r#   Ústdin_is_foregrounded_ttyrU   ƒ   s<   € õ& �fÑÔð ØˆuÝŒ:‰<Œ<�2œ<¨¯ª©¬Ñ8Ô8Ò8Ð8r"   c                 ó0  — t          j        | ¦  «        }|d         |d         }}t          |t           j        z  ¦  «        }t          |t           j        z  ¦  «        }| | |t           j                 dv |t           j                 dv f}t          |¦  «        S )Né   é   )r   ó   )r   ó    )r=   Ú	tcgetattrÚboolÚECHOÚICANONÚVMINÚVTIMEÚall)rO   ÚattrsÚlflagsÚccÚechoÚicanonÚ	sentinelss          r#   Úcbreak_already_setrh   ›   sŒ   € õ Ô˜fÑ%Ô%€EØ�q”˜5 œ8ˆB€FÝ��œÑ%Ñ&Ô&€DÝ�&�7œ>Ñ)Ñ*Ô*€Fð
 ˆØˆ
Ø
�7Œ<Ô˜LÐ(Ø
�7Œ=Ô˜\Ð)ð	€Iõ ˆy‰>Œ>Ðr"   )NNNc              #   ób  K  — t           s-t          | ¦  «        rt          | ¦  «        rt          | ¦  «        rdV — dS t	          j        | ¦  «        }t          j        | ¦  «         	 dV — t	          j        | t          j	        |¦  «         dS # t	          j        | t          j	        |¦  «         w xY w)z«
    Force local terminal ``stream`` be character, not line, buffered.

    Only applies to Unix-based systems; on Windows this is a no-op.

    .. versionadded:: 1.0
    N)
ÚWINDOWSr
   rU   rh   r=   r[   ÚttyÚ	setcbreakÚ	tcsetattrÚ	TCSADRAIN)rO   Úold_settingss     r#   Úcharacter_bufferedrp   ±   sÀ   è è € õ 	ðGå�f‰~Œ~ðGõ )¨Ñ0Ô0ðGõ ˜fÑ%Ô%ð	Gð 	ˆˆˆˆˆåÔ(¨Ñ0Ô0ˆÝŒ�fÑÔÐð	GØˆEˆEˆEåÔ˜f¥gÔ&7¸ÑFÔFÐFÐFÐFø�GÔ˜f¥gÔ&7¸ÑFÔFÐFÐFøøøs   Á&B Â"B.Úinput_c                 óÔ   — t          | ¦  «        sdS t          j        dk    rt          j        ¦   «         S t          j        | gg g d¦  «        \  }}}t          |o	|d         | u ¦  «        S )zá
    Test ``input_`` to determine whether a read action will succeed.

    :param input_: Input stream object (file-like).

    :returns: ``True`` if a read should succeed, ``False`` otherwise.

    .. versionadded:: 1.0
    Tr   g        r   )r	   r;   ÚplatformÚmsvcrtÚkbhitÚselectr\   )rq   ÚreadsrJ   s      r#   Úready_for_readingrx   Ì   sk   € õ �fÑÔð ØˆtÝ
„|�wÒÐÝŒ|‰~Œ~Ðå”m V H¨b°"°cÑ:Ô:‰ˆˆq�!Ý�EÐ0˜e Aœh¨&Ð0Ñ1Ô1Ð1r"   c                 óà   — t           sft          | ¦  «        rWt          | ¦  «        rHt          j        | t
          j        d¦  «        }t          t          j	        d|¦  «        d         ¦  «        S dS )a|  
    Query stream ``input_`` to see how many bytes may be readable.

    .. note::
        If we are unable to tell (e.g. if ``input_`` isn't a true file
        descriptor or isn't a valid TTY) we fall back to suggesting reading 1
        byte only.

    :param input: Input stream object (file-like).

    :returns: `int` number of bytes to read.

    .. versionadded:: 1.0
    s     Úhr   r   )
rj   r
   r	   r9   r:   r=   ÚFIONREADÚintr7   r?   )rq   Úfionreads     r#   Úbytes_to_readr~   ã   sb   € õ$ ð 4•v˜f‘~”~ð 4­*°VÑ*<Ô*<ð 4Ý”;˜v¥wÔ'7¸Ñ?Ô?ˆÝ•6”=  hÑ/Ô/°Ô2Ñ3Ô3Ð3Øˆ1r"   )(Ú__doc__Ú
contextlibr   Útypingr   r   r   r   rQ   rv   r;   Úutilr	   r
   rs   rj   rt   Úctypesr   r   r   r   r   Úctypes.wintypesr   r   r   r9   r7   r=   rk   r|   r4   rN   r\   rU   rh   rp   rx   r~   r!   r"   r#   ú<module>r…      s”  ððð ð &Ð %Ð %Ð %Ð %Ð %Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 	€	€	€	Ø €€€Ø 
€
€
€
ð %Ð $Ð $Ð $Ð $Ð $Ð $Ð $ð Œ,˜'Ò
!€ðð „<�7ÒÐØ€M€M€Mðð ð ð ð ð ð ð ð ð ð ð ð ð ð <Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ð;à€L€L€LØ€M€M€MØ€N€N€NØ€J€J€Jð „<�7ÒÐð �u˜X cœ]¨H°S¬MÐ9Ô:ð  ð  ð  ð  ð  ð> �u˜X cœ]¨H°S¬MÐ9Ô:ð  ð  ð  ð  ðF$�%˜˜S˜”/ð $ð $ð $ð $ð9 bð 9¨Tð 9ð 9ð 9ð 9ð0˜rð  dð ð ð ð ð, ðGØðGàÐÔ ðGð Gð Gñ „ðGð42˜bð 2 Tð 2ð 2ð 2ð 2ð.˜"ð  ð ð ð ð ð ð r"   