From e70a8886d6facd83a97dde50d70c07778eccee90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9Fmur=20Oymak?= Date: Wed, 17 Jul 2019 12:22:06 +0300 Subject: [PATCH] Show server IP on timeout banner --- src/frontend/stmclient.cc | 1 + src/frontend/terminaloverlay.cc | 11 ++++++----- src/frontend/terminaloverlay.h | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/frontend/stmclient.cc b/src/frontend/stmclient.cc index e6e9b3a31..c983edee3 100644 --- a/src/frontend/stmclient.cc +++ b/src/frontend/stmclient.cc @@ -192,6 +192,7 @@ void STMClient::init( void ) wstring escape_key_name = std::wstring(tmp.begin(), tmp.end()); escape_key_help = L"Commands: Ctrl-Z suspends, \".\" quits, " + escape_pass_name + L" gives literal " + escape_key_name; overlays.get_notification_engine().set_escape_key_string( tmp ); + overlays.get_notification_engine().server_address( ip ); } wchar_t tmp[ 128 ]; swprintf( tmp, 128, L"Nothing received from server on UDP port %s.", port.c_str() ); diff --git a/src/frontend/terminaloverlay.cc b/src/frontend/terminaloverlay.cc index adee67350..2737c2a76 100644 --- a/src/frontend/terminaloverlay.cc +++ b/src/frontend/terminaloverlay.cc @@ -159,6 +159,7 @@ void ConditionalCursorMove::apply( Framebuffer &fb, uint64_t confirmed_epoch ) c NotificationEngine::NotificationEngine() : last_word_from_server( timestamp() ), last_acked_state( timestamp() ), + server_addr(), escape_key_string(), message(), message_is_network_error( false ), @@ -216,8 +217,8 @@ void NotificationEngine::apply( Framebuffer &fb ) const double since_heard = (double)(now - last_word_from_server) / 1000.0; double since_ack = (double)(now - last_acked_state) / 1000.0; - const char server_message[] = "contact"; - const char reply_message[] = "reply"; + const char server_message[] = "contact with"; + const char reply_message[] = "reply from"; double time_elapsed = since_heard; const char *explanation = server_message; @@ -235,17 +236,17 @@ void NotificationEngine::apply( Framebuffer &fb ) const return; } if ( message.empty() && time_expired ) { - swprintf( tmp, 128, L"mosh: Last %s %s ago.%s", explanation, + swprintf( tmp, 128, L"mosh: Last %s %s %s ago.%s", explanation, server_addr.c_str(), human_readable_duration( static_cast( time_elapsed ), "seconds" ).c_str(), keystroke_str ); } else if ( (!message.empty()) && (!time_expired) ) { swprintf( tmp, 128, L"mosh: %ls%s", message.c_str(), keystroke_str ); } else { - swprintf( tmp, 128, L"mosh: %ls (%s without %s.)%s", message.c_str(), + swprintf( tmp, 128, L"mosh: %ls (%s without %s %s.)%s", message.c_str(), human_readable_duration( static_cast( time_elapsed ), "s" ).c_str(), - explanation, keystroke_str ); + explanation, server_addr.c_str(), keystroke_str ); } wstring string_to_draw( tmp ); diff --git a/src/frontend/terminaloverlay.h b/src/frontend/terminaloverlay.h index 84421eb81..45028830d 100644 --- a/src/frontend/terminaloverlay.h +++ b/src/frontend/terminaloverlay.h @@ -141,6 +141,7 @@ namespace Overlay { private: uint64_t last_word_from_server; uint64_t last_acked_state; + string server_addr; string escape_key_string; wstring message; bool message_is_network_error; @@ -157,6 +158,7 @@ namespace Overlay { const wstring &get_notification_string( void ) const { return message; } void server_heard( uint64_t s_last_word ) { last_word_from_server = s_last_word; } void server_acked( uint64_t s_last_acked ) { last_acked_state = s_last_acked; } + void server_address( const std::string &addr ) { server_addr = addr; } int wait_time( void ) const; void set_notification_string( const wstring &s_message, bool permanent = false, bool s_show_quit_keystroke = true )