From 1f001b2f915710e254d039c1f74c533196826235 Mon Sep 17 00:00:00 2001 From: Nominate Date: Tue, 6 Aug 2013 08:10:05 +0100 Subject: Stops line-spamming and clears before printing help This addresses one issue in #340 perfectly and slightly improves the other. --- testing/toxic/prompt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 16750c5d..c832db39 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -159,10 +159,11 @@ static void execute(ToxWindow* self, char* cmd) { } } else if(!strcmp(cmd, "clear")) { - wclear(self->window); + wclear(self->window); } else if(!strcmp(cmd, "help")) { - print_usage(self); + wclear(self->window); + print_usage(self); } else if(!strncmp(cmd, "status ", strlen("status "))) { char* msg; @@ -265,8 +266,8 @@ static void execute(ToxWindow* self, char* cmd) { static void prompt_onKey(ToxWindow* self, int key) { // PRINTABLE characters: Add to line. if(isprint(key)) { - if(prompt_buf_pos == (sizeof(prompt_buf) - 1)) { - return; + if(prompt_buf_pos == (COLS - 3)) { + return; } prompt_buf[prompt_buf_pos++] = key; prompt_buf[prompt_buf_pos] = 0; -- cgit v1.2.3 From 45c84e55e6e25bd95b5b6c86368845ff20dec7e9 Mon Sep 17 00:00:00 2001 From: Nominate Date: Tue, 6 Aug 2013 11:16:17 +0100 Subject: Corrected wrap-around This should allow wrap-around and allow proper execution. --- testing/toxic/prompt.c | 80 +++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index c832db39..742b35f8 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -1,6 +1,6 @@ /* - * Toxic -- Tox Curses Client - */ +* Toxic -- Tox Curses Client +*/ #include #include @@ -41,7 +41,17 @@ unsigned char * hex_string_to_bin(char hex_string[]) static char prompt_buf[256] = {0}; static int prompt_buf_pos=0; -static void execute(ToxWindow* self, char* cmd) { +static void execute(ToxWindow* self, char* u_cmd) { + int i; + int newlines = 0; + char cmd[256] = {0}; + for(i = 0; i < strlen(prompt_buf); i++) + { + if (u_cmd[i] == '\n') + ++newlines; + else + cmd[i - newlines] = u_cmd[i]; + } if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) { endwin(); @@ -158,7 +168,7 @@ static void execute(ToxWindow* self, char* cmd) { break; } } - else if(!strcmp(cmd, "clear")) { + else if(!strcmp(cmd, "clear")) { wclear(self->window); } else if(!strcmp(cmd, "help")) { @@ -197,7 +207,7 @@ static void execute(ToxWindow* self, char* cmd) { for(i=0; i<32; i++) { char xx[3]; - snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); + snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); strcat(id, xx); } @@ -266,8 +276,16 @@ static void execute(ToxWindow* self, char* cmd) { static void prompt_onKey(ToxWindow* self, int key) { // PRINTABLE characters: Add to line. if(isprint(key)) { - if(prompt_buf_pos == (COLS - 3)) { - return; + if (prompt_buf_pos == 255){ + wprintw(self->window, "\nToo Long.\n"); + prompt_buf_pos = 0; + prompt_buf[0] = 0; + } + else if(!(prompt_buf_pos == 0) && (prompt_buf_pos < COLS) && (prompt_buf_pos % (COLS - 3) == 0)) { + prompt_buf[prompt_buf_pos++] = '\n'; + } + else if(!(prompt_buf_pos == 0) && (prompt_buf_pos > COLS) && ((prompt_buf_pos - (COLS - 3)) % (COLS) == 0)) { + prompt_buf[prompt_buf_pos++] = '\n'; } prompt_buf[prompt_buf_pos++] = key; prompt_buf[prompt_buf_pos] = 0; @@ -290,20 +308,22 @@ static void prompt_onKey(ToxWindow* self, int key) { } static void prompt_onDraw(ToxWindow* self) { - curs_set(1); - int x, y; - - getyx(self->window, y, x); - (void) x; - - wattron(self->window, COLOR_PAIR(1)); - mvwprintw(self->window, y, 0, "# "); - wattroff(self->window, COLOR_PAIR(1)); - - mvwprintw(self->window, y, 2, "%s", prompt_buf); - wclrtoeol(self->window); - - wrefresh(self->window); + curs_set(1); + int x, y; + getyx(self->window, y, x); + (void) x; + int i; + for (i = 0; i < (strlen(prompt_buf)); i++) + { + if ((prompt_buf[i] == '\n') && (y != 0)) + --y; + } + wattron(self->window, COLOR_PAIR(1)); + mvwprintw(self->window, y, 0, "# "); + wattroff(self->window, COLOR_PAIR(1)); + mvwprintw(self->window, y, 2, "%s", prompt_buf); + wclrtoeol(self->window); + wrefresh(self->window); } static void print_usage(ToxWindow* self) { @@ -311,15 +331,15 @@ static void print_usage(ToxWindow* self) { wprintw(self->window, "Commands:\n"); wattroff(self->window, A_BOLD); - wprintw(self->window, " connect : Connect to DHT server\n"); - wprintw(self->window, " add : Add friend\n"); - wprintw(self->window, " status : Set your status\n"); - wprintw(self->window, " nick : Set your nickname\n"); - wprintw(self->window, " accept : Accept friend request\n"); - wprintw(self->window, " myid : Print your ID\n"); - wprintw(self->window, " quit/exit : Exit program\n"); - wprintw(self->window, " help : Print this message again\n"); - wprintw(self->window, " clear : Clear this window\n"); + wprintw(self->window, " connect : Connect to DHT server\n"); + wprintw(self->window, " add : Add friend\n"); + wprintw(self->window, " status : Set your status\n"); + wprintw(self->window, " nick : Set your nickname\n"); + wprintw(self->window, " accept : Accept friend request\n"); + wprintw(self->window, " myid : Print your ID\n"); + wprintw(self->window, " quit/exit : Exit program\n"); + wprintw(self->window, " help : Print this message again\n"); + wprintw(self->window, " clear : Clear this window\n"); wattron(self->window, A_BOLD); wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n"); -- cgit v1.2.3 From fb9791bc6946fd893e101537fb19fea3b351b0ce Mon Sep 17 00:00:00 2001 From: Nominate Date: Tue, 6 Aug 2013 11:20:11 +0100 Subject: Update prompt.c --- testing/toxic/prompt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 742b35f8..3006b8a6 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -44,12 +44,12 @@ static int prompt_buf_pos=0; static void execute(ToxWindow* self, char* u_cmd) { int i; int newlines = 0; - char cmd[256] = {0}; + char cmd[256] = {0}; for(i = 0; i < strlen(prompt_buf); i++) { if (u_cmd[i] == '\n') - ++newlines; - else + ++newlines; + else cmd[i - newlines] = u_cmd[i]; } @@ -276,7 +276,7 @@ static void execute(ToxWindow* self, char* u_cmd) { static void prompt_onKey(ToxWindow* self, int key) { // PRINTABLE characters: Add to line. if(isprint(key)) { - if (prompt_buf_pos == 255){ + if (prompt_buf_pos == (sizeof(prompt_buf) - 1)){ wprintw(self->window, "\nToo Long.\n"); prompt_buf_pos = 0; prompt_buf[0] = 0; -- cgit v1.2.3 From 532f16a377616442ba499f48285b9fff4c138a3c Mon Sep 17 00:00:00 2001 From: Nominate Date: Tue, 6 Aug 2013 11:50:10 +0100 Subject: Fixed formatting --- testing/toxic/prompt.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 3006b8a6..a53c163f 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -43,8 +43,8 @@ static int prompt_buf_pos=0; static void execute(ToxWindow* self, char* u_cmd) { int i; - int newlines = 0; - char cmd[256] = {0}; + int newlines = 0; + char cmd[256] = {0}; for(i = 0; i < strlen(prompt_buf); i++) { if (u_cmd[i] == '\n') @@ -331,15 +331,15 @@ static void print_usage(ToxWindow* self) { wprintw(self->window, "Commands:\n"); wattroff(self->window, A_BOLD); - wprintw(self->window, " connect : Connect to DHT server\n"); - wprintw(self->window, " add : Add friend\n"); - wprintw(self->window, " status : Set your status\n"); - wprintw(self->window, " nick : Set your nickname\n"); - wprintw(self->window, " accept : Accept friend request\n"); - wprintw(self->window, " myid : Print your ID\n"); - wprintw(self->window, " quit/exit : Exit program\n"); - wprintw(self->window, " help : Print this message again\n"); - wprintw(self->window, " clear : Clear this window\n"); + wprintw(self->window, " connect : Connect to DHT server\n"); + wprintw(self->window, " add : Add friend\n"); + wprintw(self->window, " status : Set your status\n"); + wprintw(self->window, " nick : Set your nickname\n"); + wprintw(self->window, " accept : Accept friend request\n"); + wprintw(self->window, " myid : Print your ID\n"); + wprintw(self->window, " quit/exit : Exit program\n"); + wprintw(self->window, " help : Print this message again\n"); + wprintw(self->window, " clear : Clear this window\n"); wattron(self->window, A_BOLD); wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n"); -- cgit v1.2.3