Ë
    zñ�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'y)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        |«      «      }|rd|j                  j                  |j                  j                  z
  dz   }|j                  j                  |j                  j                  z
  dz   }||fS y)Nc                   ó.   — e Zd ZdefdefdefdefdefgZy)ú-_pty_size.<locals>.CONSOLE_SCREEN_BUFFER_INFOÚdwSizeÚdwCursorPositionÚwAttributesÚsrWindowÚdwMaximumWindowSizeN)Ú__name__Ú
__module__Ú__qualname__r   r   r   Ú_fields_© ó    úQ/var/www/api.ozpay.ru/ozpay/venv/lib/python3.12/site-packages/invoke/terminals.pyÚCONSOLE_SCREEN_BUFFER_INFOr   3   s1   „ à˜6Ð"Ø# VÐ,Ø Ð)Ø˜[Ð)Ø&¨Ð/ð‰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Ñ3ˆÜ%+§_¡_×%OÑ%OÐ"Ü%ˆÔäÜÐ.Ó/ð/
Ð"Ô+ñ
 ˜CÓ ˆÙ)Ó+ˆÙ(¨¬u°T«{Ó;ˆáØ—M‘M×'Ñ'¨$¯-©-×*<Ñ*<Ñ<¸qÑ@ˆEØ—M‘M×(Ñ(¨4¯=©=×+<Ñ+<Ñ<¸qÑ@ˆEØ˜%�<Ðàr"   c                  ó2  — 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 | S w xY w)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‰k˜#˜q ! Q¨Ó*ˆð	Ü—[‘[¤§¡¬W×-?Ñ-?ÀÓEˆFô $Ÿ]™]¨3°Ó7ˆNˆD�$˜Ø˜$�<Ðøô —‘œi¬´.ÐAò 	ØØˆð	ús   ŸAA/ Á/#BÂBc                  ó4   — t        «       \  } }| xs d|xs 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yt        j                  «       t        j                  | 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ÔØÜ�:‰:‹<œ2Ÿ<™<¨¯©«Ó8Ñ8Ð8r"   c                 ó"  — 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              #   ó`  K  — t         s!t        | «      rt        | «      rt        | «      rd–— yt	        j
                  | «      }t        j                  | «       	 d–— t	        j                  | t        j                  |«       y# t	        j                  | t        j                  |«       w xY w­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   ±   sz   è ø€ õ 	Ü�fŒ~Ü(¨Ô0Ü˜fÔ%ää×(Ñ(¨Ó0ˆÜ�‰�fÔð	GÛä×Ñ˜f¤g×&7Ñ&7¸ÕFøŒG×Ñ˜f¤g×&7Ñ&7¸ÕFüs   ‚AB.ÁB Á&B.Â'B+Â+B.Úinput_c                 óÊ   — t        | «      syt        j                  dk(  rt        j                  «       S t        j
                  | gg g d«      \  }}}t        |xr |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   Ì   s\   € ô �fÔØÜ
‡|�|�wÒÜ�|‰|‹~Ðä—m‘m V H¨b°"°cÓ:‰ˆˆq�!Ü�EÒ0˜e A™h¨&Ð0Ó1Ð1r"   c                 óÊ   — t         s]t        | «      rRt        | «      rGt        j                  | t
        j                  d«      }t        t        j                  d|«      d   «      S y)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~   ã   sJ   € õ$ ”v˜f”~¬*°VÔ*<Ü—;‘;˜v¤w×'7Ñ'7¸Ó?ˆÜ”6—=‘=  hÓ/°Ñ2Ó3Ð3Ør"   )(Ú__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Û 	Û Û 
÷ %ð �,‰,˜'Ñ
!€ðð ‡<�<�7ÒÛ÷õ ÷ <Ò;ãÛÛÛð ‡<�<�7Òð �u˜X c™]¨H°S©MÐ9Ñ:ô  ð> �u˜X c™]¨H°S©MÐ9Ñ:ó  ðF$�%˜˜S˜‘/ó $ð9 bð 9¨Tó 9ð0˜rð  dó ð, ðGØðGàÐÑ òGó ðGð42˜bð 2 Tó 2ð.˜"ð  ô r"   