
    PL
j                    &    d Z ddlm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/kuhnn/.hermes/hermes-agent/hermes_cli/pt_input_extras.pyinstall_shift_enter_aliasr      s    0MMMMMM,,,,,,,   qq dm,IG?  c""i//"+N3qLG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,,,,,,,   qq dm,IG?  c""i//"+N3qLGNr   N)r   r   )__doc__
__future__r   r   r        r   <module>r       sV   	 	 # " " " " "$ $ $ $N     r   