Architecture
This document outlines how tmux-thumbs interacts with Tmux and the OS to provide a seamless overlay experience. This is useful for contributors or those debugging complex issues.
The Swapper Logic
The core interaction mechanism is located in src/swapper.rs. Unlike simple CLI tools, tmux-thumbs must draw over existing content without destroying it.
The Lifecycle of a Pick
-
Capture: When you trigger the plugin, it runs
tmux capture-pane. This grabs the text content of the active pane, respecting current scroll position and zoom state. -
Generation: The captured text is piped into the
thumbsRust binary. The binary:- Parses the text against regex patterns (
src/state.rs). - Assigns hints based on the selected alphabet (
src/alphabets.rs). - Generates a formatted view with ANSI colors.
- Parses the text against regex patterns (
-
The "Swap": Instead of drawing directly to the active pane (which might mess up running applications),
tmux-thumbs:- Creates a new background window/pane.
- Runs the
thumbsbinary in that new pane to display the hints. - Swaps the active pane with this new "thumbs pane".
- To the user, it looks like an overlay appeared instantly.
-
Selection: The user interacts with the
thumbsbinary running in the swapped pane. When a selection is made:- The selected text is written to a temporary file (
/tmp/thumbs-last). - The binary signals completion.
- The selected text is written to a temporary file (
-
Cleanup & Execution: The swapper detects the signal:
- Swaps the original pane back into focus.
- Destroys the temporary "thumbs pane".
- Reads the selection from the temporary file.
- Executes the user-defined command (e.g.,
tmux set-buffer) using the selected text.
OSC52 Support
If enabled, tmux-thumbs attempts to copy directly to the system clipboard using OSC52 escape sequences.
- Implementation:
src/swapper.rsencodes the selection in Base64 and wraps it in the\x1b]52;...sequence. - Tmux Passthrough: It wraps this further in
\x1bPtmux;...\x1b\\to ensure Tmux passes it to the host terminal.