summaryrefslogtreecommitdiff
path: root/testing/toxic
diff options
context:
space:
mode:
Diffstat (limited to 'testing/toxic')
-rw-r--r--testing/toxic/prompt.c85
1 files changed, 53 insertions, 32 deletions
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index 16750c5d..a53c163f 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,11 +168,12 @@ 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")) {
165 print_usage(self); 175 wclear(self->window);
176 print_usage(self);
166 } 177 }
167 else if(!strncmp(cmd, "status ", strlen("status "))) { 178 else if(!strncmp(cmd, "status ", strlen("status "))) {
168 char* msg; 179 char* msg;
@@ -196,7 +207,7 @@ static void execute(ToxWindow* self, char* cmd) {
196 207
197 for(i=0; i<32; i++) { 208 for(i=0; i<32; i++) {
198 char xx[3]; 209 char xx[3];
199 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff); 210 snprintf(xx, sizeof(xx), "%02x", self_public_key[i] & 0xff);
200 strcat(id, xx); 211 strcat(id, xx);
201 } 212 }
202 213
@@ -265,8 +276,16 @@ static void execute(ToxWindow* self, char* cmd) {
265static void prompt_onKey(ToxWindow* self, int key) { 276static void prompt_onKey(ToxWindow* self, int key) {
266 // PRINTABLE characters: Add to line. 277 // PRINTABLE characters: Add to line.
267 if(isprint(key)) { 278 if(isprint(key)) {
268 if(prompt_buf_pos == (sizeof(prompt_buf) - 1)) { 279 if (prompt_buf_pos == (sizeof(prompt_buf) - 1)){
269 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';
270 } 289 }
271 prompt_buf[prompt_buf_pos++] = key; 290 prompt_buf[prompt_buf_pos++] = key;
272 prompt_buf[prompt_buf_pos] = 0; 291 prompt_buf[prompt_buf_pos] = 0;
@@ -289,20 +308,22 @@ static void prompt_onKey(ToxWindow* self, int key) {
289} 308}
290 309
291static void prompt_onDraw(ToxWindow* self) { 310static void prompt_onDraw(ToxWindow* self) {
292 curs_set(1); 311 curs_set(1);
293 int x, y; 312 int x, y;
294 313 getyx(self->window, y, x);
295 getyx(self->window, y, x); 314 (void) x;
296 (void) x; 315 int i;
297 316 for (i = 0; i < (strlen(prompt_buf)); i++)
298 wattron(self->window, COLOR_PAIR(1)); 317 {
299 mvwprintw(self->window, y, 0, "# "); 318 if ((prompt_buf[i] == '\n') && (y != 0))
300 wattroff(self->window, COLOR_PAIR(1)); 319 --y;
301 320 }
302 mvwprintw(self->window, y, 2, "%s", prompt_buf); 321 wattron(self->window, COLOR_PAIR(1));
303 wclrtoeol(self->window); 322 mvwprintw(self->window, y, 0, "# ");
304 323 wattroff(self->window, COLOR_PAIR(1));
305 wrefresh(self->window); 324 mvwprintw(self->window, y, 2, "%s", prompt_buf);
325 wclrtoeol(self->window);
326 wrefresh(self->window);
306} 327}
307 328
308static void print_usage(ToxWindow* self) { 329static void print_usage(ToxWindow* self) {
@@ -310,15 +331,15 @@ static void print_usage(ToxWindow* self) {
310 wprintw(self->window, "Commands:\n"); 331 wprintw(self->window, "Commands:\n");
311 wattroff(self->window, A_BOLD); 332 wattroff(self->window, A_BOLD);
312 333
313 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");
314 wprintw(self->window, " add <id> <message> : Add friend\n"); 335 wprintw(self->window, " add <id> <message> : Add friend\n");
315 wprintw(self->window, " status <message> : Set your status\n"); 336 wprintw(self->window, " status <message> : Set your status\n");
316 wprintw(self->window, " nick <nickname> : Set your nickname\n"); 337 wprintw(self->window, " nick <nickname> : Set your nickname\n");
317 wprintw(self->window, " accept <number> : Accept friend request\n"); 338 wprintw(self->window, " accept <number> : Accept friend request\n");
318 wprintw(self->window, " myid : Print your ID\n"); 339 wprintw(self->window, " myid : Print your ID\n");
319 wprintw(self->window, " quit/exit : Exit program\n"); 340 wprintw(self->window, " quit/exit : Exit program\n");
320 wprintw(self->window, " help : Print this message again\n"); 341 wprintw(self->window, " help : Print this message again\n");
321 wprintw(self->window, " clear : Clear this window\n"); 342 wprintw(self->window, " clear : Clear this window\n");
322 343
323 wattron(self->window, A_BOLD); 344 wattron(self->window, A_BOLD);
324 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");