From c0a1b69223b86dfcdcfe7c2767f464a3b17925f3 Mon Sep 17 00:00:00 2001 From: night0721 Date: Wed, 25 Sep 2024 10:46:16 +0100 Subject: [PATCH] Make username longer than maximum length to be truncated --- src/zen/ui.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/zen/ui.c b/src/zen/ui.c index d098cf8..ba75cb4 100644 --- a/src/zen/ui.c +++ b/src/zen/ui.c @@ -222,11 +222,19 @@ void draw_users() /* If length of name is longer than half of allowed size in window, * trim it to end with .. to show the it is too long to be displayed */ - if (name_len >= (MAX_NAME / 2) - 2) { - name_len = (MAX_NAME / 2) - 2; + int too_long = 0; + if (name_len > MAX_NAME / 2) { + name_len = MAX_NAME / 2; + too_long = 1; + } + + char line[name_len]; + if (too_long) { + strncpy(line, seluser.name, name_len - 2); + strncat(line, "..", 2); + } else { + strcpy(line, seluser.name); } - char *line = memalloc(name_len); - memcpy(line, seluser.name, name_len); int color = users->items[i].color; @@ -254,7 +262,6 @@ void draw_users() } wattroff(users_content, A_REVERSE); - free(line); line_count++; }