Make username longer than maximum length to be truncated

This commit is contained in:
Night Kaly 2024-09-25 10:46:16 +01:00
parent 46e8b3c8e8
commit c0a1b69223
Signed by: night0721
GPG key ID: 957D67B8DB7A119B

View file

@ -222,11 +222,19 @@ void draw_users()
/* If length of name is longer than half of allowed size in window, /* 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 * trim it to end with .. to show the it is too long to be displayed
*/ */
if (name_len >= (MAX_NAME / 2) - 2) { int too_long = 0;
name_len = (MAX_NAME / 2) - 2; 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; int color = users->items[i].color;
@ -254,7 +262,6 @@ void draw_users()
} }
wattroff(users_content, A_REVERSE); wattroff(users_content, A_REVERSE);
free(line);
line_count++; line_count++;
} }