Skip to content

Commit

Permalink
Show infobar when Ctrl-^ is typed.
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Nov 26, 2012
1 parent 5eafc20 commit e2b40fc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/frontend/stmclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ bool STMClient::process_user_input( int fd )

overlays.get_prediction_engine().new_user_byte( the_byte, *local_framebuffer );

const static wstring help_message( L"Commands: Ctrl-Z suspends, \".\" quits, \"^\" gives literal Ctrl-^" );

if ( quit_sequence_started ) {
if ( the_byte == '.' ) { /* Quit sequence is Ctrl-^ . */
if ( network->has_remote_addr() && (!network->shutdown_in_progress()) ) {
Expand Down Expand Up @@ -291,11 +293,17 @@ bool STMClient::process_user_input( int fd )
}

quit_sequence_started = false;

if ( overlays.get_notification_engine().get_notification_string() == help_message ) {
overlays.get_notification_engine().set_notification_string( L"" );
}

continue;
}

quit_sequence_started = (the_byte == 0x1E);
if ( quit_sequence_started ) {
overlays.get_notification_engine().set_notification_string( help_message, true, false );
continue;
}

Expand Down
19 changes: 13 additions & 6 deletions src/frontend/terminaloverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ NotificationEngine::NotificationEngine()
last_acked_state( timestamp() ),
message(),
message_is_network_exception( false ),
message_expiration( -1 )
message_expiration( -1 ),
show_quit_keystroke( true )
{}

static std::string human_readable_duration( int num_seconds, const std::string seconds_abbr ) {
Expand Down Expand Up @@ -232,16 +233,22 @@ void NotificationEngine::apply( Framebuffer &fb ) const
explanation = reply_message;
}

const static char quit_keystroke[] = " [To quit: Ctrl-^ .]";
const static char blank[] = "";

const char *keystroke_str = show_quit_keystroke ? quit_keystroke : blank;

if ( message.empty() && (!time_expired) ) {
return;
} else if ( message.empty() && time_expired ) {
swprintf( tmp, 128, L"mosh: Last %s %s ago. [To quit: Ctrl-^ .]", explanation,
human_readable_duration( time_elapsed, "seconds" ).c_str() );
swprintf( tmp, 128, L"mosh: Last %s %s ago.%s", explanation,
human_readable_duration( time_elapsed, "seconds" ).c_str(),
keystroke_str );
} else if ( (!message.empty()) && (!time_expired) ) {
swprintf( tmp, 128, L"mosh: %ls [To quit: Ctrl-^ .]", message.c_str() );
swprintf( tmp, 128, L"mosh: %ls%s", message.c_str(), keystroke_str );
} else {
swprintf( tmp, 128, L"mosh: %ls (%s without %s.) [To quit: Ctrl-^ .]", message.c_str(),
human_readable_duration( time_elapsed, "s" ).c_str(), explanation );
swprintf( tmp, 128, L"mosh: %ls (%s without %s.)%s", message.c_str(),
human_readable_duration( time_elapsed, "s" ).c_str(), explanation, keystroke_str );
}

wstring string_to_draw( tmp );
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/terminaloverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ namespace Overlay {
wstring message;
bool message_is_network_exception;
uint64_t message_expiration;
bool show_quit_keystroke;

bool server_late( uint64_t ts ) const { return (ts - last_word_from_server) > 6500; }
bool reply_late( uint64_t ts ) const { return (ts - last_acked_state) > 10000; }
Expand All @@ -160,7 +161,7 @@ namespace Overlay {
void server_acked( uint64_t s_last_acked ) { last_acked_state = s_last_acked; }
int wait_time( void ) const;

void set_notification_string( const wstring &s_message, bool permanent = false )
void set_notification_string( const wstring &s_message, bool permanent = false, bool s_show_quit_keystroke = true )
{
message = s_message;
if ( permanent ) {
Expand All @@ -169,6 +170,7 @@ namespace Overlay {
message_expiration = timestamp() + 1000;
}
message_is_network_exception = false;
show_quit_keystroke = s_show_quit_keystroke;
}

void set_network_exception( const NetworkException &e )
Expand Down

0 comments on commit e2b40fc

Please sign in to comment.