Terminal emulators often have an option to avoid sending mouse events to
the terminal app (usually you just have to hold the shift key). Some of
them also have an option to change the default to not sending mouse events
to the terminal app.  However, this is still a bad experience for most
users as the scrollback window in the terminal emulator is not trustworthy
when running tmux (or vi or any other terminal app that uses the alternate
screen functionality of terminals) and if you use splits, the terminal
emulator has no idea where the splits are and will not behave the way one
would desire.

As for why this is complicated, terminals used to be printers attached to a
serial port (teletypewriters). Then we got "glass teletypes" which used a
CRT instead of a printer. Then came DEC's Video Terminals in the '70s with
standards like VT-05, VT-50, VT-100, etc. which allowed command
line programs to do amazing things like change a character at a specific x
and y coordinate instead of only being able to add lines at the bottom of
the screen.  All terminal emulators today are just software versions of
those physical terminals.  Because they are software, they can do things
that originals could not, like allow selecting of text without the program
running in the terminal's help (which is how selecting text and hitting
cmd-C works).  Because the terminal emulator is doing that, the application
running in the terminal is completely ignorant of the actions you are
taking.  Some terminal protocols do allow passing of mouse events to
applications that have asked for them.  Tmux can ask for this with
"set-option -g mouse on", at that point the mouse event is no longer
processed by the terminal emulator, but passed to tmux.  Tmux as a terminal
app can only be sure it can talk to the terminal emulator currently
controlling the pty (which is short for pseudotty where tty is
teletypewriter) it is attached to, so it can't tell the OS to add the text
to the clipboard (because it could be running under ssh for instance).  X
Windows and macOS however provide command line programs that can talk to
the clipboard.  So the right answer is for the user (who knows how the
system is set up) to configure tmux to "do the right thing" for the user in
that situation.  There was an attempt to fix this nightmare by adding
escape sequences (how an application talks to the terminal emulator) to
tell it to update the clipboard (see OSC 52), however, support for those
escape sequences is not 100% (for instance Terminal.app in macOS does not
support them). Even terminals that do support them don't always do it the
same way:
https://sw.kovidgoyal.net/kitty/protocol-extensions.html#pasting-to-clipboard.
There are also security concerns as an user with root access on a box you
ssh into could read/set your local operating system's clipboard contents.

tl;dr terminal emulators are a series of hacks for backwards compatibility
dating back to the dawn of digital computers and it is amazing any of this
works at all.


On Wed, Jan 27, 2021 at 6:20 PM Peng Yu <pengyu...@gmail.com> wrote:

> On 1/27/21, Sean Hammond <tmux-us...@snhmnd.fastmail.com> wrote:
> > On Tue, 26 Jan 2021, at 4:51 PM, Peng Yu wrote:
> >> I want to have an identical configure file so that it can allow use
> >> highlight text and type command-C (Mac) or ctrl-shift-C (Linux) for
> >> copying. Basically, I just want the normal behavior of a terminal. Could
> >> anybody let me know the tmux code to figure this?
> >
> > You might find this guide useful:
>
> I don't quite understand this. It seems that tmux makes it more
> complicated than necessary by disable the default behavior of Mac
> Terminal or Linux terminal Is it so? Why not just let them behave as
> what they would do without tmux in the aspect of copying?
>
> I don't think it is a good idea to make it so difficult to just get
> back the default behavior of terminals. Any simpler solutions
> available?
>
> > https://www.seanh.cc/2020/12/27/copy-and-paste-in-tmux/
> >
> > It uses the tmux-yank plugin to achieve the cross-platform behaviour.
> >
> > Also see my tmux config:
> >
> > https://github.com/seanh/tmux
> >
> > This doesn't bind command-c on mac. But this is the line that binds
> > control-c on linux, you could add a similar line for mac but using
> command-c
> > and pbcopy:
> >
> > bind -T copy-mode-vi C-c send -X copy-pipe-no-clear "xsel -i --clipboard"
>
>
> --
> Regards,
> Peng
>
> --
> You received this message because you are subscribed to the Google Groups
> "tmux-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to tmux-users+unsubscr...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/tmux-users/CABrM6wnKnk4z0KdB05g935BsRCDDfdeN%3D36TYjMgfe%2BmUUAPxA%40mail.gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tmux-users+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/tmux-users/CAH2YjjEm9tQpkOEPmBDGVFv1u3PsFXAzy9DqnLbt47juADRtPw%40mail.gmail.com.

Reply via email to