support osc 52 clipboard copy integration.

This feature is particularly relevant for mosh for chrome (which also
used in windows I believe).
This commit is contained in:
Alex Cornejo
2017-07-15 19:06:14 +00:00
committed by John Hood
parent 04f6dafb58
commit 4b240ac033
5 changed files with 38 additions and 7 deletions
+13 -2
View File
@@ -31,6 +31,7 @@
*/
#include <unistd.h>
#include <algorithm>
#include <string>
#include <stdio.h>
@@ -39,6 +40,7 @@
#include "parseraction.h"
using namespace Terminal;
using namespace std;
/* Terminal functions -- routines activated by CSI, escape or a control char */
@@ -559,7 +561,15 @@ 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 )
{
if ( OSC_string.size() >= 1 ) {
/* handle osc copy clipboard sequence 52;c; */
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';') {
Terminal::Framebuffer::title_type clipboard(
OSC_string.begin() + 5, OSC_string.end() );
fb->set_clipboard( clipboard );
/* handle osc terminal title sequence */
} else if ( OSC_string.size() >= 1 ) {
long cmd_num = -1;
int offset = 0;
if ( OSC_string[ 0 ] == L';' ) {
@@ -578,7 +588,8 @@ void Dispatcher::OSC_dispatch( const Parser::OSC_End *act __attribute((unused)),
bool set_title = (cmd_num == 0 || cmd_num == 2);
if ( set_icon || set_title ) {
fb->set_title_initialized();
Terminal::Framebuffer::title_type newtitle( OSC_string.begin() + offset, OSC_string.end() );
int title_length = min(OSC_string.size(), (size_t)256);
Terminal::Framebuffer::title_type newtitle( OSC_string.begin() + offset, OSC_string.begin() + title_length );
if ( set_icon ) { fb->set_icon_name( newtitle ); }
if ( set_title ) { fb->set_window_title( newtitle ); }
}