Skip to content

feat: pre_keys/post_keys support for keystroke injection#20

Merged
MSmaili merged 5 commits intoMSmaili:mainfrom
jxyyz:feat/keys-support
Apr 1, 2026
Merged

feat: pre_keys/post_keys support for keystroke injection#20
MSmaili merged 5 commits intoMSmaili:mainfrom
jxyyz:feat/keys-support

Conversation

@jxyyz
Copy link
Copy Markdown
Contributor

@jxyyz jxyyz commented Mar 2, 2026

Closes #17

What

Adds pre_keys and post_keys fields to SendItem and action-level config. This allows sending keystrokes before/after pasting text to tmux targets - useful for TUI apps that need state preparation (e.g. i for vim insert mode, C-c to cancel current input).

Usage example

wiremux.send({
  value = "explain this code",
  pre_keys = "i",
  submit = true,
})

-- action-level defaults
wiremux.send("hello", {
  pre_keys = { "C-c" },
  post_keys = { "Escape" },
})

Status

This is a first working prototype - pushed so it's available for testing and review. I'll be validating this further on my side.

Open to feedback and suggestions on the approach.

jxyyz added 2 commits March 2, 2026 04:14
Allow sending keystrokes before and after pasting text to tmux targets.
Useful for TUI apps that need e.g. C-c to cancel input or i/Escape for vim-mode editors.

- Add pre_keys/post_keys to SendItem and ActionConfig (string|string[])
- Wire through do_send() → backend.send() with correct batch ordering
- Item-level keys override opts-level as fallback
- Add tests and documentation
Collapse 6 positional parameters into a single send_opts table for
readability. Build backend_opts via tbl_extend to add focus.

- do_send(expanded, opts, send_opts) instead of 6 args
- Callers build { submit, title, pre_keys, post_keys } at call site
- No behavioral change
@jxyyz
Copy link
Copy Markdown
Contributor Author

jxyyz commented Mar 2, 2026

There is probably the same problem that was resolved in #15.

It appears when I try to replace submit = true option with post_keys = "Enter"

I'll check this later and adjust my implementation to the solution provided in that issue.

jxyyz and others added 3 commits March 2, 2026 06:16
post_keys suffered the same race condition as submit (issue MSmaili#15) — keystrokes
arrived in the same tmux batch as paste, before the TUI processed the text.

- Move post_keys from main batch to deferred execution (300ms delay)
- Unify submit and post_keys into _send_deferred() for single-point change
- Deferred order per target: post_keys -> Enter (if submit)
- Update tests to verify post_keys arrives in deferred batch, not main
@MSmaili MSmaili merged commit 77d97f5 into MSmaili:main Apr 1, 2026
1 check 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.

[FEAT] Support for sending keystrokes to the target

2 participants