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

add prompt logging support

This commit is contained in:
Jfreegman
2014-03-01 18:06:35 -05:00
parent 7109b8fa18
commit 7f38c3c6e7
7 changed files with 68 additions and 27 deletions

View File

@ -360,6 +360,18 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
static void prompt_onInit(ToxWindow *self, Tox *m)
{
scrollok(self->window, true);
PromptBuf *prt = self->promptbuf;
prt->log = malloc(sizeof(struct chatlog));
if (prt->log == NULL) {
endwin();
fprintf(stderr, "malloc() failed. Aborting...\n");
exit(EXIT_FAILURE);
}
memset(prt->log, 0, sizeof(struct chatlog));
execute(self->window, self, m, "/help", GLOBAL_COMMAND_MODE);
wclrtoeol(self->window);
}
@ -369,6 +381,7 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int friendnum , u
if (friendnum < 0)
return;
PromptBuf *prt = self->promptbuf;
prep_prompt_win();
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
@ -382,22 +395,29 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int friendnum , u
wprintw(self->window, "\n");
print_time(self->window);
uint8_t *msg;
if (status == 1) {
msg = "has come online\n";
wattron(self->window, COLOR_PAIR(GREEN));
wattron(self->window, A_BOLD);
wprintw(self->window, "* %s ", nick);
wattroff(self->window, A_BOLD);
wprintw(self->window, "has come online\n");
wprintw(self->window, "%s", msg);
wattroff(self->window, COLOR_PAIR(GREEN));
add_to_log_buf(msg, nick, prt->log, true);
alert_window(self, WINDOW_ALERT_2, false);
} else {
msg = "has gone offline\n";
wattron(self->window, COLOR_PAIR(RED));
wattron(self->window, A_BOLD);
wprintw(self->window, "* %s ", nick);
wattroff(self->window, A_BOLD);
wprintw(self->window, "has gone offline\n");
wprintw(self->window, "%s", msg);
wattroff(self->window, COLOR_PAIR(RED));
add_to_log_buf(msg, nick, prt->log, true);
}
}
@ -405,16 +425,23 @@ static void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data,
{
// make sure message data is null-terminated
data[length - 1] = 0;
PromptBuf *prt = self->promptbuf;
prep_prompt_win();
wprintw(self->window, "\n");
print_time(self->window);
wprintw(self->window, "Friend request with the message: '%s'\n", data);
uint8_t msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Friend request with the message '%s'\n", data);
wprintw(self->window, "%s", msg);
add_to_log_buf(msg, "", prt->log, true);
int n = add_friend_request(key);
if (n == -1) {
wprintw(self->window, "Friend request queue is full. Discarding request.\n");
uint8_t *errmsg = "Friend request queue is full. Discarding request.\n";
wprintw(self->window, "%s", errmsg);
add_to_log_buf(errmsg, "", prt->log, true);
return;
}
@ -460,6 +487,7 @@ ToxWindow new_prompt(void)
memset(&ret, 0, sizeof(ret));
ret.active = true;
ret.is_prompt = true;
ret.onKey = &prompt_onKey;
ret.onDraw = &prompt_onDraw;