summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/toxic/prompt.c80
1 files 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 @@
1/* 1/*
2 * Toxic -- Tox Curses Client 2* Toxic -- Tox Curses Client
3 */ 3*/
4 4
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h> 6#include <string.h>
@@ -41,7 +41,17 @@ unsigned char * hex_string_to_bin(char hex_string[])
41static char prompt_buf[256] = {0}; 41static char prompt_buf[256] = {0};
42static int prompt_buf_pos=0; 42static int prompt_buf_pos=0;
43 43
44static void execute(ToxWindow* self, char* cmd) { 44static void execute(ToxWindow* self, char* u_cmd) {
45 int i;
46 int newlines = 0;
47 char cmd[256] = {0};
48 for(i = 0; i < strlen(prompt_buf); i++)
49 {
50 if (u_cmd[i] == '\n')
51 ++newlines;
52 else
53 cmd[i - newlines] = u_cmd[i];
54 }
45 55
46 if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) { 56 if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) {
47 endwin(); 57 endwin();
@@ -158,7 +168,7 @@ static void execute(ToxWindow* self, char* cmd) {
158 break; 168 break;
159 } 169 }
160 } 170 }
161 else if(!strcmp(cmd, "clear")) { 171 else if(!strcmp(cmd, "clear")) {
162 wclear(self->window); 172 wclear(self->window);
163 } 173 }
164 else if(!strcmp(cmd, "help")) { 174 else if(!strcmp(cmd, "help")) {
@@ -197,7 +207,7 @@ static void execute(ToxWindow* self, char* cmd) {
197 207
198 for(i=0; i<32; i++) { 208 for(i=0; i<32; i++) {
199 char xx[3]; 209 char xx[3];
200 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); 210 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
201 strcat(id, xx); 211 strcat(id, xx);
202 } 212 }
203 213
@@ -266,8 +276,16 @@ static void execute(ToxWindow* self, char* cmd) {
266static void prompt_onKey(ToxWindow* self, int key) { 276static void prompt_onKey(ToxWindow* self, int key) {
267 // PRINTABLE characters: Add to line. 277 // PRINTABLE characters: Add to line.
268 if(isprint(key)) { 278 if(isprint(key)) {
269 if(prompt_buf_pos == (COLS - 3)) { 279 if (prompt_buf_pos == 255){
270 return; 280 wprintw(self->window, "\nToo Long.\n");
281 prompt_buf_pos = 0;
282 prompt_buf[0] = 0;
283 }
284 else if(!(prompt_buf_pos == 0) && (prompt_buf_pos < COLS) && (prompt_buf_pos % (COLS - 3) == 0)) {
285 prompt_buf[prompt_buf_pos++] = '\n';
286 }
287 else if(!(prompt_buf_pos == 0) && (prompt_buf_pos > COLS) && ((prompt_buf_pos - (COLS - 3)) % (COLS) == 0)) {
288 prompt_buf[prompt_buf_pos++] = '\n';
271 } 289 }
272 prompt_buf[prompt_buf_pos++] = key; 290 prompt_buf[prompt_buf_pos++] = key;
273 prompt_buf[prompt_buf_pos] = 0; 291 prompt_buf[prompt_buf_pos] = 0;
@@ -290,20 +308,22 @@ static void prompt_onKey(ToxWindow* self, int key) {
290} 308}
291 309
292static void prompt_onDraw(ToxWindow* self) { 310static void prompt_onDraw(ToxWindow* self) {
293 curs_set(1); 311 curs_set(1);
294 int x, y; 312 int x, y;
295 313 getyx(self->window, y, x);
296 getyx(self->window, y, x); 314 (void) x;
297 (void) x; 315 int i;
298 316 for (i = 0; i < (strlen(prompt_buf)); i++)
299 wattron(self->window, COLOR_PAIR(1)); 317 {
300 mvwprintw(self->window, y, 0, "# "); 318 if ((prompt_buf[i] == '\n') && (y != 0))
301 wattroff(self->window, COLOR_PAIR(1)); 319 --y;
302 320 }
303 mvwprintw(self->window, y, 2, "%s", prompt_buf); 321 wattron(self->window, COLOR_PAIR(1));
304 wclrtoeol(self->window); 322 mvwprintw(self->window, y, 0, "# ");
305 323 wattroff(self->window, COLOR_PAIR(1));
306 wrefresh(self->window); 324 mvwprintw(self->window, y, 2, "%s", prompt_buf);
325 wclrtoeol(self->window);
326 wrefresh(self->window);
307} 327}
308 328
309static void print_usage(ToxWindow* self) { 329static void print_usage(ToxWindow* self) {
@@ -311,15 +331,15 @@ static void print_usage(ToxWindow* self) {
311 wprintw(self->window, "Commands:\n"); 331 wprintw(self->window, "Commands:\n");
312 wattroff(self->window, A_BOLD); 332 wattroff(self->window, A_BOLD);
313 333
314 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n"); 334 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
315 wprintw(self->window, " add <id> <message> : Add friend\n"); 335 wprintw(self->window, " add <id> <message> : Add friend\n");
316 wprintw(self->window, " status <message> : Set your status\n"); 336 wprintw(self->window, " status <message> : Set your status\n");
317 wprintw(self->window, " nick <nickname> : Set your nickname\n"); 337 wprintw(self->window, " nick <nickname> : Set your nickname\n");
318 wprintw(self->window, " accept <number> : Accept friend request\n"); 338 wprintw(self->window, " accept <number> : Accept friend request\n");
319 wprintw(self->window, " myid : Print your ID\n"); 339 wprintw(self->window, " myid : Print your ID\n");
320 wprintw(self->window, " quit/exit : Exit program\n"); 340 wprintw(self->window, " quit/exit : Exit program\n");
321 wprintw(self->window, " help : Print this message again\n"); 341 wprintw(self->window, " help : Print this message again\n");
322 wprintw(self->window, " clear : Clear this window\n"); 342 wprintw(self->window, " clear : Clear this window\n");
323 343
324 wattron(self->window, A_BOLD); 344 wattron(self->window, A_BOLD);
325 wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n"); 345 wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n");