Skip to content

[FEAT] Support for sending keystrokes to the target #17

@jxyyz

Description

@jxyyz

Problem

I'm using Claude Code with vim mode. So it requires pressing i for starting INSERT mode before providing any text/prompt.

I believe there's no easy way to send keystrokes before or after pasting text to a target within wiremux's API.

This also applies to other TUI apps - anything where you need to prepare the target's state before pasting (enter insert mode, clear a prompt, etc.) or clean up after (press Escape, submit with a specific key sequence).

Suggestion

NOTE: I'm happy to implement these changes. I'll probably tinker with this in my spare moments anyway to achieve this functionality for my own workflow.

Add keys_before and keys_after fields to SendItem:

---@class wiremux.action.SendItem
---@field value string
---@field label? string
---@field submit? boolean
---@field keys_before? string[]   -- keystrokes to send before pasting
---@field keys_after? string[]    -- keystrokes to send after pasting

The tmux batch per target would be:
a)
keys_beforepaste-bufferkeys_afterEnter (if submit).

or b)
keys_beforepaste-bufferEnter (if submit) → keys_after

... not sure which is better.

Of course there are other possible approaches to this problem. I'm open to discuss them.

Usage

-- Send to TUI app in vim mode
wiremux.send({
  value = "explain this code",
  keys_before = { "i" },
  submit = true,
})

-- Or in a send library
wiremux.send({
  { value = "explain {file}", label = "Explain", keys_before = { "i" }, submit = true },
  { value = "review {selection}", label = "Review", keys_before = { "i" }, submit = true },
})

Note: This depends on send_keys being fixed first (see #16 - send_keys hardcoded Enter issue), since the current implementation can't send arbitrary keystrokes.

Future enhancements

Above suggestion is based on existing action.send_keys() in tmux backend implementation.

We can consider these enhancements in the future:

  • exposing some sort of action.send_keystrokes (maybe with a better name) in user facing API, to allow users to programmatically achieve more complicated workflows in TUI targets
  • allowing users to check if something is happening on the screen (e.g., checking if -- INSERT -- indicator is present in the TUI)
    • I think it can be a good use case for the capture() function from watch.lua

But I think it needs some additional planning and good design decisions, since it will increase the overall complexity of the plugin. And maybe it's not the goal of this project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions