fix(tui): forward copied selections through tmux - #161
Conversation
| /// exits. On macOS the native pasteboard leads because it does not depend on OSC 52 | ||
| /// support. Each platform falls back to the other channel. | ||
| #[cfg(not(target_os = "macos"))] | ||
| /// Tmux paste buffers are loaded explicitly and forwarded to the outer terminal |
There was a problem hiding this comment.
Might be worth narrowing this wording a bit. This handles the tmux server directly containing Tact, but it won’t necessarily handle outer/nested tmux sessions or a local tmux around SSH. Also, load-buffer -w only forwards to the terminal when possible.
| fn copy_selection(terminal: &mut TerminalSession, text: &str) -> std::result::Result<(), String> { | ||
| let tmux_copy = std::env::var_os("TMUX") | ||
| .map(|_| clipboard::copy_to_tmux(text).map_err(|error| error.to_string())); | ||
| let platform_copy = copy_platform_selection(terminal, text); |
There was a problem hiding this comment.
I think this runs the platform copy even when the tmux copy succeeds, so it isn’t really acting as a fallback. On Linux with set-clipboard on, we could end up writing twice and creating two identical tmux buffers. Could we make this lazy and stop after the first successful copy? We could probably also leave the existing macOS path alone since pbcopy already handles this there.
There was a problem hiding this comment.
Good catch. We can certainly make this lazy. Will fix.
There was a problem hiding this comment.
Fixed in a871f1d.
I left local macos on the existing pbcopy path. Remote macos still uses tmux first because pbcopy only updates the remote clipboard.
| } | ||
|
|
||
| #[test] | ||
| fn successful_tmux_copy_ignores_platform_failure() { |
There was a problem hiding this comment.
I don’t think these tests catch the issue above since both results have already been computed by the time they reach copy_result. Could we test with closures or fake backends and check that the fallback isn’t called after a successful copy?
|
Thanks! Hope you've been well 🫂 |
Merging this PR will not alter performance
Comparing Footnotes
|
Indeed, I am and I hope you are too. I've been enjoying tact quite a lot. Thanks for making it. |
Summary
Copying text from tact inside tmux did not reliably reach the terminal on the machine hosting the tmux client. Depending on tmux's clipboard config, OSC 52 could also be ignored without creating a tmux paste buffer.
When
$TMUXis present, tact now pipes the selection throughtmux load-buffer -w -. This stores the text in tmux's paste buffer and forwards it to the outer terminal clipboard. The existing platform clipboard path remains available, and behavior outside tmux is unchanged.