mobile-shell / mobile-shell/mosh

mosh does not transmit OSC 52 sequence to client

Open
#637 14 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
14.5k
Forks
865
PR merge metrics
No merged PRs in 30d

Description

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?
+    }
   }
 }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/terminal/terminalfunctions.cc at Dispatcher::OSC_dispatch and trace how OSC sequences are parsed and how terminal output is written. Reproduce the issue with an OSC 52 clipboard sequence; done means the sequence reaches the client terminal without breaking existing OSC handling, with a regression check if an existing test path is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.