From b4512811ba9780dd83f5bff435920ee99dce51fb Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 18 Sep 2013 17:30:35 -0400 Subject: [PATCH] fixed prompt scroll bugs and statusbar struct issues --- src/chat.c | 2 +- src/friendlist.c | 2 +- src/prompt.c | 43 +++++++++++++++++++++++-------------------- src/prompt.h | 4 ++++ src/toxic_windows.h | 1 + 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/chat.c b/src/chat.c index a7760d9..67c3a86 100644 --- a/src/chat.c +++ b/src/chat.c @@ -314,7 +314,7 @@ static void execute(ToxWindow *self, ChatContext *ctx, StatusBar *statusbar, Tox } tox_setname(m, nick, len+1); - prompt_update_nick(self->prompt, nick); + prompt_update_nick(self->prompt, nick, len+1); wprintw(ctx->history, "Nickname set to: %s\n", nick); } diff --git a/src/friendlist.c b/src/friendlist.c index 8f722d5..c8c6377 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -21,7 +21,7 @@ extern ToxWindow *prompt; typedef struct { uint8_t name[TOX_MAX_NAME_LENGTH]; - uint8_t namelength; + uint16_t namelength; uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH]; uint16_t statusmsg_len; int num; diff --git a/src/prompt.c b/src/prompt.c index 53b297c..622abb6 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -65,17 +65,19 @@ static struct { }; /* Updates own nick in prompt statusbar */ -void prompt_update_nick(ToxWindow *prompt, uint8_t *nick) +void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len) { StatusBar *statusbar = (StatusBar *) prompt->stb; snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick); + statusbar->nick_len = len; } /* Updates own statusmessage in prompt statusbar */ -void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg) +void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len) { StatusBar *statusbar = (StatusBar *) prompt->stb; snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg); + statusbar->statusmsg_len = len; } /* Updates own status in prompt statusbar */ @@ -170,13 +172,6 @@ void cmd_add(ToxWindow *self, Tox *m, int argc, char **argv) return; } - uint8_t id_bin[TOX_FRIEND_ADDRESS_SIZE]; - char xx[3]; - uint32_t x; - uint8_t *msg; - size_t i; - int num; - char *id = argv[1]; if (id == NULL) { @@ -184,6 +179,8 @@ void cmd_add(ToxWindow *self, Tox *m, int argc, char **argv) return; } + uint8_t *msg; + if (argc == 2) { msg = argv[2]; @@ -207,6 +204,11 @@ void cmd_add(ToxWindow *self, Tox *m, int argc, char **argv) return; } + size_t i; + char xx[3]; + uint32_t x; + uint8_t id_bin[TOX_FRIEND_ADDRESS_SIZE]; + for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; ++i) { xx[0] = id[2 * i]; xx[1] = id[2 * i + 1]; @@ -224,7 +226,7 @@ void cmd_add(ToxWindow *self, Tox *m, int argc, char **argv) id[i] = toupper(id[i]); } - num = tox_addfriend(m, id_bin, msg, strlen(msg) + 1); + int num = tox_addfriend(m, id_bin, msg, strlen(msg) + 1); switch (num) { case TOX_FAERR_TOOLONG: @@ -341,7 +343,7 @@ void cmd_help(ToxWindow *self, Tox *m, int argc, char **argv) wprintw(self->window, " note : Set a personal note\n"); wprintw(self->window, " nick : Set your nickname\n"); wprintw(self->window, " join : Join a group chat\n"); - wprintw(self->window, " invite : Invite friend to a groupchat\n"); + wprintw(self->window, " invite : Invite friend to a groupchat\n"); wprintw(self->window, " groupchat : Create a group chat\n"); wprintw(self->window, " myid : Print your ID\n"); wprintw(self->window, " quit/exit : Exit Toxic\n"); @@ -492,7 +494,7 @@ void cmd_nick(ToxWindow *self, Tox *m, int argc, char **argv) } tox_setname(m, nick, len+1); - prompt_update_nick(self, nick); + prompt_update_nick(self, nick, len+1); store_data(m, DATA_FILE); } @@ -545,8 +547,9 @@ void cmd_status(ToxWindow *self, Tox *m, int argc, char **argv) if (msg != NULL) { msg[strlen(++msg)-1] = L'\0'; /* remove opening and closing quotes */ - tox_set_statusmessage(m, msg, strlen(msg) + 1); - prompt_update_statusmessage(self, msg); + uint16_t len = strlen(msg) + 1; + tox_set_statusmessage(m, msg, len); + prompt_update_statusmessage(self, msg, len); } } @@ -570,9 +573,9 @@ void cmd_note(ToxWindow *self, Tox *m, int argc, char **argv) } msg[strlen(++msg)-1] = L'\0'; - - tox_set_statusmessage(m, msg, strlen(msg) + 1); - prompt_update_statusmessage(self, msg); + uint16_t len = strlen(msg) + 1; + tox_set_statusmessage(m, msg, len); + prompt_update_statusmessage(self, msg, len); } static void execute(ToxWindow *self, Tox *m, char *u_cmd) @@ -663,14 +666,14 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key) /* Add printable characters to line */ if (isprint(key)) { if (prompt_buf_pos == (sizeof(prompt_buf) - 1)) { - wprintw(self->window, "\nToo Long.\n"); - prompt_buf_pos = 0; - prompt_buf[0] = 0; + return; } else if (!(prompt_buf_pos == 0) && (prompt_buf_pos < COLS) && (prompt_buf_pos % (COLS - 3) == 0)) { + wprintw(self->window, "\n"); prompt_buf[prompt_buf_pos++] = '\n'; } else if (!(prompt_buf_pos == 0) && (prompt_buf_pos > COLS) && ((prompt_buf_pos - (COLS - 3)) % (COLS) == 0)) { + wprintw(self->window, "\n"); prompt_buf[prompt_buf_pos++] = '\n'; } diff --git a/src/prompt.h b/src/prompt.h index c4d51df..6f56b25 100644 --- a/src/prompt.h +++ b/src/prompt.h @@ -7,5 +7,9 @@ ToxWindow new_prompt(); int add_req(uint8_t *public_key); unsigned char *hex_string_to_bin(char hex_string[]); void prompt_init_statusbar(ToxWindow *self, Tox *m); +void prompt_update_nick(ToxWindow *prompt, uint8_t *nick, uint16_t len); +void prompt_update_statusmessage(ToxWindow *prompt, uint8_t *statusmsg, uint16_t len); +void prompt_update_status(ToxWindow *prompt, TOX_USERSTATUS status); +void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected); #endif /* end of include guard: PROMPT_H_UZYGWFFL */ diff --git a/src/toxic_windows.h b/src/toxic_windows.h index cc29a2d..ccd1d2c 100644 --- a/src/toxic_windows.h +++ b/src/toxic_windows.h @@ -73,6 +73,7 @@ typedef struct { uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH]; uint16_t statusmsg_len; uint8_t nick[TOX_MAX_NAME_LENGTH]; + uint16_t nick_len; TOX_USERSTATUS status; bool is_online; } StatusBar;