1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-06 04:07:55 +02:00

minor improvements and bug fixes

This commit is contained in:
Jfreegman 2013-08-12 19:50:50 -04:00
parent b2f4e266d3
commit 24083b3082
2 changed files with 29 additions and 11 deletions

38
chat.c
View File

@ -79,9 +79,9 @@ static void chat_onAction(ToxWindow *self, Messenger *m, int num, uint8_t *actio
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2)); wattroff(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(4)); wattron(ctx->history, COLOR_PAIR(5));
wprintw(ctx->history, "%s\n", action); wprintw(ctx->history, "%s\n", action);
wattroff(ctx->history, COLOR_PAIR(4)); wattroff(ctx->history, COLOR_PAIR(5));
self->blink = true; self->blink = true;
beep(); beep();
@ -104,7 +104,18 @@ static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t
static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint16_t len) static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint16_t len)
{ {
ChatContext *ctx = (ChatContext*) self->x;
if (ctx->friendnum != num)
return;
status[len-1] = '\0';
fix_name(status);
snprintf(self->title, sizeof(self->title), "[%s (%d)]", status, num);
wattron(ctx->history, COLOR_PAIR(3));
wprintw(ctx->history, " * Your partner changed status to '%s'\n", status);
wattroff(ctx->history, COLOR_PAIR(3));
} }
/* check that the string has one non-space character */ /* check that the string has one non-space character */
@ -157,20 +168,24 @@ static void chat_onKey(ToxWindow *self, Messenger *m, int key)
if (ctx->line[0] == '/') if (ctx->line[0] == '/')
execute(self, ctx, m, ctx->line, timeinfo); execute(self, ctx, m, ctx->line, timeinfo);
else { else {
/* make sure the string has at least non-space character */
if (!string_is_empty(ctx->line)) { if (!string_is_empty(ctx->line)) {
/* make sure the string has at least non-space character */ uint8_t selfname[MAX_NAME_LENGTH];
getself_name(m, selfname);
fix_name(selfname);
wattron(ctx->history, COLOR_PAIR(2)); wattron(ctx->history, COLOR_PAIR(2));
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2)); wattroff(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(1)); wattron(ctx->history, COLOR_PAIR(1));
wprintw(ctx->history, "you: ", ctx->line); wprintw(ctx->history, "%s: ", selfname);
wattroff(ctx->history, COLOR_PAIR(1)); wattroff(ctx->history, COLOR_PAIR(1));
wprintw(ctx->history, "%s\n", ctx->line); wprintw(ctx->history, "%s\n", ctx->line);
} if (m_sendmessage(m, ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) == 0) {
if (m_sendmessage(m, ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) == 0) { wattron(ctx->history, COLOR_PAIR(3));
wattron(ctx->history, COLOR_PAIR(3)); wprintw(ctx->history, " * Failed to send message.\n");
wprintw(ctx->history, " * Failed to send message.\n"); wattroff(ctx->history, COLOR_PAIR(3));
wattroff(ctx->history, COLOR_PAIR(3)); }
} }
} }
ctx->line[0] = '\0'; ctx->line[0] = '\0';
@ -214,9 +229,9 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct
char msg[MAX_STR_SIZE-len-4]; char msg[MAX_STR_SIZE-len-4];
snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action); snprintf(msg, sizeof(msg), "* %s %s\n", (uint8_t*) selfname, action);
wattron(ctx->history, COLOR_PAIR(1)); wattron(ctx->history, COLOR_PAIR(5));
wprintw(ctx->history, msg); wprintw(ctx->history, msg);
wattroff(ctx->history, COLOR_PAIR(1)); wattroff(ctx->history, COLOR_PAIR(5));
if (m_sendaction(m, ctx->friendnum, (uint8_t*) msg, strlen(msg)+1) < 0) { if (m_sendaction(m, ctx->friendnum, (uint8_t*) msg, strlen(msg)+1) < 0) {
wattron(ctx->history, COLOR_PAIR(3)); wattron(ctx->history, COLOR_PAIR(3));
wprintw(ctx->history, " * Failed to send action\n"); wprintw(ctx->history, " * Failed to send action\n");
@ -274,6 +289,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct
wprintw(ctx->history, "Invalid syntax.\n"); wprintw(ctx->history, "Invalid syntax.\n");
return; return;
} }
nick++; nick++;
setname(m, (uint8_t*) nick, strlen(nick)+1); setname(m, (uint8_t*) nick, strlen(nick)+1);
wprintw(ctx->history, "Nickname set to: %s\n", nick); wprintw(ctx->history, "Nickname set to: %s\n", nick);

2
main.c
View File

@ -124,6 +124,7 @@ static void init_term()
init_pair(2, COLOR_CYAN, COLOR_BLACK); init_pair(2, COLOR_CYAN, COLOR_BLACK);
init_pair(3, COLOR_RED, COLOR_BLACK); init_pair(3, COLOR_RED, COLOR_BLACK);
init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK);
init_pair(5, COLOR_YELLOW, COLOR_BLACK);
} }
refresh(); refresh();
} }
@ -139,6 +140,7 @@ static void init_tox()
m_callback_namechange(m, on_nickchange, NULL); m_callback_namechange(m, on_nickchange, NULL);
m_callback_statusmessage(m, on_statuschange, NULL); m_callback_statusmessage(m, on_statuschange, NULL);
m_callback_action(m, on_action, NULL); m_callback_action(m, on_action, NULL);
setname(m, (uint8_t*) "n00b", strlen("n00b")+1);
} }
#define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */ #define MAXLINE 90 /* Approx max number of chars in a sever line (IP + port + key) */