Skip to content

Form: submit on Ctrl+S (works in every terminal)#98

Merged
meszmate merged 1 commit intomainfrom
fix/universal-form-submit
Apr 26, 2026
Merged

Form: submit on Ctrl+S (works in every terminal)#98
meszmate merged 1 commit intomainfrom
fix/universal-form-submit

Conversation

@meszmate
Copy link
Copy Markdown
Owner

Summary

You reported Ctrl+Enter not submitting the form on macOS. It's not your terminal — it's a fundamental encoding issue. Most terminals (macOS Terminal.app, basic xterm, default VS Code terminal) encode both `Enter` and `Ctrl+Enter` as the same byte (`\r` / 0x0D). Only terminals that opt into the Kitty keyboard protocol can tell them apart. So `Form`'s old `Ctrl+Enter` binding silently did nothing for most users.

Library change

`Form` gains three new fields with sensible defaults:

Field Default Notes
`submit_keys` `{ Ctrl+S, Ctrl+Enter }` Ctrl+S works in every terminal; Ctrl+Enter is a bonus for capable ones
`cancel_keys` `{ Escape }` unchanged behavior
`hint_text` `"Tab: next field | Ctrl+S: submit | Esc: cancel"` shown in the footer; override if you change the bindings

`handleKey` now iterates these lists instead of hard-coding the combo, so users can replace either list with their own `KeyEvent` slice.

Audit of the rest of the codebase

I grepped `src/` and `examples/` for other multi-modifier bindings that would fail in standard terminals. Form was the only offender. Everything else uses keys that work universally:

  • single-modifier (Ctrl+letter, Alt+letter)
  • Tab and Shift+Tab
  • arrow keys
  • function keys
  • plain Enter / Escape / Backspace

Test plan

  • `zig build` passes
  • `zig build test` — full suite passes
  • `zig build run-form` — type into fields, press Ctrl+S → form submits (verified on macOS Terminal.app)

Ctrl+Enter is indistinguishable from plain Enter in most terminals
(macOS Terminal.app, basic xterm, the default VS Code terminal — they
all encode both as 0x0D). Only terminals that opt into the Kitty
keyboard protocol can tell them apart. So Form's Ctrl+Enter submit
binding silently did nothing for most users.

Library change:

  Form gains submit_keys, cancel_keys, and hint_text fields. Defaults:

    submit_keys = { Ctrl+S, Ctrl+Enter }   // Ctrl+S works everywhere
    cancel_keys = { Escape }
    hint_text   = 'Tab: next field | Ctrl+S: submit | Esc: cancel'

  handleKey iterates the binding lists instead of hard-coding one
  combo. Users can replace either list with their own KeyEvent slice.

Audit of the rest of src/ and examples/ found no other multi-modifier
bindings that fail in standard terminals — Form was the only offender.
Single-modifier (Ctrl+letter, Alt+letter), Tab, Shift+Tab, arrow keys,
and the function keys all work universally.

Verified: `zig build run-form`, type into fields, press Ctrl+S — form
submits. Tests pass.
@meszmate meszmate merged commit d9369c4 into main Apr 26, 2026
9 checks passed
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