
    gf,E                        d Z ddlZddlZddlZddlmZ ddlZ ej                         dk(  rddlZ	ddl
mZ n
ddl	Z	ddlmZ  G d dej                        Zd Zd	 Zd
 Zd Zd Zd Zd Zd ZdZ e e       j5                               ZeD ]  Zedz  Ze e       dez   <    g  ej<                  d      e	j>                  f ej<                  d      e	j>                  f ej<                  d      e	j@                  f ej<                  d      e!f ej<                  d      e	jD                  f ej<                  d      e	j@                  fde	jF                  fde	jH                  fde	jJ                  fde	jL                  fde	jN                  fde	jP                  fde	jR                  fd e	jT                  fd!e	jV                  fd"e	jX                  fd#e	jV                  fd$e	jZ                  fd%e	j\                  fd&e	j>                  fd'e/fd(e0fd)e1fd*e2fd+e3fd,e4fd-e5fd.e6fd/e7fd0e8fd1e9fd2e:fd3e;fd4e<fd5e=fd6e>fd7e?fd8e	j                  fd9e	j                  fd:e	j                  fd;e	j                  fd<e	j\                  fd=e	jZ                  fd>e	jX                  fd?e	jV                  fd@e	jF                  fdAe	jH                  fdBe	jJ                  fdCe	jL                  fdDe	jV                  fdEe	jX                  fdFe	j                  fdGe	j                  fdHe	j                  fdIe	j                  fZHdJe	j                  fdKe	j                  fdLe	j\                  fdMe	jZ                  fdNe	jD                  fdOe	jN                  fdPe	jP                  fdQe	j                  fdRe	j                  fdSe	j                  fdTe	j                  ffZMdUZNy)Vz*Sub-module providing 'keyboard awareness'.    N)OrderedDictWindows)_capability_namesc                       e Zd ZdZddZed        Zd Zej                  j                  e_        ed        Z
ed        Zy)		Keystrokea  
    A unicode-derived class for describing a single keystroke.

    A class instance describes a single keystroke received on input,
    which may contain multiple characters as a multibyte sequence,
    which is indicated by properties :attr:`is_sequence` returning
    ``True``.

    When the string is a known sequence, :attr:`code` matches terminal
    class attributes for comparison, such as ``term.KEY_LEFT``.

    The string-name of the sequence, such as ``u'KEY_LEFT'`` is accessed
    by property :attr:`name`, and is used by the :meth:`__repr__` method
    to display a human-readable form of the Keystroke this class
    instance represents. It may otherwise by joined, split, or evaluated
    just as as any other unicode string.
    Nc                 b    t         j                  j                  | |      }||_        ||_        |S )zClass constructor.)six	text_type__new___name_code)clsucscodenamenews        h/var/dept/share/cheung/public_html/OutSchool/python/env/lib/python3.12/site-packages/blessed/keyboard.pyr   zKeystroke.__new__*   s+    mm##C-		
    c                     | j                   duS )z9Whether the value represents a multibyte sequence (bool).Nr   selfs    r   is_sequencezKeystroke.is_sequence1   s     zz%%r   c                 p    | j                   t        j                  j                  |       S | j                   S )zDocstring overwritten.)r   r	   r
   __repr__r   s    r   r   zKeystroke.__repr__6   s.    04

0B&&t, 	

	r   c                     | j                   S )z;String-name of key sequence, such as ``u'KEY_LEFT'`` (str).)r   r   s    r   r   zKeystroke.name<        zzr   c                     | j                   S )z2Integer keycode value of multibyte sequence (int).r   r   s    r   r   zKeystroke.codeA   r   r   ) NN)__name__
__module____qualname____doc__r   propertyr   r   r	   r
   r   r    r   r   r   r      s_    $ & & }},,H   r   r   c                      t        t              D  cg c]  } | j                  d      r|  }} |D ci c]  }|t        t        |       c}S c c} w c c}w )a1  
    Return mapping of curses key-names paired by their keycode integer value.

    :rtype: dict
    :returns: Dictionary of (name, code) pairs for curses keyboard constant
        values and their mnemonic name. Such as code ``260``, with the value of
        its key-name identity, ``u'KEY_LEFT'``.
    KEY_)dircurses
startswithgetattr)attr	_keynameskeynames      r   get_curses_keycodesr/   G   sU     #&f+ -$OOF+  -I -=FG'GWVW--GG-Gs
   AAc                  ,   t        t                     } | j                  t               | j                  d t	               j                         j                         D               t        t        | j                         | j                                     S )a?  
    Return mapping of keycode integer values paired by their curses key-name.

    :rtype: dict
    :returns: Dictionary of (code, name) pairs for curses keyboard constant
        values and their mnemonic name. Such as key ``260``, with the value of
        its identity, ``u'KEY_LEFT'``.

    These keys are derived from the attributes by the same of the curses module,
    with the following exceptions:

    * ``KEY_DELETE`` in place of ``KEY_DC``
    * ``KEY_INSERT`` in place of ``KEY_IC``
    * ``KEY_PGUP`` in place of ``KEY_PPAGE``
    * ``KEY_PGDOWN`` in place of ``KEY_NPAGE``
    * ``KEY_ESCAPE`` in place of ``KEY_EXIT``
    * ``KEY_SUP`` in place of ``KEY_SR``
    * ``KEY_SDOWN`` in place of ``KEY_SF``

    This function is the inverse of :func:`get_curses_keycodes`.  With the
    given override "mixins" listed above, the keycode for the delete key will
    map to our imaginary ``KEY_DELETE`` mnemonic, effectively erasing the
    phrase ``KEY_DC`` from our code vocabulary for anyone that wishes to use
    the return value to determine the key-name by keycode.
    c              3   N   K   | ]  \  }}|j                  d       s||f  yw)r'   N)r*   ).0r   values      r   	<genexpr>z%get_keyboard_codes.<locals>.<genexpr>r   s)      %$T__U[E\us   %	%)r   r/   updateCURSES_KEYCODE_OVERRIDE_MIXINglobalscopyitemsdictzipvalueskeys)keycodess    r   get_keyboard_codesr?   U   sk    4 .01HOO12OO )0)9)?)?)A  HOO%x}}788r   c                     i }| j                   r,| j                   dk7  rt        j                  || j                   <   | j                  r,| j                  dk7  rt        j                  || j                  <   |S )a  
    Determine and return mapping of left and right arrow keys sequences.

    :arg blessed.Terminal term: :class:`~.Terminal` instance.
    :rtype: dict
    :returns: Dictionary of sequences ``term._cuf1``, and ``term._cub1``,
        valued as ``KEY_RIGHT``, ``KEY_LEFT`` (when appropriate).

    This function supports :func:`get_terminal_sequences` to discover
    the preferred input sequence for the left and right application keys.

    It is necessary to check the value of these sequences to ensure we do not
    use ``u' '`` and ``u'\b'`` for ``KEY_RIGHT`` and ``KEY_LEFT``,
    preferring their true application key sequence, instead.
     )_cuf1r)   	KEY_RIGHT_cub1KEY_LEFT)termkeymaps     r   _alternative_left_rightrI   {   sX    " FzzdjjD(#--tzzzzdjjE)#__tzzMr   c                 8   t        | j                  r"d d t        j                         D        D        nd      j	                  t        |              j	                  t               t        fdt        j                         t        d      D              S )a  
    Return mapping of keyboard sequences paired by keycodes.

    :arg blessed.Terminal term: :class:`~.Terminal` instance.
    :returns: mapping of keyboard unicode sequences paired by keycodes
        as integer.  This is used as the argument ``mapper`` to
        the supporting function :func:`resolve_sequence`.
    :rtype: OrderedDict

    Initialize and return a keyboard map and sequence lookup table,
    (sequence, keycode) from :class:`~.Terminal` instance ``term``,
    where ``sequence`` is a multibyte input sequence of unicode
    characters, such as ``u'\x1b[D'``, and ``keycode`` is an integer
    value, matching curses constant such as term.KEY_LEFT.

    The return value is an OrderedDict instance, with their keys
    sorted longest-first.
    c              3   L   K   | ]  \  }}|r|j                  d       |f  yw)latin1N)decode)r2   seqvals      r   r4   z)get_keyboard_sequences.<locals>.<genexpr>   s/      S# 	 
H	s#s   "$c              3   P   K   | ]  \  }}t        j                  |      |f   y wN)r)   tigetstr)r2   rO   caps      r   r4   z)get_keyboard_sequences.<locals>.<genexpr>   s*      
c __S!3'
s   $&r%   c              3   ,   K   | ]  }||   f  y wrQ   r%   )r2   rN   sequence_maps     r   r4   z)get_keyboard_sequences.<locals>.<genexpr>   s       9%(l3 9s   T)keyreverse)r:   does_stylingcapability_namesr9   r5   rI   DEFAULT_SEQUENCE_MIXINr   sortedr=   len)rG   rU   s    @r   get_keyboard_sequencesr]      s    <  
		
.446
 !#$L /56./
  9,2S$-89 : :r   c           
      l    | D ch c]!  }t        dt        |            D ]  }|d| 	 # c}}S c c}}w )a  
    Return a set of proper prefixes for given sequence of strings.

    :arg iterable sequences
    :rtype: set
    :return: Set of all string prefixes

    Given an iterable of strings, all textparts leading up to the final
    string is returned as a unique set.  This function supports the
    :meth:`~.Terminal.inkey` method by determining whether the given
    input is a sequence that **may** lead to a final matching pattern.

    >>> prefixes(['abc', 'abdf', 'e', 'jkl'])
    set([u'a', u'ab', u'abd', u'j', u'jk'])
       N)ranger\   )	sequencesrN   is      r   get_leading_prefixesrc      s5       )E%3s82DEQCGEGEEEs   &0c                     |j                         D ])  \  }}| j                  |      st        ||||         c S  t        | xr | d   xs d      S )a  
    Return a single :class:`Keystroke` instance for given sequence ``text``.

    :arg str text: string of characters received from terminal input stream.
    :arg OrderedDict mapper: unicode multibyte sequences, such as ``u'\x1b[D'``
        paired by their integer value (260)
    :arg dict codes: a :type:`dict` of integer values (such as 260) paired
        by their mnemonic name, such as ``'KEY_LEFT'``.
    :rtype: Keystroke
    :returns: Keystroke instance for the given sequence

    The given ``text`` may extend beyond a matching sequence, such as
    ``u\x1b[Dxxx`` returns a :class:`Keystroke` instance of attribute
    :attr:`Keystroke.sequence` valued only ``u\x1b[D``.  It is up to
    calls to determine that ``xxx`` remains unresolved.
    )r   r   r   r   r   )r   )r9   r*   r   )textmappercodessequencer   s        r   resolve_sequenceri      sY    " !,,. H$??8$5;GGH )$q'0S11r   c                 R    |r$t        d|t        j                         | z
  z
        S |S )a  
    Return time remaining since ``stime`` before given ``timeout``.

    This function assists determining the value of ``timeout`` for
    class method :meth:`~.Terminal.kbhit` and similar functions.

    :arg float stime: starting time for measurement
    :arg float timeout: timeout period, may be set to None to
       indicate no timeout (where None is always returned).
    :rtype: float or int
    :returns: time remaining as float. If no time is remaining,
       then the integer ``0`` is returned.
    r   )maxtime)stimetimeouts     r   
_time_leftro      s(     7>3q'TYY[5012J7Jr   c                 
   t        j                          }d\  }}	 | j                  t        ||            }|r||z  }| j                  d      }|rt        j                  ||      }|	 ||fS |t        ||      s	 ||fS j)a?  
    Convenience read-until-pattern function, supporting :meth:`~.get_location`.

    :arg blessed.Terminal term: :class:`~.Terminal` instance.
    :arg float timeout: timeout period, may be set to None to indicate no
        timeout (where 0 is always returned).
    :arg str pattern: target regular expression pattern to seek.
    :rtype: tuple
    :returns: tuple in form of ``(match, str)``, *match*
        may be :class:`re.MatchObject` if pattern is discovered
        in input stream before timeout has elapsed, otherwise
        None. ``str`` is any remaining text received exclusive
        of the matching pattern).

    The reason a tuple containing non-matching data is returned, is that the
    consumer should push such data back into the input buffer by
    :meth:`~.Terminal.ungetch` if any was received.

    For example, when a user is performing rapid input keystrokes while its
    terminal emulator surreptitiously responds to this in-band sequence, we
    must ensure any such keyboard data is well-received by the next call to
    term.inkey() without delay.
    )Nr   )rn   r   )patternstring)rl   inkeyro   research)rG   rq   rn   rm   matchbufr   s          r   _read_untilrx      s    0 IIKEJE3  jjE7!;j<
 3JC**Q*'C  		'#6 #:	 z%'A#:+ r   )TABKP_MULTIPLYKP_ADDKP_SEPARATORKP_SUBTRACT
KP_DECIMAL	KP_DIVIDEKP_EQUALKP_0KP_1KP_2KP_3KP_4KP_5KP_6KP_7KP_8KP_9r_   r'   
         	         z[Az[Bz[Cz[Dz[1;2Az[1;2Bz[1;2Cz[1;2Dz[Fz[Hz[Kz[Uz[VzOMzOjzOkzOlzOmzOnzOozOXzOpzOqzOrzOszOtzOuzOvzOwzOxzOyz[1~z[2~z[3~z[4~z[5~z[6~z[7~z[8~z[OAz[OBz[OCz[ODz[OFz[OHzOPzOQzORzOS
KEY_DELETE
KEY_INSERTKEY_PGUP
KEY_PGDOWN
KEY_ESCAPEKEY_SUP	KEY_SDOWNKEY_UP_LEFTKEY_UP_RIGHT
KEY_CENTER	KEY_BEGIN)r   r?   r]   )Or#   rt   rl   platformcollectionsr   r	   systemjinxedr)   jinxed.has_keyr   rY   curses.has_keyr
   r   r/   r?   rI   r]   rc   ri   ro   rx   _CURSES_KEYCODE_ADDINSrk   r<   _LASTVALkeycode_namer7   unichr	KEY_ENTERKEY_BACKSPACEKEY_TABKEY_EXITKEY_UPKEY_DOWNrD   rF   KEY_SRKEY_SF
KEY_SRIGHT	KEY_SLEFTKEY_ENDKEY_HOME	KEY_NPAGE	KEY_PPAGEKEY_KP_MULTIPLY
KEY_KP_ADDKEY_KP_SEPARATORKEY_KP_SUBTRACTKEY_KP_DECIMALKEY_KP_DIVIDEKEY_KP_EQUALKEY_KP_0KEY_KP_1KEY_KP_2KEY_KP_3KEY_KP_4KEY_KP_5KEY_KP_6KEY_KP_7KEY_KP_8KEY_KP_9KEY_FINDKEY_ICKEY_DC
KEY_SELECTKEY_F1KEY_F2KEY_F3KEY_F4rZ   KEY_A1KEY_A3KEY_B2KEY_BEGr6   __all__r%   r   r   <module>r      s   0 
   #  8??	!DD- -`H#9L2.:bF&2.K"5@ ( "$++-.* 0LMH'/GIf|#$0&H SZZ^V%%&H SZZ^V%%&	H
 SZZ]F(()H SZZ]GH SZZ^V__%H SZZ_f**+H H  H   !H  H 6==!H 6==!H  6$$%!H" 6##$#H$ %H&  'H* +H,   !-H.   !/H<   !=H>  ?H@ 
AHB  !CHD  EHF GHH IHJ KHL MHN OHP QHR SHT UHV WHX YHZ [H\ ]H^ _Hd !eHf gHh iHj ""#kHl !!"mHn !!"oHp !qHr  sHt uHv !wHx !!"yHz !{H|  }H~ !HH IHJ KHL MHN OH \ 6==!6==!!!"6##$6??#&-- FMM"V]]#6==!&..!!  Ir   