Skip to content

Support OSC 4/10–12 queries, XTMODKEYS, ?1007, and pixel ?1016/?2048 #26

Done

Description

@tony

Summary

Real-world TUI startup sequences (nvim, fzf, yazi, crossterm, termenv / lipgloss) probe OSC 4 ; idx ; ?, chained OSC 10 ; ? ; ? (10/11/12) plus OSC 104/110/111/112 resets, XTMODKEYS (CSI > 4 ; pv m and CSI ? 4 m), ?1007 alternate-screen wheel-to-arrow scroll, pixel-calibrated ?1016 / ?2048 / TIOCSWINSZ dimensions, and XTSMGRAPHICS (CSI ? Pi ; Pa ; Pv S) fenced by DA1/DSR sentinels, while desktop notification sequences (OSC 9, OSC 99, OSC 777) currently emit UnhandledSequence noise (#2).

Motivation

  • Terminal._handle_osc() currently handles OSC 10 ; ? and OSC 11 ; ? only when data == b"?" (missing chained OSC 10;?;? emitted by xterm / termenv probes, OSC 12 cursor color set/query + OSC 112 reset, and OSC 4 / OSC 104 256-palette set/query/reset).
  • When nvim declines or probes CSI ? u Kitty keyboard mode, it sends CSI > 4 ; 2 m (modifyOtherKeys level 2) and may query CSI ? 4 m; tracking modify_other_keys (0, 1, 2) per screen and encoding modified keys in KeyEvent keeps nvim key chords working out of the box.
  • On the alternate screen with mouse tracking disabled and ?1007 (ALTERNATE_SCROLL) enabled (default in modern terminals and less/man pagers), mouse wheel events translate into Up/Down cursor keys (DECCKM-aware).
  • ?1016 MouseEvent encoding currently emits raw pixel_x/pixel_y even when negative or unset (0 instead of deriving cell-center/clamped non-negative coordinates from cell_width_px / cell_height_px), and Terminal.resize() / PtySession.resize() hard-code 0;0 pixel sizes in CSI 48 ; rows ; cols ; px_h ; px_w t (?2048) and TIOCSWINSZ.
  • Answering XTSMGRAPHICS (CSI ? Pi ; Pa ; Pv S) with non-blocking error status CSI ? Pi ; 3 S prevents SIXEL-probing applications from stalling on a sentinel timeout, while silently accepting OSC 9 (text notification), OSC 99 (Kitty notification), and OSC 777 (notify;...) prevents false UnhandledSequence errors under Policy.strict=True or event recording.

Proposal

Invariants

The invariants below are load-bearing; everything under Intent is open.

  • All query replies (OSC 4/10/11/12, DECRQM returning 0 for any unrecognized ANSI/DEC mode, XTGETTCAP, XTSMGRAPHICS, XTMODKEYS ?4m, DA1/DA2, DSR) enqueue in exact arrival order and respect Policy.allow_color_queries and Limits.max_reply_bytes.
  • ?1016 SGR-Pixel mouse coordinates are clamped to >= 0 (deriving default pixel coordinates from (col, row) and (cell_width_px, cell_height_px) when explicit pixel coordinates are not supplied, or gating ?1016 when pixel geometry is 0).
  • Terminal documentation states single-threaded ownership explicitly (mutation and inspection belong to one thread/event-loop unless externally synchronized, while immutable Snapshot objects may be shared freely across threads).

Intent (non-binding)

  • Store sparse palette overrides (dict[int, tuple[int, int, int]]) and _cursor_rgb on Terminal (reset by OSC 104, OSC 112, and RIS), support semicolon-chained OSC 10;?;? (10, 11, 12) queries, add Mode.ALTERNATE_SCROLL = DEC_PRIVATE_MASK | 1007, track modify_other_keys: int (0..2) on Screen, report pixel dimensions in ?2048 and PtySession.resize(), reply �[?{pi};3S to CSI ? Pi ; Pa ; Pv S, and consume OSC 9/99/777 without emitting UnhandledSequence.

Not doing

  • Implementing full stateful XTSMGRAPHICS color/geometry register mutation, XTSAVE/XTRESTORE, Kitty REPORT_ALTERNATE_KEYS/REPORT_ASSOCIATED_TEXT, or structured notification Event dataclasses in 0.1.0 (tracked separately for 0.2.0).

References

Activity

  1. added
    enhancement
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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