diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2021-01-28 22:19:48 +0100 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2021-01-28 22:19:48 +0100 |
commit | 7e169db30f3bc899c8708badf39d8ed268ef1968 (patch) | |
tree | 6a76bb9c7ca05a67590835209a16624a13299876 /ssh | |
parent | fcb0a17768142fbd660aae6a24015b67522b015a (diff) |
ssh: client: Improve counting
Diffstat (limited to 'ssh')
-rw-r--r-- | ssh/client.c | 15 |
1 files changed, 9 insertions, 6 deletions
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", |