summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/toxic/chat.c38
-rw-r--r--testing/toxic/main.c2
2 files changed, 29 insertions, 11 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index 112b20b7..da67567d 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -79,9 +79,9 @@ static void chat_onAction(ToxWindow *self, Messenger *m, int num, uint8_t *actio
79 wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); 79 wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
80 wattroff(ctx->history, COLOR_PAIR(2)); 80 wattroff(ctx->history, COLOR_PAIR(2));
81 81
82 wattron(ctx->history, COLOR_PAIR(4)); 82 wattron(ctx->history, COLOR_PAIR(5));
83 wprintw(ctx->history, "%s\n", action); 83 wprintw(ctx->history, "%s\n", action);
84 wattroff(ctx->history, COLOR_PAIR(4)); 84 wattroff(ctx->history, COLOR_PAIR(5));
85 85
86 self->blink = true; 86 self->blink = true;
87 beep(); 87 beep();
@@ -104,7 +104,18 @@ static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t
104 104
105static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint16_t len) 105static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint16_t len)
106{ 106{
107 ChatContext *ctx = (ChatContext*) self->x;
108 if (ctx->friendnum != num)
109 return;
110
111 status[len-1] = '\0';
112 fix_name(status);
113 snprintf(self->title, sizeof(self->title), "[%s (%d)]", status, num);
107 114
115 wattron(ctx->history, COLOR_PAIR(3));
116 wprintw(ctx->history, " * Your partner changed status to '%s'\n", status);
117 wattroff(ctx->history, COLOR_PAIR(3));
118
108} 119}
109 120
110/* check that the string has one non-space character */ 121/* check that the string has one non-space character */
@@ -157,20 +168,24 @@ static void chat_onKey(ToxWindow *self, Messenger *m, int key)
157 if (ctx->line[0] == '/') 168 if (ctx->line[0] == '/')
158 execute(self, ctx, m, ctx->line, timeinfo); 169 execute(self, ctx, m, ctx->line, timeinfo);
159 else { 170 else {
171 /* make sure the string has at least non-space character */
160 if (!string_is_empty(ctx->line)) { 172 if (!string_is_empty(ctx->line)) {
161 /* make sure the string has at least non-space character */ 173 uint8_t selfname[MAX_NAME_LENGTH];
174 getself_name(m, selfname);
175 fix_name(selfname);
176
162 wattron(ctx->history, COLOR_PAIR(2)); 177 wattron(ctx->history, COLOR_PAIR(2));
163 wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); 178 wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
164 wattroff(ctx->history, COLOR_PAIR(2)); 179 wattroff(ctx->history, COLOR_PAIR(2));
165 wattron(ctx->history, COLOR_PAIR(1)); 180 wattron(ctx->history, COLOR_PAIR(1));
166 wprintw(ctx->history, "you: ", ctx->line); 181 wprintw(ctx->history, "%s: ", selfname);
167 wattroff(ctx->history, COLOR_PAIR(1)); 182 wattroff(ctx->history, COLOR_PAIR(1));
168 wprintw(ctx->history, "%s\n", ctx->line); 183 wprintw(ctx->history, "%s\n", ctx->line);
169 } 184 if (m_sendmessage(m, ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) == 0) {
170 if (m_sendmessage(m, ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) == 0) { 185 wattron(ctx->history, COLOR_PAIR(3));
171 wattron(ctx->history, COLOR_PAIR(3)); 186 wprintw(ctx->history, " * Failed to send message.\n");
172 wprintw(ctx->history, " * Failed to send message.\n"); 187 wattroff(ctx->history, COLOR_PAIR(3));
173 wattroff(ctx->history, COLOR_PAIR(3)); 188 }
174 } 189 }
175 } 190 }
176 ctx->line[0] = '\0'; 191 ctx->line[0] = '\0';
@@ -214,9 +229,9 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct
214 char msg[MAX_STR_SIZE-len-4]; 229 char msg[MAX_STR_SIZE-len-4];
215 snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action); 230 snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action);
216 231
217 wattron(ctx->history, COLOR_PAIR(1)); 232 wattron(ctx->history, COLOR_PAIR(5));
218 wprintw(ctx->history, msg); 233 wprintw(ctx->history, msg);
219 wattroff(ctx->history, COLOR_PAIR(1)); 234 wattroff(ctx->history, COLOR_PAIR(5));
220 if (m_sendaction(m, ctx->friendnum, (uint8_t*) msg, strlen(msg)+1) < 0) { 235 if (m_sendaction(m, ctx->friendnum, (uint8_t*) msg, strlen(msg)+1) < 0) {
221 wattron(ctx->history, COLOR_PAIR(3)); 236 wattron(ctx->history, COLOR_PAIR(3));
222 wprintw(ctx->history, " * Failed to send action\n"); 237 wprintw(ctx->history, " * Failed to send action\n");
@@ -274,6 +289,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct
274 wprintw(ctx->history, "Invalid syntax.\n"); 289 wprintw(ctx->history, "Invalid syntax.\n");
275 return; 290 return;
276 } 291 }
292
277 nick++; 293 nick++;
278 setname(m, (uint8_t*) nick, strlen(nick)+1); 294 setname(m, (uint8_t*) nick, strlen(nick)+1);
279 wprintw(ctx->history, "Nickname set to: %s\n", nick); 295 wprintw(ctx->history, "Nickname set to: %s\n", nick);
diff --git a/testing/toxic/main.c b/testing/toxic/main.c
index 397f9391..c5c881fd 100644
--- a/testing/toxic/main.c
+++ b/testing/toxic/main.c
@@ -124,6 +124,7 @@ static void init_term()
124 init_pair(2, COLOR_CYAN, COLOR_BLACK); 124 init_pair(2, COLOR_CYAN, COLOR_BLACK);
125 init_pair(3, COLOR_RED, COLOR_BLACK); 125 init_pair(3, COLOR_RED, COLOR_BLACK);
126 init_pair(4, COLOR_BLUE, COLOR_BLACK); 126 init_pair(4, COLOR_BLUE, COLOR_BLACK);
127 init_pair(5, COLOR_YELLOW, COLOR_BLACK);
127 } 128 }
128 refresh(); 129 refresh();
129} 130}
@@ -139,6 +140,7 @@ static void init_tox()
139 m_callback_namechange(m, on_nickchange, NULL); 140 m_callback_namechange(m, on_nickchange, NULL);
140 m_callback_statusmessage(m, on_statuschange, NULL); 141 m_callback_statusmessage(m, on_statuschange, NULL);
141 m_callback_action(m, on_action, NULL); 142 m_callback_action(m, on_action, NULL);
143 setname(m, (uint8_t*) "n00b", strlen("n00b")+1);
142} 144}
143 145
144#define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ 146#define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */