Show infobar when Ctrl-^ is typed.

This commit is contained in:
Keith Winstein
2012-11-26 04:03:04 -05:00
parent 5eafc209ea
commit e2b40fcaa7
3 changed files with 24 additions and 7 deletions
+8
View File
@@ -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()) ) {
@@ -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;
}
+13 -6
View File
@@ -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 ) {
@@ -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 );
+3 -1
View File
@@ -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; }
@@ -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 ) {
@@ -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 )