§
    Pòmj©  ã                  ó6   — d Z ddlmZ d
d„Zd
d„Zd
d„Zd
d„Zd	S )u½  Augmentations to prompt_toolkit's input-parsing tables.

Imported once at CLI startup. Each helper installs a small mapping into
prompt_toolkit's `ANSI_SEQUENCES` so byte sequences emitted by modern
keyboard protocols (Kitty / xterm `modifyOtherKeys`) decode to existing
key tuples Hermes already binds.

Kept in a standalone module â€” separate from `cli.py` â€” so the registrations
can be unit-tested without importing the whole CLI runtime.
é    )ÚannotationsÚreturnÚintc                 ó´   — 	 ddl m}  ddlm} n# t          $ r Y dS w xY w|j        |j        f}d}dD ]%}|                      |¦  «        |k    r
|| |<   |dz  }Œ&|S )uÃ  Map Shift+Enter byte sequences to the (Escape, ControlM) key tuple
    that Alt+Enter produces, so the existing Alt+Enter newline handler
    fires for terminals that emit a distinct Shift+Enter.

    Sequences mapped:
      - "\x1b[13;2u"     â€” Kitty keyboard protocol / CSI-u, modifier=2 (Shift)
      - "\x1b[27;2;13~"  â€” xterm modifyOtherKeys=2, modifier=2 (Shift)
      - "\x1b[27;2;13u"  â€” alternate ordering some emitters use

    The CSI-u sequence is not in stock prompt_toolkit. The modifyOtherKeys
    variant `\x1b[27;2;13~` IS in stock prompt_toolkit but mapped to plain
    `Keys.ControlM` â€” i.e. Shift+Enter behaves identically to Enter, which
    is the very bug this helper exists to fix. We therefore overwrite
    those two specific keys (and `\x1b[27;2;13u`) unconditionally; other
    `\x1b[27;...;13~` sequences (Ctrl+Enter, Alt+Enter via modifyOtherKeys
    variants 5/6/etc.) are left untouched.

    Default macOS Terminal and stock Windows Terminal still send the same
    byte for Enter and Shift+Enter, so there is no fix for those terminals
    at the application layer â€” the sequences above never reach Hermes.

    Returns the number of sequences whose mapping was changed.
    r   ©ÚANSI_SEQUENCES©ÚKeys)z[13;2uz
[27;2;13~z
[27;2;13ué   ©Ú*prompt_toolkit.input.ansi_escape_sequencesr   Úprompt_toolkit.keysr
   Ú	ExceptionÚEscapeÚControlMÚget©r   r
   Ú	alt_enterÚchangedÚseqs        ú@/home/thesage/.hermes/hermes-agent/hermes_cli/pt_input_extras.pyÚinstall_shift_enter_aliasr      s¦   € ð0ØMÐMÐMÐMÐMÐMØ,Ð,Ð,Ð,Ð,Ð,Ð,øÝð ð ð Øˆqˆqðøøøð ”˜dœmÐ,€IØ€GØ?ð ð ˆØ×Ò˜cÑ"Ô" iÒ/Ð/Ø"+ˆN˜3ÑØq‰LˆGøØ€Nó   ‚ 
œc                 ó´   — 	 ddl m}  ddlm} n# t          $ r Y dS w xY w|j        |j        f}d}dD ]%}|                      |¦  «        |k    r
|| |<   |dz  }Œ&|S )u  Map Ctrl+Enter byte sequences to the (Escape, ControlM) key tuple
    that Alt+Enter produces, so the existing Alt+Enter newline handler
    fires for terminals that emit a distinct Ctrl+Enter.

    Sequences mapped:
      - "\x1b[13;5u"     â€” Kitty keyboard protocol / CSI-u, modifier=5 (Ctrl)
      - "\x1b[27;5;13~"  â€” xterm modifyOtherKeys=2, modifier=5 (Ctrl)
      - "\x1b[27;5;13u"  â€” alternate ordering some emitters use

    Stock prompt_toolkit doesn't map any of these. Without this alias,
    Kitty/mintty/xterm-with-modifyOtherKeys users over SSH never get a
    Ctrl+Enter newline â€” the keystroke arrives as a raw CSI sequence that
    falls through to the default character-insert handler. See #22379.

    Returns the number of sequences whose mapping was changed.
    r   r   r	   )z[13;5uz
[27;5;13~z
[27;5;13ur   r   r   s        r   Úinstall_ctrl_enter_aliasr   6   s¦   € ð"ØMÐMÐMÐMÐMÐMØ,Ð,Ð,Ð,Ð,Ð,Ð,øÝð ð ð Øˆqˆqðøøøð ”˜dœmÐ,€IØ€GØ?ð ð ˆØ×Ò˜cÑ"Ô" iÒ/Ð/Ø"+ˆN˜3ÑØq‰LˆGøØ€Nr   c                 ó  — 	 ddl m}  ddlm} n# t          $ r Y dS w xY w|j        |j        |j        |j        |j        dœ}d}|                     ¦   «         D ](\  }}|                      |¦  «        |k    r
|| |<   |dz  }Œ)|S )u
  Map Cmd+Backspace / Cmd+ForwardDelete to the readline kill bindings
    prompt_toolkit already ships (``unix-line-discard`` / ``kill-line``).

    Terminals that rewrite Cmd+Backspace to Ctrl+U (``\x15``) already work.
    Kitty keyboard protocol and xterm modifyOtherKeys terminals instead
    report Cmd as the *super* modifier bit (8), producing sequences
    prompt_toolkit does not map â€” the raw bytes then fall through to
    literal insertion.

    Cmd+Backspace â†’ ``Keys.ControlU`` (kill backward to start of line).
    Codepoint 127 with modifier 9 (super) / 10 (super+shift):
      - ``\x1b[127;9u`` / ``\x1b[127;10u``  â€” Kitty CSI-u
      - ``\x1b[27;9;127~``                   â€” xterm modifyOtherKeys

    Cmd+ForwardDelete â†’ ``Keys.ControlK`` (kill to end of line). The
    forward-delete key is a CSI *tilde* key, not a CSI-u codepoint, so the
    modifier rides in the standard ``CSI 3 ; mod ~`` form:
      - ``\x1b[3;9~`` / ``\x1b[3;10~``

    Returns the number of sequences whose mapping was changed.
    r   r   r	   )z[127;9uz	[127;10uz[27;9;127~z[3;9~z[3;10~r   )	r   r   r   r
   r   ÚControlUÚControlKÚitemsr   )r   r
   Úaliasesr   r   Úkeys         r   Úinstall_cmd_backspace_aliasr"   V   sË   € ð,ØMÐMÐMÐMÐMÐMØ,Ð,Ð,Ð,Ð,Ð,Ð,øÝð ð ð Øˆqˆqðøøøð ”}ØœØœ-Ø”]Ø”mðð €Gð €GØ—M’M‘O”Oð ð ‰ˆˆSØ×Ò˜cÑ"Ô" cÒ)Ð)Ø"%ˆN˜3ÑØq‰LˆGøØ€Nr   c                 óx   — 	 ddl m}  ddlm} n# t          $ r Y dS w xY wd}dD ]}|| vr|j        | |<   |dz  }Œ|S )uò  Map terminal-emitted noise sequences to ``Keys.Ignore`` so they
    are consumed by the VT100 parser before they reach key bindings or
    the input buffer.

    Currently covers focus reports:
      - ``\x1b[I`` â€” terminal regained focus (focus in)
      - ``\x1b[O`` â€” terminal lost focus (focus out)

    Ghostty, iTerm2, and some xterm builds can emit these sequences when
    the user switches tabs / windows or when a multiplexer toggles focus
    tracking upstream. prompt_toolkit does not map these by default, so
    its parser falls back to literal key presses (ESC, ``[``, ``I``/``O``)
    and inserts ``[I``/``[O`` into the prompt buffer after the ESC byte
    is handled.

    Registering them as ``Keys.Ignore`` is parser-level â€” strictly
    cleaner than post-hoc regex stripping in the input sanitizer because
    the bytes never reach the buffer. ``setdefault`` is used so any user
    or downstream registration wins.

    Returns the number of sequences whose mapping was changed.
    r   r   r	   )z[Iz[Or   )r   r   r   r
   r   ÚIgnore)r   r
   r   r   s       r   Ú"install_ignored_terminal_sequencesr%      sŒ   € ð.ØMÐMÐMÐMÐMÐMØ,Ð,Ð,Ð,Ð,Ð,Ð,øÝð ð ð Øˆqˆqðøøøð €GØ#ð ð ˆØnÐ$Ð$Ø"&¤+ˆN˜3ÑØq‰LˆGøØ€Nr   N)r   r   )Ú__doc__Ú
__future__r   r   r   r"   r%   © ó    r   ú<module>r*      s€   ðð	ð 	ð #Ð "Ð "Ð "Ð "Ð "ð$ð $ð $ð $ðNð ð ð ð@(ð (ð (ð (ðV"ð "ð "ð "ð "ð "r)   