From d0a818d2e2942fdb3359d569f8bbeb4af55d2ed3 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sat, 14 Apr 2012 01:55:28 -0400 Subject: [PATCH] Track icon name and window title separately. Implement MOSH_TITLE_NOPREFIX --- man/mosh.1 | 10 +++++++ src/frontend/stmclient.cc | 4 ++- src/terminal/terminaldisplay.cc | 46 ++++++++++++++++++++++------- src/terminal/terminalframebuffer.cc | 2 +- src/terminal/terminalframebuffer.h | 3 ++ src/terminal/terminalfunctions.cc | 21 +++++++++++-- 6 files changed, 72 insertions(+), 14 deletions(-) diff --git a/man/mosh.1 b/man/mosh.1 index 626fc48..beaaa9c 100644 --- a/man/mosh.1 +++ b/man/mosh.1 @@ -114,6 +114,16 @@ server. Otherwise, \fBmosh\fP will choose a port between 60000 and The escape sequence to shut down the connection is \fBCtrl-^ .\fP (typically typed with Ctrl-Shift-6, then a period). +.SH ENVIRONMENT VARIABLES + +.TP +.B MOSH_PREDICTION_DISPLAY +Controls local echo as described above. + +.TP +.B MOSH_TITLE_NOPREFIX +When set, inhibits prepending "[mosh]" to window title. + .SH SEE ALSO .BR mosh-client (1), .BR mosh-server (1). diff --git a/src/frontend/stmclient.cc b/src/frontend/stmclient.cc index f9cfb67..1d1a1a6 100644 --- a/src/frontend/stmclient.cc +++ b/src/frontend/stmclient.cc @@ -79,7 +79,9 @@ void STMClient::init( void ) swrite( STDOUT_FILENO, Terminal::Emulator::open().c_str() ); /* Add our name to window title */ - overlays.set_title_prefix( wstring( L"[mosh] " ) ); + if ( !getenv( "MOSH_TITLE_NOPREFIX" ) ) { + overlays.set_title_prefix( wstring( L"[mosh] " ) ); + } } void STMClient::shutdown( void ) diff --git a/src/terminal/terminaldisplay.cc b/src/terminal/terminaldisplay.cc index 4e7e2aa..c32c379 100644 --- a/src/terminal/terminaldisplay.cc +++ b/src/terminal/terminaldisplay.cc @@ -42,19 +42,45 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const frame.append( "\x07" ); } - /* has window title changed? */ + /* has icon name or window title changed? */ if ( (!initialized) + || (f.get_icon_name() != frame.last_frame.get_icon_name()) || (f.get_window_title() != frame.last_frame.get_window_title()) ) { - /* set window title */ - frame.append( "\033]0;" ); - const std::deque &window_title( f.get_window_title() ); - for ( BOOST_AUTO( i, window_title.begin() ); - i != window_title.end(); - i++ ) { - snprintf( tmp, 64, "%lc", *i ); - frame.append( tmp ); + /* set icon name and window title */ + if ( f.get_icon_name() == f.get_window_title() ) { + /* write combined Icon Name and Window Title */ + frame.append( "\033]0;" ); + const std::deque &window_title( f.get_window_title() ); + for ( BOOST_AUTO( i, window_title.begin() ); + i != window_title.end(); + i++ ) { + snprintf( tmp, 64, "%lc", *i ); + frame.append( tmp ); + } + frame.append( "\033\\" ); + } else { + /* write Icon Name */ + frame.append( "\033]1;" ); + const std::deque &icon_name( f.get_icon_name() ); + for ( BOOST_AUTO( i, icon_name.begin() ); + i != icon_name.end(); + i++ ) { + snprintf( tmp, 64, "%lc", *i ); + frame.append( tmp ); + } + frame.append( "\033\\" ); + + frame.append( "\033]2;" ); + const std::deque &window_title( f.get_window_title() ); + for ( BOOST_AUTO( i, window_title.begin() ); + i != window_title.end(); + i++ ) { + snprintf( tmp, 64, "%lc", *i ); + frame.append( tmp ); + } + frame.append( "\033\\" ); } - frame.append( "\033\\" ); + } /* has reverse video state changed? */ diff --git a/src/terminal/terminalframebuffer.cc b/src/terminal/terminalframebuffer.cc index 943d07e..8ac9771 100644 --- a/src/terminal/terminalframebuffer.cc +++ b/src/terminal/terminalframebuffer.cc @@ -49,7 +49,7 @@ DrawState::DrawState( int s_width, int s_height ) } Framebuffer::Framebuffer( int s_width, int s_height ) - : rows( s_height, Row( s_width, 0 ) ), window_title(), bell_count( 0 ), ds( s_width, s_height ) + : rows( s_height, Row( s_width, 0 ) ), icon_name(), window_title(), bell_count( 0 ), ds( s_width, s_height ) { assert( s_height > 0 ); assert( s_width > 0 ); diff --git a/src/terminal/terminalframebuffer.h b/src/terminal/terminalframebuffer.h index f2215e3..bd154b0 100644 --- a/src/terminal/terminalframebuffer.h +++ b/src/terminal/terminalframebuffer.h @@ -218,6 +218,7 @@ namespace Terminal { class Framebuffer { private: std::deque rows; + std::deque icon_name; std::deque window_title; unsigned int bell_count; @@ -283,7 +284,9 @@ namespace Terminal { void reset( void ); void soft_reset( void ); + void set_icon_name( const std::deque &s ) { icon_name = s; } void set_window_title( const std::deque &s ) { window_title = s; } + const std::deque & get_icon_name( void ) const { return icon_name; } const std::deque & get_window_title( void ) const { return window_title; } void prefix_window_title( const std::deque &s ); diff --git a/src/terminal/terminalfunctions.cc b/src/terminal/terminalfunctions.cc index ea3c938..f46e608 100644 --- a/src/terminal/terminalfunctions.cc +++ b/src/terminal/terminalfunctions.cc @@ -506,12 +506,29 @@ static Function func_CSI_DECSTR( CSI, "!p", CSI_DECSTR ); void Dispatcher::OSC_dispatch( const Parser::OSC_End *act, Framebuffer *fb ) { if ( OSC_string.size() >= 2 ) { - if ( (OSC_string[ 0 ] == L'0') + if ( ( (OSC_string[ 0 ] == L'0') + || (OSC_string[ 0 ] == L'1') + || (OSC_string[ 0 ] == L'2') ) && (OSC_string[ 1 ] == L';') ) { std::deque newtitle( OSC_string.begin(), OSC_string.end() ); newtitle.erase( newtitle.begin() ); newtitle.erase( newtitle.begin() ); - fb->set_window_title( newtitle ); + + switch ( OSC_string[ 0 ] ) { + case L'0': + fb->set_icon_name( newtitle ); + fb->set_window_title( newtitle ); + break; + case L'1': + fb->set_icon_name( newtitle ); + break; + case L'2': + fb->set_window_title( newtitle ); + break; + default: + break; + } + act->handled = true; } }