
    (ph&                     f    S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	  SSKJ
r   " S S	\5      r
g)
z7Module containing Windows version of :class:`Terminal`.    )absolute_importN)win32   )WINSZ)Terminalc                      ^  \ rS rSrSrU 4S jrS	S jr\S 5       r\	R                  S 5       r\	R                  S 5       rSrU =r$ )
r      z&Windows subclass of :class:`Terminal`.c                    > [         R                  (       a  [        [        U ]  5       $ [
        R                  " 5       nUS;   a  U[
        R                  " 5       -  nU$ )a  
Read, decode, and return the next byte from the keyboard stream.

:rtype: unicode
:returns: a single unicode character, or ``u''`` if a multi-byte
    sequence has not yet been fully received.

For versions of Windows 10.0.10586 and later, the console is expected
to be in ENABLE_VIRTUAL_TERMINAL_INPUT mode and the default method is
called.

For older versions of Windows, msvcrt.getwch() is used. If the received
character is ``\x00`` or ``\xe0``, the next character is
automatically retrieved.
)    à)r   VTMODE_SUPPORTEDsuperr   getchmsvcrtgetwch)selfrtn	__class__s     G/var/www/html/venv/lib/python3.13/site-packages/blessed/win_terminal.pyr   Terminal.getch   sG      !!4.00mmo""6==?"C
    c                     [         R                   " 5       U=(       d    S-   n [        R                  " 5       (       a  gUb  U[         R                   " 5       :  a   g[         R                  " S5        MQ  )aa  
Return whether a keypress has been detected on the keyboard.

This method is used by :meth:`inkey` to determine if a byte may
be read using :meth:`getch` without blocking.  This is implemented
by wrapping msvcrt.kbhit() in a timeout.

:arg float timeout: When ``timeout`` is 0, this call is
    non-blocking, otherwise blocking indefinitely until keypress
    is detected when None (default). When ``timeout`` is a
    positive number, returns after ``timeout`` seconds have
    elapsed (float).
:rtype: bool
:returns: True if a keypress is awaiting to be read on the keyboard
    attached to this terminal.
r   Tg{Gz?F)timer   kbhitsleep)r   timeoutends      r   r   Terminal.kbhit.   sW    " iikW\*||~~"sTYY['8  JJt r   c                 n    [         R                  " U 5      n[        UR                  UR                  SSS9$ )a  
Return named tuple describing size of the terminal by ``fd``.

:arg int fd: file descriptor queries for its window size.
:rtype: WINSZ
:returns: named tuple describing size of the terminal

WINSZ is a :class:`collections.namedtuple` instance, whose structure
directly maps to the return value of the :const:`termios.TIOCGWINSZ`
ioctl return value. The return parameters are:

    - ``ws_row``: width of terminal by its number of character cells.
    - ``ws_col``: height of terminal by its number of character cells.
    - ``ws_xpixel``: width of terminal by pixels (not accurate).
    - ``ws_ypixel``: height of terminal by pixels (not accurate).
r   )ws_rowws_col	ws_xpixel	ws_ypixel)r   get_terminal_sizer   linescolumns)fdwindows     r   _winsizeTerminal._winsizeK   s2    $ ((,FLL A/ 	/r   c              #   r  #    U R                   b  [        R                  " U R                   5      n[        R                  " U5      nU R
                  n[        R                  " U5         SU l        Sv   [        R                  " X5        X0l        gSv   g! [        R                  " X5        X0l        f = f7f)a  
Allow each keystroke to be read immediately after it is pressed.

This is a context manager for ``jinxed.w32.setcbreak()``.

.. note:: You must explicitly print any user input you would like
    displayed.  If you provide any kind of editing, you must handle
    backspace and other line-editing control functions in this mode
    as well!

**Normally**, characters received from the keyboard cannot be read
by Python until the *Return* key is pressed. Also known as *cooked* or
*canonical input* mode, it allows the tty driver to provide
line-editing before shuttling the input to your program and is the
(implicit) default terminal mode set by most unix shells before
executing programs.
NF)_keyboard_fdr   get_osfhandler   get_console_mode_line_buffered	setcbreakset_console_moder   
filehandle	save_modesave_line_buffereds       r   cbreakTerminal.cbreaka   s     & (--d.?.?@J ..z:I!%!4!4OOJ'9&+#&&z=&8# 	 &&z=&8#   A&B7)B 4"B7B44B7c              #   r  #    U R                   b  [        R                  " U R                   5      n[        R                  " U5      nU R
                  n[        R                  " U5         SU l        Sv   [        R                  " X5        X0l        gSv   g! [        R                  " X5        X0l        f = f7f)a  
A context manager for ``jinxed.w32.setcbreak()``.

Although both :meth:`break` and :meth:`raw` modes allow each keystroke
to be read immediately after it is pressed, Raw mode disables
processing of input and output.

In cbreak mode, special input characters such as ``^C`` are
interpreted by the terminal driver and excluded from the stdin stream.
In raw mode these values are receive by the :meth:`inkey` method.
NF)r,   r   r-   r   r.   r/   setrawr1   r2   s       r   rawTerminal.raw   s      (--d.?.?@J ..z:I!%!4!4LL$9&+#&&z=&8# 	 &&z=&8#r8   )r/   )N)__name__
__module____qualname____firstlineno____doc__r   r   staticmethodr)   
contextlibcontextmanagerr6   r;   __static_attributes____classcell__)r   s   @r   r   r      sY    00: / /* # #J  r   r   )rA   
__future__r   r   r   rC   jinxedr   terminalr   r   	_Terminal r   r   <module>rL      s1    = &      +Ry Rr   