Skip to content

Support OSC 52 clipboard updates from tmux & others #1054

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/terminal/terminalfunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void CSI_EL( Framebuffer *fb, Dispatcher *dispatch )
{
switch ( dispatch->getparam( 0, 0 ) ) {
case 0: /* default: active position to end of line, inclusive */
clearline( fb, -1, fb->ds.get_cursor_col(), fb->ds.get_width() - 1 );
clearline( fb, -1, fb->ds.get_cursor_col(), fb->ds.get_width() - 1 );
break;
case 1: /* start of screen to active position, inclusive */
clearline( fb, -1, 0, fb->ds.get_cursor_col() );
Expand Down Expand Up @@ -257,7 +257,7 @@ static void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch )
int param = dispatch->getparam( 0, 0 );
switch ( param ) {
case 0: /* clear this tab stop */
fb->ds.clear_tab( fb->ds.get_cursor_col() );
fb->ds.clear_tab( fb->ds.get_cursor_col() );
break;
case 3: /* clear all tab stops */
fb->ds.clear_default_tabs();
Expand Down Expand Up @@ -591,12 +591,22 @@ static Function func_CSI_DECSTR( CSI, "!p", CSI_DECSTR );
/* xterm uses an Operating System Command to set the window title */
void Dispatcher::OSC_dispatch( const Parser::OSC_End *act __attribute((unused)), Framebuffer *fb )
{
/* handle osc copy clipboard sequence 52;c; */
/*
* Handle OSC copy clipboard sequence 52;c; and variants. Note: While we
* accept other options (including those emitted by tmux), mosh currently
* does not preserve those options across the connection.
**/
if ( OSC_string.size() >= 5 && OSC_string[ 0 ] == L'5' &&
OSC_string[ 1 ] == L'2' && OSC_string[ 2 ] == L';' &&
OSC_string[ 3 ] == L'c' && OSC_string[ 4 ] == L';') {
OSC_string[ 1 ] == L'2' && OSC_string[ 2 ] == L';') {
// Consider at most the first 64 bytes for options.
size_t i = std::min<size_t>(64, OSC_string.size() - 1);
// Search string backwards until we find a ';', marking the end of
// options. This works since the clipboards contents are base64 encoded,
// and cannot contain ';' in the encoded form.
for (; i >= 2 && OSC_string[i] != ';'; i--) {}
i++;
Terminal::Framebuffer::title_type clipboard(
OSC_string.begin() + 5, OSC_string.end() );
OSC_string.begin() + i, OSC_string.end() );
fb->set_clipboard( clipboard );
/* handle osc terminal title sequence */
} else if ( OSC_string.size() >= 1 ) {
Expand Down