Skip to content

fix(tui): forward copied selections through tmux - #161

Merged
clabby merged 2 commits into
clabby:mainfrom
Inphi:inphi/tmux-copy
Aug 18, 2026
Merged

fix(tui): forward copied selections through tmux#161
clabby merged 2 commits into
clabby:mainfrom
Inphi:inphi/tmux-copy

Conversation

@Inphi

@Inphi Inphi commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

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 $TMUX is present, tact now pipes the selection through tmux 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.

Comment thread bin/tact/src/tui/mod.rs Outdated
/// 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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bin/tact/src/tui/mod.rs Outdated
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);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. We can certainly make this lazy. Will fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bin/tact/src/tui/mod.rs Outdated
}

#[test]
fn successful_tmux_copy_ignores_platform_failure() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Fixed in a871f1d.

@clabby

clabby commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Thanks! Hope you've been well 🫂

@codspeed-hq

codspeed-hq Bot commented Aug 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 18 untouched benchmarks
⏩ 31 skipped benchmarks1


Comparing Inphi:inphi/tmux-copy (a871f1d) with main (9ca1564)2

Open in CodSpeed

Footnotes

  1. 31 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (2cd2016) during the generation of this report, so 9ca1564 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Inphi

Inphi commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! Hope you've been well 🫂

Indeed, I am and I hope you are too. I've been enjoying tact quite a lot. Thanks for making it.

@clabby
clabby merged commit 828b81e into clabby:main Aug 18, 2026
5 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.

2 participants