1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 14:53:26 +01:00

prevent statusmessage from wrapping on prompt screen

This commit is contained in:
Jfreegman 2014-08-10 00:29:18 -04:00
parent e75cf4f3ad
commit 2f12a8d429
2 changed files with 30 additions and 4 deletions

View File

@ -943,10 +943,11 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
self->x = x2; self->x = x2;
/* Truncate note if it doesn't fit in statusbar */ /* Truncate note if it doesn't fit in statusbar */
uint16_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 7; uint16_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 6;
if (statusbar->statusmsg_len > maxlen) { if (statusbar->statusmsg_len > maxlen) {
statusbar->statusmsg[maxlen] = '\0'; statusbar->statusmsg[maxlen - 3] = '\0';
strcat(statusbar->statusmsg, "...");
statusbar->statusmsg_len = maxlen; statusbar->statusmsg_len = maxlen;
} }

View File

@ -44,6 +44,7 @@
extern ToxWindow *prompt; extern ToxWindow *prompt;
extern struct user_settings *user_settings_; extern struct user_settings *user_settings_;
extern struct _Winthread Winthread;
_FriendRequests FriendRequests; _FriendRequests FriendRequests;
@ -267,6 +268,29 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
wattroff(statusbar->topline, A_BOLD); wattroff(statusbar->topline, A_BOLD);
} }
/* Reset statusbar->statusmsg on window resize */
if (x2 != self->x) {
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {0};
pthread_mutex_lock(&Winthread.lock);
tox_get_self_status_message(m, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
pthread_mutex_unlock(&Winthread.lock);
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
statusbar->statusmsg_len = strlen(statusbar->statusmsg);
}
self->x = x2;
/* Truncate note if it doesn't fit in statusbar */
uint16_t maxlen = x2 - getcurx(statusbar->topline) - 3;
if (statusbar->statusmsg_len > maxlen) {
statusbar->statusmsg[maxlen - 3] = '\0';
strcat(statusbar->statusmsg, "...");
statusbar->statusmsg_len = maxlen;
}
if (statusbar->statusmsg[0]) if (statusbar->statusmsg[0])
wprintw(statusbar->topline, " - %s", statusbar->statusmsg); wprintw(statusbar->topline, " - %s", statusbar->statusmsg);
@ -376,10 +400,11 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
strcpy(ver, TOXICVER); strcpy(ver, TOXICVER);
const char *toxic_ver = strtok(ver, "_"); const char *toxic_ver = strtok(ver, "_");
if ( (!statusmsg[0] || !strncmp("Toxing on Toxic", statusmsg, 15)) && toxic_ver != NULL) { if ( (s_len <= 0 || !strncmp("Toxing on Toxic", statusmsg, strlen("Toxing on Toxic"))) && toxic_ver != NULL) {
snprintf(statusmsg, MAX_STR_SIZE, "Toxing on Toxic v.%s", toxic_ver); snprintf(statusmsg, sizeof(statusmsg), "Toxing on Toxic v.%s", toxic_ver);
s_len = strlen(statusmsg); s_len = strlen(statusmsg);
statusmsg[s_len] = '\0'; statusmsg[s_len] = '\0';
tox_set_status_message(m, (uint8_t *) statusmsg, (uint64_t) s_len);
} }
prompt_update_statusmessage(prompt, statusmsg); prompt_update_statusmessage(prompt, statusmsg);