From 7e169db30f3bc899c8708badf39d8ed268ef1968 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 28 Jan 2021 22:19:48 +0100 Subject: ssh: client: Improve counting --- ssh/client.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'ssh') diff --git a/ssh/client.c b/ssh/client.c index 79377ce..e338a1b 100644 --- a/ssh/client.c +++ b/ssh/client.c @@ -486,17 +486,20 @@ static void handle_event(struct state *state, const struct tomsg_event event) { break; case TOMSG_EV_IS_ONLINE: - case TOMSG_EV_PUSH_ONLINE: + case TOMSG_EV_PUSH_ONLINE: { + const char *once_strings[4] = {NULL, "once", "twice", "thrice"}; printf(" %s is ", event.is_online.username); if (event.type == TOMSG_EV_PUSH_ONLINE) printf("now "); - if (event.is_online.online_count == 1) { - printf("online once\n"); - } else if (event.is_online.online_count > 1) { - printf("online %" PRIi64 " times\n", event.is_online.online_count); - } else { + const int64_t count = event.is_online.online_count; + if (count <= 0) { printf("offline\n"); + } else if (count <= 3) { + printf("online %s\n", once_strings[count]); + } else { + printf("online %" PRIi64 " times\n", count); } break; + } case TOMSG_EV_USER_ACTIVE: printf(" Marked %s\n", -- cgit v1.2.3-70-g09d2