summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorplutooo <tfy12vbr@student.lu.se>2013-07-31 11:20:16 -0700
committerplutooo <tfy12vbr@student.lu.se>2013-07-31 11:20:16 -0700
commit0815d1110d452f174bc523c11291b8da41e01d4a (patch)
tree4a177316087771d4fff0257a9fa5b14fa51b9db3 /testing
parent2247b7fad552d75eb0e0f4407970aa76f64b8942 (diff)
toxic: Made everything 1000x more userfriendly.
Diffstat (limited to 'testing')
-rw-r--r--testing/toxic/chat.c27
-rw-r--r--testing/toxic/friendlist.c37
-rw-r--r--testing/toxic/main.c25
-rw-r--r--testing/toxic/prompt.c7
-rw-r--r--testing/toxic/windows.h7
5 files changed, 79 insertions, 24 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index 53cf3319..da9ad025 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -1,3 +1,7 @@
1/*
2 * Toxic -- Tox Curses Client
3 */
4
1#include <curses.h> 5#include <curses.h>
2#include <stdlib.h> 6#include <stdlib.h>
3#include <string.h> 7#include <string.h>
@@ -38,7 +42,13 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len)
38 fix_name(msg); 42 fix_name(msg);
39 fix_name(nick); 43 fix_name(nick);
40 44
41 wprintw(ctx->history, "%s: %s\n", nick, msg); 45 wattron(ctx->history, COLOR_PAIR(4));
46 wprintw(ctx->history, "%s: ", nick);
47 wattroff(ctx->history, COLOR_PAIR(4));
48
49 wprintw(ctx->history, "%s\n", msg);
50
51 self->blink = true;
42} 52}
43 53
44static void chat_onNickChange(ToxWindow* self, int num, uint8_t* nick, uint16_t len) { 54static void chat_onNickChange(ToxWindow* self, int num, uint8_t* nick, uint16_t len) {
@@ -70,15 +80,27 @@ static void chat_onKey(ToxWindow* self, int key) {
70 } 80 }
71 } 81 }
72 else if(key == '\n') { 82 else if(key == '\n') {
73 wprintw(ctx->history, "you: %s\n", ctx->line); 83 wattron(ctx->history, COLOR_PAIR(1));
84 wprintw(ctx->history, "you: ", ctx->line);
85 wattroff(ctx->history, COLOR_PAIR(1));
86
87 wprintw(ctx->history, "%s\n", ctx->line);
74 88
75 if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { 89 if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) {
90 wattron(ctx->history, COLOR_PAIR(3));
76 wprintw(ctx->history, " * Failed to send message.\n"); 91 wprintw(ctx->history, " * Failed to send message.\n");
92 wattroff(ctx->history, COLOR_PAIR(3));
77 } 93 }
78 94
79 ctx->line[0] = '\0'; 95 ctx->line[0] = '\0';
80 ctx->pos = 0; 96 ctx->pos = 0;
81 } 97 }
98 else if(key == 0x107) {
99 if(ctx->pos != 0) {
100 ctx->line[--ctx->pos] = '\0';
101 }
102 }
103
82} 104}
83 105
84static void chat_onDraw(ToxWindow* self) { 106static void chat_onDraw(ToxWindow* self) {
@@ -105,7 +127,6 @@ static void chat_onInit(ToxWindow* self) {
105 getmaxyx(self->window, y, x); 127 getmaxyx(self->window, y, x);
106 128
107 ctx->history = subwin(self->window, y - 4, x, 0, 0); 129 ctx->history = subwin(self->window, y - 4, x, 0, 0);
108 wprintw(ctx->history, "Here goes chat\n");
109 scrollok(ctx->history, 1); 130 scrollok(ctx->history, 1);
110 131
111 ctx->linewin = subwin(self->window, 2, x, y - 3, 0); 132 ctx->linewin = subwin(self->window, 2, x, y - 3, 0);
diff --git a/testing/toxic/friendlist.c b/testing/toxic/friendlist.c
index 629adaff..f9a413f9 100644
--- a/testing/toxic/friendlist.c
+++ b/testing/toxic/friendlist.c
@@ -22,7 +22,7 @@ typedef struct {
22 uint8_t name[MAX_NAME_LENGTH]; 22 uint8_t name[MAX_NAME_LENGTH];
23 uint8_t status[MAX_USERSTATUS_LENGTH]; 23 uint8_t status[MAX_USERSTATUS_LENGTH];
24 int num; 24 int num;
25 25 int chatwin;
26} friend_t; 26} friend_t;
27 27
28static friend_t friends[MAX_FRIENDS_NUM]; 28static friend_t friends[MAX_FRIENDS_NUM];
@@ -37,7 +37,7 @@ void fix_name(uint8_t* name) {
37 uint8_t* q = name; 37 uint8_t* q = name;
38 38
39 while(*p != 0) { 39 while(*p != 0) {
40 if(isalnum(*p)) { 40 if(isprint(*p)) {
41 *q++ = *p; 41 *q++ = *p;
42 } 42 }
43 43
@@ -47,6 +47,16 @@ void fix_name(uint8_t* name) {
47 *q = 0; 47 *q = 0;
48} 48}
49 49
50void friendlist_onMessage(ToxWindow* self, int num, uint8_t* str, uint16_t len) {
51
52 if(num >= num_friends)
53 return;
54
55 if(friends[num].chatwin == -1) {
56 friends[num].chatwin = add_window(new_chat(num));
57 }
58}
59
50void friendlist_onNickChange(ToxWindow* self, int num, uint8_t* str, uint16_t len) { 60void friendlist_onNickChange(ToxWindow* self, int num, uint8_t* str, uint16_t len) {
51 61
52 if(len >= MAX_NAME_LENGTH || num >= num_friends) 62 if(len >= MAX_NAME_LENGTH || num >= num_friends)
@@ -55,8 +65,6 @@ void friendlist_onNickChange(ToxWindow* self, int num, uint8_t* str, uint16_t le
55 memcpy((char*) &friends[num].name, (char*) str, len); 65 memcpy((char*) &friends[num].name, (char*) str, len);
56 friends[num].name[len] = 0; 66 friends[num].name[len] = 0;
57 fix_name(friends[num].name); 67 fix_name(friends[num].name);
58
59 return;
60} 68}
61 69
62void friendlist_onStatusChange(ToxWindow* self, int num, uint8_t* str, uint16_t len) { 70void friendlist_onStatusChange(ToxWindow* self, int num, uint8_t* str, uint16_t len) {
@@ -67,8 +75,6 @@ void friendlist_onStatusChange(ToxWindow* self, int num, uint8_t* str, uint16_t
67 memcpy((char*) &friends[num].status, (char*) str, len); 75 memcpy((char*) &friends[num].status, (char*) str, len);
68 friends[num].status[len] = 0; 76 friends[num].status[len] = 0;
69 fix_name(friends[num].status); 77 fix_name(friends[num].status);
70
71 return;
72} 78}
73 79
74int friendlist_onFriendAdded(int num) { 80int friendlist_onFriendAdded(int num) {
@@ -80,6 +86,7 @@ int friendlist_onFriendAdded(int num) {
80 getname(num, friends[num_friends].name); 86 getname(num, friends[num_friends].name);
81 strcpy((char*) friends[num_friends].name, "unknown"); 87 strcpy((char*) friends[num_friends].name, "unknown");
82 strcpy((char*) friends[num_friends].status, "unknown"); 88 strcpy((char*) friends[num_friends].status, "unknown");
89 friends[num_friends].chatwin = -1;
83 90
84 num_friends++; 91 num_friends++;
85 return 0; 92 return 0;
@@ -96,7 +103,12 @@ static void friendlist_onKey(ToxWindow* self, int key) {
96 num_selected = (num_selected+1) % num_friends; 103 num_selected = (num_selected+1) % num_friends;
97 } 104 }
98 else if(key == '\n') { 105 else if(key == '\n') {
99 focus_window(add_window(new_chat(num_selected))); 106
107 if(friends[num_selected].chatwin != -1)
108 return;
109
110 friends[num_selected].chatwin = add_window(new_chat(num_selected));
111 focus_window(friends[num_selected].chatwin);
100 } 112 }
101} 113}
102 114
@@ -110,12 +122,8 @@ static void friendlist_onDraw(ToxWindow* self) {
110 } 122 }
111 else { 123 else {
112 wattron(self->window, COLOR_PAIR(2) | A_BOLD); 124 wattron(self->window, COLOR_PAIR(2) | A_BOLD);
113 wprintw(self->window, "Friend list:\n"); 125 wprintw(self->window, "Open chat with.. (up/down keys, enter)\n");
114 wattroff(self->window, A_BOLD); 126 wattroff(self->window, COLOR_PAIR(2) | A_BOLD);
115
116 wprintw(self->window, " ENTER: start a chat\n");
117 wprintw(self->window, " UP/DOWN: navigate list\n");
118 wattroff(self->window, COLOR_PAIR(2));
119 } 127 }
120 128
121 wprintw(self->window, "\n"); 129 wprintw(self->window, "\n");
@@ -123,7 +131,7 @@ static void friendlist_onDraw(ToxWindow* self) {
123 for(i=0; i<num_friends; i++) { 131 for(i=0; i<num_friends; i++) {
124 132
125 if(i == num_selected) wattron(self->window, COLOR_PAIR(3)); 133 if(i == num_selected) wattron(self->window, COLOR_PAIR(3));
126 wprintw(self->window, " [%d] ", friends[i].num); 134 wprintw(self->window, " [#%d] ", friends[i].num);
127 if(i == num_selected) wattroff(self->window, COLOR_PAIR(3)); 135 if(i == num_selected) wattroff(self->window, COLOR_PAIR(3));
128 136
129 attron(A_BOLD); 137 attron(A_BOLD);
@@ -149,6 +157,7 @@ ToxWindow new_friendlist() {
149 ret.onKey = &friendlist_onKey; 157 ret.onKey = &friendlist_onKey;
150 ret.onDraw = &friendlist_onDraw; 158 ret.onDraw = &friendlist_onDraw;
151 ret.onInit = &friendlist_onInit; 159 ret.onInit = &friendlist_onInit;
160 ret.onMessage = &friendlist_onMessage;
152 ret.onNickChange = &friendlist_onNickChange; 161 ret.onNickChange = &friendlist_onNickChange;
153 ret.onStatusChange = &friendlist_onStatusChange; 162 ret.onStatusChange = &friendlist_onStatusChange;
154 strcpy(ret.title, "[friends]"); 163 strcpy(ret.title, "[friends]");
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index 1c095c54..fffc3f84 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -32,7 +32,14 @@ void on_request(uint8_t* public_key, uint8_t* data, uint16_t length) {
32 size_t i; 32 size_t i;
33 int n = add_req(public_key); 33 int n = add_req(public_key);
34 34
35 wprintw(prompt->window, "\nFriend request.\nUse \"accept %d\" to accept it.\n", n); 35 wprintw(prompt->window, "\nFriend request from:\n");
36
37 for(i=0; i<32; i++) {
38 wprintw(prompt->window, "%02x", public_key[i] & 0xff);
39 }
40 wprintw(prompt->window, "\n");
41
42 wprintw(prompt->window, "Use \"accept %d\" to accept it.\n", n);
36 43
37 for(i=0; i<w_num; i++) { 44 for(i=0; i<w_num; i++) {
38 if(windows[i].onFriendRequest != NULL) 45 if(windows[i].onFriendRequest != NULL)
@@ -230,6 +237,7 @@ static void load_data() {
230} 237}
231 238
232static void draw_bar() { 239static void draw_bar() {
240 static int odd = 0;
233 size_t i; 241 size_t i;
234 242
235 attron(COLOR_PAIR(4)); 243 attron(COLOR_PAIR(4));
@@ -238,17 +246,27 @@ static void draw_bar() {
238 246
239 move(LINES - 1, 0); 247 move(LINES - 1, 0);
240 248
241 attron(COLOR_PAIR(3) | A_BOLD); 249 attron(COLOR_PAIR(4) | A_BOLD);
242 printw(" TOXIC 1.0 |"); 250 printw(" TOXIC 1.0 |");
243 attroff(COLOR_PAIR(3) | A_BOLD); 251 attroff(COLOR_PAIR(4) | A_BOLD);
244 252
245 for(i=0; i<w_num; i++) { 253 for(i=0; i<w_num; i++) {
246 if(i == w_active) { 254 if(i == w_active) {
247 attron(A_BOLD); 255 attron(A_BOLD);
248 } 256 }
249 257
258 odd = (odd+1) % 2;
259
260 if(windows[i].blink && odd) {
261 attron(COLOR_PAIR(3));
262 }
263
250 printw(" %s", windows[i].title); 264 printw(" %s", windows[i].title);
251 265
266 if(windows[i].blink && odd) {
267 attron(COLOR_PAIR(3));
268 }
269
252 if(i == w_active) { 270 if(i == w_active) {
253 attroff(A_BOLD); 271 attroff(A_BOLD);
254 } 272 }
@@ -278,6 +296,7 @@ int main(int argc, char* argv[]) {
278 // Draw. 296 // Draw.
279 a = &windows[w_active]; 297 a = &windows[w_active];
280 prepare_window(a->window); 298 prepare_window(a->window);
299 a->blink = false;
281 a->onDraw(a); 300 a->onDraw(a);
282 draw_bar(); 301 draw_bar();
283 302
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index 52e9bde0..cd9ef219 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -42,7 +42,7 @@ static int prompt_buf_pos=0;
42 42
43static void execute(ToxWindow* self, char* cmd) { 43static void execute(ToxWindow* self, char* cmd) {
44 44
45 if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit")) { 45 if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) {
46 endwin(); 46 endwin();
47 exit(0); 47 exit(0);
48 } 48 }
@@ -282,12 +282,11 @@ static void prompt_onDraw(ToxWindow* self) {
282 282
283static void print_usage(ToxWindow* self) { 283static void print_usage(ToxWindow* self) {
284 wattron(self->window, COLOR_PAIR(2) | A_BOLD); 284 wattron(self->window, COLOR_PAIR(2) | A_BOLD);
285 wprintw(self->window, "Usage:\n"); 285 wprintw(self->window, "Commands:\n");
286 wattroff(self->window, A_BOLD); 286 wattroff(self->window, A_BOLD);
287 287
288 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n"); 288 wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
289 wprintw(self->window, " add <id> <message> : Add friend\n"); 289 wprintw(self->window, " add <id> <message> : Add friend\n");
290 wprintw(self->window, " msg <number> <message> : Send message\n");
291 wprintw(self->window, " status <message> : Set your status\n"); 290 wprintw(self->window, " status <message> : Set your status\n");
292 wprintw(self->window, " nick <nickname> : Set your nickname\n"); 291 wprintw(self->window, " nick <nickname> : Set your nickname\n");
293 wprintw(self->window, " accept <number> : Accept friend request\n"); 292 wprintw(self->window, " accept <number> : Accept friend request\n");
@@ -296,7 +295,7 @@ static void print_usage(ToxWindow* self) {
296 295
297 296
298 wattron(self->window, A_BOLD); 297 wattron(self->window, A_BOLD);
299 wprintw(self->window, "Use the TAB key to navigate through the tabs.\n"); 298 wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n");
300 wattroff(self->window, A_BOLD); 299 wattroff(self->window, A_BOLD);
301 300
302 wattroff(self->window, COLOR_PAIR(2)); 301 wattroff(self->window, COLOR_PAIR(2));
diff --git a/testing/toxic/windows.h b/testing/toxic/windows.h
index 480fd658..dde1430f 100644
--- a/testing/toxic/windows.h
+++ b/testing/toxic/windows.h
@@ -1,3 +1,9 @@
1/*
2 * Toxic -- Tox Curses Client
3 */
4
5#include <stdbool.h>
6
1typedef struct ToxWindow_ ToxWindow; 7typedef struct ToxWindow_ ToxWindow;
2 8
3struct ToxWindow_ { 9struct ToxWindow_ {
@@ -11,6 +17,7 @@ struct ToxWindow_ {
11 char title[256]; 17 char title[256];
12 18
13 void* x; 19 void* x;
20 bool blink;
14 21
15 WINDOW* window; 22 WINDOW* window;
16}; 23};