mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:53:05 +01:00
add prompt logging support
This commit is contained in:
parent
7109b8fa18
commit
7f38c3c6e7
@ -681,7 +681,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
memset(ctx->log, 0, sizeof(struct chatlog));
|
||||
|
||||
if (friends[self->num].logging_on)
|
||||
log_enable(ctx->log, self->name, friends[self->num].pub_key);
|
||||
log_enable(self->name, friends[self->num].pub_key, ctx->log);
|
||||
|
||||
wprintw(ctx->history, "\n\n");
|
||||
execute(ctx->history, self, m, "/help", CHAT_COMMAND_MODE);
|
||||
|
@ -222,22 +222,22 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
|
||||
|
||||
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (!self->is_chat && !self->is_groupchat) { /* remove if prompt logging gets implemented */
|
||||
wprintw(window, "Invalid command.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (argc == 0) {
|
||||
if (ctx->log->log_on) {
|
||||
wprintw(window, "Logging for this chat is ");
|
||||
bool on;
|
||||
|
||||
if (self->is_chat || self->is_groupchat)
|
||||
on = self->chatwin->log->log_on;
|
||||
else if (self->is_prompt)
|
||||
on = self->promptbuf->log->log_on;
|
||||
|
||||
if (on) {
|
||||
wprintw(window, "Logging for this window is ");
|
||||
wattron(window, COLOR_PAIR(GREEN) | A_BOLD);
|
||||
wprintw(window, "[on]");
|
||||
wattroff(window, COLOR_PAIR(GREEN) | A_BOLD);
|
||||
wprintw(window, ". Type \"/log off\" to disable.\n");
|
||||
} else {
|
||||
wprintw(window, "Logging for this chat is ");
|
||||
wprintw(window, "Logging for this window is ");
|
||||
wattron(window, COLOR_PAIR(RED) | A_BOLD);
|
||||
wprintw(window, "[off]");
|
||||
wattroff(window, COLOR_PAIR(RED) | A_BOLD);
|
||||
@ -248,26 +248,34 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
}
|
||||
|
||||
uint8_t *swch = argv[1];
|
||||
uint8_t *ident = NULL;
|
||||
|
||||
if (!strcmp(swch, "1") || !strcmp(swch, "on")) {
|
||||
|
||||
if (self->is_chat) {
|
||||
friends[self->num].logging_on = true;
|
||||
ident = friends[self->num].pub_key;
|
||||
log_enable(self->name, friends[self->num].pub_key, self->chatwin->log);
|
||||
} else if (self->is_prompt) {
|
||||
uint8_t myid[TOX_FRIEND_ADDRESS_SIZE];
|
||||
tox_get_address(m, myid);
|
||||
log_enable(self->name, &myid, self->promptbuf->log);
|
||||
} else if (self->is_groupchat) {
|
||||
log_enable(self->name, NULL, self->chatwin->log);
|
||||
}
|
||||
|
||||
log_enable(ctx->log, self->name, ident);
|
||||
|
||||
wprintw(window, "Logging ");
|
||||
wattron(window, COLOR_PAIR(GREEN) | A_BOLD);
|
||||
wprintw(window, "[on]\n");
|
||||
wattroff(window, COLOR_PAIR(GREEN) | A_BOLD);
|
||||
return;
|
||||
} else if (!strcmp(swch, "0") || !strcmp(swch, "off")) {
|
||||
if (self->is_chat)
|
||||
if (self->is_chat) {
|
||||
friends[self->num].logging_on = false;
|
||||
|
||||
log_disable(ctx->log);
|
||||
log_disable(self->chatwin->log);
|
||||
} else if (self->is_prompt) {
|
||||
log_disable(self->promptbuf->log);
|
||||
} else if (self->is_groupchat) {
|
||||
log_disable(self->chatwin->log);
|
||||
}
|
||||
|
||||
wprintw(window, "Logging ");
|
||||
wattron(window, COLOR_PAIR(RED) | A_BOLD);
|
||||
@ -363,6 +371,7 @@ void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
|
||||
wprintw(window, " /status <type> <msg> : Set status with optional note\n");
|
||||
wprintw(window, " /note <msg> : Set a personal note\n");
|
||||
wprintw(window, " /nick <nick> : Set your nickname\n");
|
||||
wprintw(window, " /log <on> or <off> : Enable/disable logging\n");
|
||||
wprintw(window, " /groupchat : Create a group chat\n");
|
||||
wprintw(window, " /myid : Print your ID\n");
|
||||
wprintw(window, " /help : Print this message again\n");
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* log->c
|
||||
/* log.c
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2014 Toxic All Rights Reserved.
|
||||
@ -121,7 +121,7 @@ void add_to_log_buf(uint8_t *msg, uint8_t *name, struct chatlog *log, bool event
|
||||
write_to_log(log);
|
||||
}
|
||||
|
||||
void log_enable(struct chatlog *log, uint8_t *name, uint8_t *key)
|
||||
void log_enable(uint8_t *name, uint8_t *key, struct chatlog *log)
|
||||
{
|
||||
log->log_on = true;
|
||||
|
||||
|
@ -31,5 +31,5 @@ void add_to_log_buf(uint8_t *msg, uint8_t *name, struct chatlog *log, bool event
|
||||
This is triggered automatically when the log buffer is full, but may be forced. */
|
||||
void write_to_log(struct chatlog *log);
|
||||
|
||||
void log_enable(struct chatlog *log, uint8_t *name, uint8_t *key);
|
||||
void log_disable(struct chatlog *log);
|
||||
void log_enable(uint8_t *name, uint8_t *key, struct chatlog *log);
|
||||
void log_disable(struct chatlog *log);
|
||||
|
@ -479,6 +479,8 @@ void exit_toxic(Tox *m)
|
||||
free(DATA_FILE);
|
||||
free(SRVLIST_FILE);
|
||||
free(prompt->stb);
|
||||
log_disable(prompt->promptbuf->log);
|
||||
free(prompt->promptbuf->log);
|
||||
free(prompt->promptbuf);
|
||||
tox_kill(m);
|
||||
endwin();
|
||||
|
38
src/prompt.c
38
src/prompt.c
@ -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;
|
||||
|
@ -114,6 +114,7 @@ struct ToxWindow {
|
||||
/* window type identifiers */
|
||||
bool is_chat;
|
||||
bool is_groupchat;
|
||||
bool is_prompt;
|
||||
|
||||
bool alert0;
|
||||
bool alert1;
|
||||
@ -182,6 +183,7 @@ struct PromptBuf {
|
||||
int hst_pos;
|
||||
int hst_tot;
|
||||
|
||||
struct chatlog *log;
|
||||
WINDOW *linewin;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user