Skip to content

Commit

Permalink
Make "elapsed time" human readable even when other error is displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Nov 6, 2012
1 parent cdd00fe commit b018e3a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/frontend/terminaloverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ NotificationEngine::NotificationEngine()
message_expiration( -1 )
{}

static std::string human_readable_duration(int num_seconds) {
static std::string human_readable_duration( int num_seconds, const std::string seconds_abbr ) {
char tmp[ 128 ];
if ( num_seconds < 60 ) {
snprintf( tmp, 128, "%d seconds", num_seconds );
snprintf( tmp, 128, "%d %s", num_seconds, seconds_abbr.c_str() );
} else if ( num_seconds < 3600 ) {
snprintf( tmp, 128, "%d:%02d", num_seconds / 60, num_seconds % 60 );
} else {
Expand Down Expand Up @@ -235,12 +235,13 @@ void NotificationEngine::apply( Framebuffer &fb ) const
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).c_str() );
swprintf( tmp, 128, L"mosh: Last %s %s ago. [To quit: Ctrl-^ .]", explanation,
human_readable_duration( time_elapsed, "seconds" ).c_str() );
} else if ( (!message.empty()) && (!time_expired) ) {
swprintf( tmp, 128, L"mosh: %ls [To quit: Ctrl-^ .]", message.c_str() );
} else {
swprintf( tmp, 128, L"mosh: %ls (%.0f s without %s.) [To quit: Ctrl-^ .]", message.c_str(),
time_elapsed, explanation );
swprintf( tmp, 128, L"mosh: %ls (%s without %s.) [To quit: Ctrl-^ .]", message.c_str(),
human_readable_duration( time_elapsed, "s" ).c_str(), explanation );
}

wstring string_to_draw( tmp );
Expand Down

0 comments on commit b018e3a

Please sign in to comment.