Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mosh does not transmit OSC 52 sequence to client #637

Open
sunaku opened this issue Jun 17, 2015 · 13 comments · May be fixed by #1104
Open

mosh does not transmit OSC 52 sequence to client #637

sunaku opened this issue Jun 17, 2015 · 13 comments · May be fixed by #1104

Comments

@sunaku
Copy link

sunaku commented Jun 17, 2015

Similar to #549 and #552, this limitation prevents me from copying text from remote shell sessions into my local terminal via the OSC 52 escape sequence. It's also the reason I still use SSH instead of Mosh. 😱

I tried to patch this but got stuck. 😢 Any hints on how to write a string to the raw terminal device?

diff --git a/src/terminal/terminalfunctions.cc b/src/terminal/terminalfunctions.cc
index 35c8055..1983aec 100644
--- a/src/terminal/terminalfunctions.cc
+++ b/src/terminal/terminalfunctions.cc
@@ -558,6 +558,46 @@ void Dispatcher::OSC_dispatch( const Parser::OSC_End *act, Framebuffer *fb )
        * 2: set window title */
       cmd_num = OSC_string[ 0 ] - L'0';
       offset = 2;
+    } else if ( (OSC_string.size() >= 3) && (OSC_string[ 2 ] == L';') ) {
+      /* OSC of the form "\033]XX;<Pt>\007" where XX can be:
+       * 10: Change VT100 text foreground color to Pt.
+       * 11: Change VT100 text background color to Pt.
+       * 12: Change text cursor color to Pt.
+       * 13: Change mouse foreground color to Pt.
+       * 14: Change mouse background color to Pt.
+       * 15: Change Tektronix foreground color to Pt.
+       * 16: Change Tektronix background color to Pt.
+       * 17: Change highlight background color to Pt.
+       * 18: Change Tektronix cursor color to Pt.
+       * 19: Change highlight foreground color to Pt.
+       * 46: Change Log File to Pt.  (This is normally disabled by a compile-time option).
+       * 50: Set Font to Pt.
+       * 51: reserved for Emacs shell.
+       * 52: Manipulate Selection Data.
+       */
+      cmd_num = 10 * (OSC_string[ 0 ] - L'0') +
+                     (OSC_string[ 1 ] - L'0');
+      offset = 3;
+    } else if ( (OSC_string.size() >= 4) && (OSC_string[ 3 ] == L';') ) {
+      /* OSC of the form "\033]XXX;<Pt>\007" where XXX can be:
+       * 104: Reset Color Number c.
+       * 105: Reset Special Color Number c.
+       * 106: Enable/disable Special Color Number c.
+       * 110: Reset VT100 text foreground color.
+       * 111: Reset VT100 text background color.
+       * 112: Reset text cursor color.
+       * 113: Reset mouse foreground color.
+       * 114: Reset mouse background color.
+       * 115: Reset Tektronix foreground color.
+       * 116: Reset Tektronix background color.
+       * 117: Reset highlight color.
+       * 118: Reset Tektronix cursor color.
+       * 119: Reset highlight foreground color.
+       */
+      cmd_num = 100 * (OSC_string[ 0 ] - L'0') +
+                 10 * (OSC_string[ 1 ] - L'0') +
+                      (OSC_string[ 2 ] - L'0');
+      offset = 4;
     }
     bool set_icon = (cmd_num == 0 || cmd_num == 1);
     bool set_title = (cmd_num == 0 || cmd_num == 2);
@@ -569,6 +609,9 @@ void Dispatcher::OSC_dispatch( const Parser::OSC_End *act, Framebuffer *fb )

       act->handled = true;
     }
+    else {
+      // HELP ME: how can I write the OSC_string as-is to the terminal device?
+    }
   }
 }
@vdrandom
Copy link

(I'm not really sure if it's the right place, but another issue is a couple of years old with no news: #352, and this seems related.)
Maybe support cursor shape change escapes as well:

\033[X \007
or
\e[X q

where X indicates the shape of the text cursor
EDIT: I personally have no experience with C++, so I probably cannot help with that.
Also tmux somehow manages to change the shape and color of the cursor even during mosh session in command mode (^B, :).

@acornejo
Copy link
Contributor

This also causes problems with the mosh chrome extension, since the only way to access the clipboard from within a chrome terminal is through these escape sequences (xclip, pbcopy, etc.. don't really work inside chrome)

@agriffis
Copy link

agriffis commented Feb 4, 2018

Was this fixed by #899?

@andersk
Copy link
Member

andersk commented Feb 4, 2018

@agriffis That’s the theory. It’s not in a released version yet; you’ll need both a server and a client from Git.

I haven’t tested it myself, but looking at the implementation, I’m worried it’s probably buggy, so I’m going to leave this open for now.

  1. It only handles the specific sequence OSC 5 2 ; c ; base-64-data (BEL|ST), so it does not handle clipboard types other than the system clipboard (see the specification).
  2. It does not pass on the sequence if it’s the same as the last such sequence passed on, so you can’t copy the same string twice in a row (even if there was an intervening copy in another application), or paste twice in a row.

@agriffis
Copy link

agriffis commented Feb 4, 2018

you’ll need both a server and a client from Git

As it happens, I have that ;-)

https://copr.fedorainfracloud.org/coprs/agriffis/mosh-nightly/

does not handle clipboard types other than the system clipboard

Hard to tell if that matters. primary, select, cut buffers are all relics of X11. Although I don't know why mosh wouldn't just pass that parameter through.

can’t copy the same string twice in a row

Ugh, yes, I see that. (just tested)

@andersk
Copy link
Member

andersk commented Feb 4, 2018

Hard to tell if that matters. primary, select, cut buffers are all relics of X11. Although I don't know why mosh wouldn't just pass that parameter through.

Well, some of us still use X11, but more to the point, the clipboard type is specified as a set of zero or more characters from cps01234567, so it could have c and also something else.

can’t copy the same string twice in a row

Ugh, yes, I see that. (just tested)

Thanks for the testing.

@gwicke
Copy link

gwicke commented Jul 17, 2019

#1054 has more liberal OSC 52 option parsing, which makes clipboard updates work with tmux among others. The custom options are not preserved across the connection at this point, but at least it does update the clipboard, without a need for tweaking tmux & co to conform to mosh.

@dohsimpson
Copy link

#899 fixed it for me. My set up using iTerm2 + mosh + tmux. iTerm2 needs "Allow clipboard access to terminal apps" enabled.

You need to build both the client and the server. And restart your mosh session.

e.g. my mosh version: mosh 1.3.2 [build b1da700]

FYI, use this command to test clipboard works. This should put "blabla" in your Mac's clipboard.

printf "\033]52;c;$(printf "%s" "blabla" | base64)\a" (credit)

@mpercy
Copy link

mpercy commented Oct 8, 2019

@dohsimpson I am running mosh 1.3.2 (macOS client, Linux server) and the above printf does not copy to my client's system clipboard when using mosh (it works over plain ssh).

Edit: I just realized that mosh 1.3.2 was released in 2017 and you have commented here in 2019, so I suppose you just cherry-picked #899 on top of 1.3.2 and rolled your own build. Your comment referring to version 1.3.2 as working was confusing to me, since the 1.3.2 release does not have this feature.

mgulick added a commit to mgulick/mosh that referenced this issue Jul 23, 2020
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
@mgulick mgulick linked a pull request Jul 23, 2020 that will close this issue
mgulick added a commit to mgulick/mosh that referenced this issue Jul 23, 2020
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
@ScottRochford
Copy link

It would be really good if this fix made it into the mainstream release, which seems long overdue - is something blocking it?

@NightMachinery
Copy link

NightMachinery commented Oct 29, 2020

This makes mosh not work with kitty's clipboard as well: kovidgoyal/kitty#1558

@greened
Copy link

greened commented Nov 24, 2020

I need something very similar to the patch posted in the first comment of this issue, for emacs directory tracking (OSC 51). I think I just need to pass the OSC to the terminal but like @sunaku I'm not sure how to do that.

See #1122.

Mic92 pushed a commit to Mic92/mosh that referenced this issue Aug 13, 2021
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
jlangston pushed a commit to jlangston/mosh that referenced this issue Dec 28, 2021
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
kam1kaze pushed a commit to kam1kaze/mosh-static that referenced this issue Jan 25, 2022
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
Mic92 pushed a commit to Mic92/mosh that referenced this issue Jan 30, 2022
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
nikkon-dev pushed a commit to nikkon-dev/mosh that referenced this issue Feb 10, 2022
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
@rcorre
Copy link

rcorre commented Feb 25, 2022

#899 did not fix it for me. With a Mac client (using kitty terminal) and Linux server both running mosh-1.3.2-105-gdbe419d (built from source), OSC yank works over a raw ssh session but not mosh.

I tried #1054 and that fixed it for me.

denizevrenci pushed a commit to denizevrenci/mosh that referenced this issue Oct 2, 2022
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
mgulick added a commit to mgulick/mosh that referenced this issue Jan 6, 2024
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
MaxGyver83 pushed a commit to MaxGyver83/mosh that referenced this issue Jun 5, 2024
The OSC 52 escape sequence supports specifying which X selection
buffer place to the selection into.  The protocol format is:

  \033]52;C;D\007

The C parameter determines the selection buffer.  It consists of zero
or more of the following characters:

 c: CLIPBOARD
 p: PRIMARY
 q: SECONDARY
 s: XTerm-selected (based on XTerm.vt100.selectToClipboard)
 0-7: Numbered cut buffer

The default if left blank is 's0', representing the configurable
primary/clipboard selection and cut buffer 0. [1]

D is the base64 encoded text to place in the selection buffer.

This patch modifies the transferred clipboard data to include both the
selection parameter and the base64 text.  I.e. previously the
transferred clipboard data only contained 'D', and now it contains
'C;D'.

To test this functionality:

  1. Open XTerm
  2. Ctrl-Right Click and select 'Allow Window Ops'
  3. Connect to a server w/ mosh
  4. Run the following in the remote connection:
     $ printf "\033]52;c;$(echo test1234 | base64)\007"
     $ printf "\033]52;p;$(echo test2345 | base64)\007"
     $ printf "\033]52;q;$(echo test3456 | base64)\007"
  6. Open another terminal on the local machine and run:
     $ xclip -o -selection clipboard
     test1234
     $ xclip -o -selection primary
     test2345
     $ xclip -o -selection secondary
     test3456
  7. You can also try:
     $ printf "\033]52;;$(echo testdefault | base64)\007"
     (This should update either the clipboard or primary selection
     based on the Xterm settings)
  8. To test the cut buffers you can use the same
     procedure, substituting the cut buffer number in C, and then use
     'xcutsel' to transfer the data from the cut buffer to the PRIMARY
     selection, where it can then be viewed with 'xclip'.

Note, I observed that XTerm does not currently (as of XTerm patch 358)
support specifying more than one value in C.  The specification does
support it, and this appears to just be a simple bug in XTerm (a patch
has been submitted to the maintainer to fix it).

[1] https://github.com/ThomasDickey/xterm-snapshots/blob/master/ctlseqs.txt

Fixes mobile-shell#967.

Part 2
======

Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
msva pushed a commit to alphallc/mosh that referenced this issue Jun 16, 2024
Instead of using the contents of the clipboard to determine if the
user has copied any text, use a sequence number that is updated
whenever text is copied.  Consider the following scenario (as
described in mobile-shell#1090):

1. User copies text 'abc' on remote machine via mosh.
2. User copies text 'xyz' on local machine.
3. User copies text 'abc' on remote machine again.

The local clipboard will still has 'xyz' because the most recent copy
text 'abc' matches the last text copied via mosh, so it does not
detect that the user copied new text and does not update the local
clipboard.

This patch updates detection of newly copied text via a sequence
number.  This number is an 8-bit unsigned integer that is updated
every time new text is copied.  This will roll over after 256
clipboard updates, but that is fine as we only care about it being
different than the last value.

Fixes mobile-shell#1090.
Fixes mobile-shell#637.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet