Skip to content

Add ?8/?66/?67 input modes, MouseTracker, and AsyncSession #42

Done

Description

@tony

Summary

Wave 3 input and async-driving slice of #34 (runnable in parallel with Wave 3 Appearance, pairing with XTSAVE/XTRESTORE in #29): add DECARM (?8), DECNKM (?66), and DECBKM (?67) input modes while keeping Terminal.encode() stateless, add MouseTracker in src/libvt/input.py, and add bidirectional outbound driving on AsyncTerminalStream behind a narrow AsyncSession Protocol in src/libvt/aio.py.

Motivation

  • Full-screen TUIs toggle DECNKM (?66 application keypad), DECBKM (?67 backarrow sends BS 0x08 vs DEL 0x7f), and DECARM (?8 auto-repeat) alongside XTSAVE/XTRESTORE (Support XTSAVE (CSI ? Pm s) and XTRESTORE (CSI ? Pm r) private mode save/restore #29), and ?1002 button-event mouse tracking suppresses repeated motion reports within the same cell—state that breaks read-only callers if mutated inside Terminal.encode().
  • AsyncTerminalStream currently accepts only a read-side StreamReader (plus optional reply sink), so cross-platform pipe/socket tests on Windows and POSIX cannot drive send_key(), send_event(), or paste() through the same interactive interface as PtySession.

Proposal

  • Add Mode.AUTO_REPEAT (?8), Mode.APPLICATION_KEYPAD (?66, reconciled with DECKPAM ESC = and DECKPNM ESC >), and Mode.BACKARROW_IS_BS (?67) in src/libvt/modes.py, src/libvt/input.py, and src/libvt/terminal.py, keeping Terminal.encode(event) pure (repeat=True dropped when ?8 is reset unless Kitty REPORT_EVENT_TYPES is active).
  • Add a session-scoped MouseTracker helper in src/libvt/input.py that suppresses duplicate same-cell ?1002 drag motion events while passing ?1003 any-event motion and button transitions through unchanged, wired into AsyncTerminalStream.send_event() and PtySession.send_event().
  • Extend AsyncTerminalStream with optional outbound writer support (send, send_event, send_key, paste, drain, write_eof) and export a structural AsyncSession t.Protocol (terminal, send, send_event, send_key, paste, drain, wait_for, aclose) implemented by both AsyncTerminalStream and PtySession, keeping returncode, TIOCSWINSZ resize(), Linux EIO EOF, and process-group termination exclusive to PtySession.
  • Keep outbound queueing single-FIFO with atomic frame writes so auto-replies drained from Terminal never interleave inside a bracketed paste() frame (ESC[200~..ESC[201~), and keep the inbound reader loop running unconditionally without awaiting outbound drain() so full child stdin pipes never deadlock PTY/pipe reads.

Alternatives

  • Storing last_mouse_cell directly on Terminal and mutating it inside Terminal.encode(ev): rejected because logging or asserting term.encode(ev) before session.send_event(ev) would silently swallow the outbound mouse drag event.
  • Adding AsyncTerminalStream.from_blocking() via asyncio.to_thread in 0.1.0: rejected until post-0.1.0 because blocking read() worker threads cannot be cancelled deterministically on aclose().

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions