Skip to content

feat(terminal): add DECRQM (CSI ? Ps $ p) — report DEC private mode state#65

Draft
roramirez wants to merge 1 commit into
mainfrom
feat/decrqm-mode-query
Draft

feat(terminal): add DECRQM (CSI ? Ps $ p) — report DEC private mode state#65
roramirez wants to merge 1 commit into
mainfrom
feat/decrqm-mode-query

Conversation

@roramirez

Copy link
Copy Markdown
Owner

Summary

Implements DECRQM (CSI ? Ps $ p), the Request Mode query for DEC private modes. mmterm now replies CSI ? Ps ; Pm $ y where Pm is 1 (set), 2 (reset), or 0 (mode not recognized). Applications such as neovim use DECRQM to probe terminal capabilities before enabling a mode, avoiding redundant or unsupported mode switches.

Changes

  • src/terminal/parser.rs:
    • Route every ?-prefixed CSI through handle_dec_private_modes (vte reports the $ intermediate alongside the ?, so DECRQM does not collide with plain set/reset).
    • Handle action == 'p' as DECRQM: reply from a new decrqm_state helper that maps a mode number to 0/1/2 over the state mmterm already tracks (?1, ?7, ?25, ?1000/1002/1003, ?1004, ?1006, ?1049, ?2004).
    • Collapse the DECSET/DECRST (h/l) arms into ('h' | 'l', …) patterns using a single on = action == 'h' flag — same behavior, fewer lines.
  • src/terminal/parser_test.rs: a test covering set, reset, reset-after-disable, unknown-mode, and that a query does not toggle the mode.
  • CHANGELOG.md: entry under [Unreleased] / Added.

How to test

  • cargo test (see decrqm_reports_mode_state in parser_test.rs; the full suite still passes with the refactored setter).
  • In a running mmterm session: printf '\033[?2004$p' replies \033[?2004;1$y when bracketed paste is enabled.

Checks

  • cargo fmt
  • cargo clippy --locked -- -D warnings
  • cargo test (1204 passed)
  • km score --trend origin/main --fail-if-worse (PASS, B+)
  • CHANGELOG.md updated

Report whether a DEC private mode is set (1), reset (2), or not
recognized (0) in reply to a DECRQM query, covering the modes mmterm
already tracks (cursor keys, autowrap, cursor visibility, mouse, focus
reporting, alt screen, bracketed paste). neovim and others use this to
probe capabilities before enabling a mode.

Route all `?`-prefixed sequences through one handler and collapse the
DECSET/DECRST arms into `h | l` patterns while here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant