Right, you're correct, the copy-buffer will never get control characters by copying using copy mode except newlines and multibyte unicode.
Can you (or someone) please explain those params in the tmux Ms terminfo entry? What's %p1%s? The %p2%s appears to be the base64 encoded paste buffer. Maybe one could add a %p3%s which is the raw, not base64 that could be used for this purpose? To be honest, this method would be cleaner and simpler than my script below.
When I couldn't get this working earlier, I thought tmux was filtering the escape codes but the problem wasn't passthrough, it was that I wasn't sending the output to the correct tty.
Here is the current wcl script:
# start send to ansi printer
echo -ne '\e[5i' >$SSH_TTY
# send stdin to the outer terminal
cat >$SSH_TTY
# end ansi printer output
echo -ne '\e[4i' >$SSH_TTY
and in my .tmux.conf I have this line:
bind -Tcopy-mode MouseDragEnd1Pane send -X copy-pipe-and-cancel '~/bin/wcl'
and now, when I select text in a tmux window with a shell, it magically is available in my Windows clipboard.
If I middle click in tmux, it's pasted back into the shell. Ahh, so nice! Used it already multiple times to write this post!
This works but I do have a problem with unicode characters that are encoded as multiple bytes. When there's a unicode code-point that would encode to multiple characters in utf-8 on the sceen in tmux that I copy into the copy-buffer, then paste it into Windows, I get the multi bytes instead of the single character. For example, if i have '€100' in tmux, select it to copy it, then paste it back into windows, i get '€100'.
I don't know where the problem lies here. The editor window (notepad++) on windows certainly supports unicode. The linux side certainly does too. Something along the way is re-encoding each of the characters in the multi-byte sequence as a single unicode codepoint and then sending a multi-byte character for each of those characters. It could be a manifestation of this printer to clipboard hack and if we can get the terminfo param to do raw output, maybe that would fix this? This might be a KiTTY issue. I am not sure and unsure how to debug this at the moment.
By the way, there are some typos on the github documentation page on passthrough which I will try to find the time to do a PR. In the end, I didn't need to use passthrough though I did get it working and it does not help the unicode problem.
So the first thing I tried was to copy something from the shell and then edit a file in the same tmux window with vi and paste it into the file. When I run an editor such as vi or emacs, tmux seems to switch to an alternate terminal screen within the terminal. By this, I mean, when I exit vi, instead of seeing the bottom part of the vi session still on my screen, the screen is returned to the way it was before entering the editor. The ansi term for this may be 'anternate screen'. Terminfo seems to calls this 'smcup'. There seems to be a separate paste buffer associated with the middle click when I'm in the alternete screen. Or maybe the editor is controlling this button? I'm not wholey sure. Whatever it is, I can't find a way to paste the tmux clipboard into the editor. This is reproducible without any of the copy-mode settings above and has nothing to do with Windows, and I don't think it has anything to do with KiTTY either, KiTTY seems to be sending middle click to tmux regardless of whether I'm in vi or at the shell prompt.
Is there some way to paste from the copy-buffer into an editor such as vi or emacs, both in the same tmux? (Windows not involved here).