diff --git a/src/api.c b/src/api.c index c7ecd36..233a510 100644 --- a/src/api.c +++ b/src/api.c @@ -103,9 +103,8 @@ void api_send(const char *msg) strncpy((char *) self_window->chatwin->line, msg, sizeof(self_window->chatwin->line)); add_line_to_hist(self_window->chatwin); - line_info_add(self_window, timefrmt, name, NULL, OUT_MSG, 0, 0, "%s", msg); - cqueue_add(self_window->chatwin->cqueue, msg, strlen(msg), OUT_MSG, - self_window->chatwin->hst->line_end->id + 1); + int id = line_info_add(self_window, timefrmt, name, NULL, OUT_MSG, 0, 0, "%s", msg); + cqueue_add(self_window->chatwin->cqueue, msg, strlen(msg), OUT_MSG, id); free(name); } diff --git a/src/autocomplete.c b/src/autocomplete.c index be66a33..ea8fb90 100644 --- a/src/autocomplete.c +++ b/src/autocomplete.c @@ -110,9 +110,9 @@ int complete_line(ToxWindow *self, const void *list, int n_items, int size) bool dir_search = !strncmp(ubuf, "/sendfile", strlen("/sendfile")) || !strncmp(ubuf, "/avatar", strlen("/avatar")); - #ifdef PYTHON +#ifdef PYTHON dir_search = dir_search || !strncmp(ubuf, "/run", strlen("/run")); - #endif +#endif /* isolate substring from space behind pos to pos */ char tmp[MAX_STR_SIZE]; diff --git a/src/chat.c b/src/chat.c index 73cc0bd..321fd90 100644 --- a/src/chat.c +++ b/src/chat.c @@ -895,8 +895,8 @@ static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action) char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); - line_info_add(self, timefrmt, selfname, NULL, OUT_ACTION, 0, 0, "%s", action); - cqueue_add(ctx->cqueue, action, strlen(action), OUT_ACTION, ctx->hst->line_end->id + 1); + int id = line_info_add(self, timefrmt, selfname, NULL, OUT_ACTION, 0, 0, "%s", action); + cqueue_add(ctx->cqueue, action, strlen(action), OUT_ACTION, id); } static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) @@ -947,6 +947,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) else if (wcsncmp(ctx->line, L"/run \"", wcslen(L"/run \"")) == 0) { diff = dir_match(self, m, ctx->line, L"/run"); } + #endif else if (wcsncmp(ctx->line, L"/status ", wcslen(L"/status ")) == 0) { @@ -1001,8 +1002,8 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); - line_info_add(self, timefrmt, selfname, NULL, OUT_MSG, 0, 0, "%s", line); - cqueue_add(ctx->cqueue, line, strlen(line), OUT_MSG, ctx->hst->line_end->id + 1); + int id = line_info_add(self, timefrmt, selfname, NULL, OUT_MSG, 0, 0, "%s", line); + cqueue_add(ctx->cqueue, line, strlen(line), OUT_MSG, id); } } diff --git a/src/execute.c b/src/execute.c index 607ad4d..c55fc80 100644 --- a/src/execute.c +++ b/src/execute.c @@ -198,8 +198,10 @@ void execute(WINDOW *w, ToxWindow *self, Tox *m, const char *input, int mode) return; #ifdef PYTHON + if (do_plugin_command(num_args, args) == 0) return; + #endif line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid command."); diff --git a/src/groupchat.c b/src/groupchat.c index c9119fc..8bd7c92 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -265,7 +265,8 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, uint32_t groupnum, write_to_log(msg, nick, ctx->log, false); } -static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, const char *title, +static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, + const char *title, size_t length) { ChatContext *ctx = self->chatwin; @@ -388,7 +389,7 @@ void *group_add_wait(void *data) } static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, - TOX_CONFERENCE_STATE_CHANGE change) + TOX_CONFERENCE_STATE_CHANGE change) { if (self->num != groupnum) return; @@ -559,6 +560,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) else if (wcsncmp(ctx->line, L"/run \"", wcslen(L"/run \"")) == 0) { diff = dir_match(self, m, ctx->line, L"/run"); } + #endif else { diff --git a/src/help.c b/src/help.c index 9110064..3023998 100644 --- a/src/help.c +++ b/src/help.c @@ -343,6 +343,7 @@ static void help_draw_contacts(ToxWindow *self) void help_onKey(ToxWindow *self, wint_t key) { int height; + switch (key) { case 'x': case T_KEY_ESC: @@ -380,6 +381,7 @@ void help_onKey(ToxWindow *self, wint_t key) break; #ifdef PYTHON + case 'p': help_init_window(self, 4 + num_registered_handlers(), help_max_width()); self->help->type = HELP_PLUGIN; @@ -433,6 +435,7 @@ void help_onDraw(ToxWindow *self) break; #ifdef PYTHON + case HELP_PLUGIN: help_draw_plugin(self); break; diff --git a/src/line_info.c b/src/line_info.c index c4103b1..fab27d0 100644 --- a/src/line_info.c +++ b/src/line_info.c @@ -129,17 +129,21 @@ static struct line_info *line_info_ret_queue(struct history *hst) return line; } -/* creates new line_info line and puts it in the queue. */ -void line_info_add(ToxWindow *self, const char *timestr, const char *name1, const char *name2, uint8_t type, - uint8_t bold, uint8_t colour, const char *msg, ...) +/* creates new line_info line and puts it in the queue. + * + * Returns the id of the new line. + * Returns -1 on failure. + */ +int line_info_add(ToxWindow *self, const char *timestr, const char *name1, const char *name2, uint8_t type, + uint8_t bold, uint8_t colour, const char *msg, ...) { if (!self) - return; + return -1; struct history *hst = self->chatwin->hst; if (hst->queue_sz >= MAX_LINE_INFO_QUEUE) - return; + return -1; struct line_info *new_line = calloc(1, sizeof(struct line_info)); @@ -222,6 +226,7 @@ void line_info_add(ToxWindow *self, const char *timestr, const char *name1, cons len += strlen(new_line->name2); } + new_line->id = hst->line_end->id + 1 + hst->queue_sz; new_line->len = len; new_line->type = type; new_line->bold = bold; @@ -230,6 +235,8 @@ void line_info_add(ToxWindow *self, const char *timestr, const char *name1, cons new_line->timestamp = get_unix_time(); hst->queue[hst->queue_sz++] = new_line; + + return new_line->id; } /* adds a single queue item to hst if possible. only called once per call to line_info_print() */ @@ -244,10 +251,10 @@ static void line_info_check_queue(ToxWindow *self) if (hst->start_id > user_settings->history_size) line_info_root_fwd(hst); - line->id = hst->line_end->id + 1; line->prev = hst->line_end; hst->line_end->next = line; hst->line_end = line; + hst->line_end->id = line->id; int y, y2, x, x2; getmaxyx(self->window, y2, x2); diff --git a/src/line_info.h b/src/line_info.h index 9eebaa1..985ba02 100644 --- a/src/line_info.h +++ b/src/line_info.h @@ -74,9 +74,13 @@ struct history { int queue_sz; }; -/* creates new line_info line and puts it in the queue. */ -void line_info_add(ToxWindow *self, const char *timestr, const char *name1, const char *name2, uint8_t type, - uint8_t bold, uint8_t colour, const char *msg, ...); +/* creates new line_info line and puts it in the queue. + * + * Returns the id of the new line. + * Returns -1 on failure. + */ +int line_info_add(ToxWindow *self, const char *timestr, const char *name1, const char *name2, uint8_t type, + uint8_t bold, uint8_t colour, const char *msg, ...); /* Prints a section of history starting at line_start */ void line_info_print(ToxWindow *self); diff --git a/src/message_queue.c b/src/message_queue.c index 881e512..7d11d58 100644 --- a/src/message_queue.c +++ b/src/message_queue.c @@ -42,8 +42,12 @@ void cqueue_cleanup(struct chat_queue *q) free(q); } -void cqueue_add(struct chat_queue *q, const char *msg, size_t len, uint8_t type, uint32_t line_id) +void cqueue_add(struct chat_queue *q, const char *msg, size_t len, uint8_t type, int line_id) { + if (line_id < 0) { + return; + } + struct cqueue_msg *new_m = malloc(sizeof(struct cqueue_msg)); if (new_m == NULL) diff --git a/src/message_queue.h b/src/message_queue.h index 6b41529..8cc353c 100644 --- a/src/message_queue.h +++ b/src/message_queue.h @@ -40,7 +40,7 @@ struct chat_queue { }; void cqueue_cleanup(struct chat_queue *q); -void cqueue_add(struct chat_queue *q, const char *msg, size_t len, uint8_t type, uint32_t line_id); +void cqueue_add(struct chat_queue *q, const char *msg, size_t len, uint8_t type, int line_id); /* Tries to send the oldest unsent message in queue. */ void cqueue_try_send(ToxWindow *self, Tox *m); diff --git a/src/prompt.c b/src/prompt.c index 66dd5da..c993a09 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -230,6 +230,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) #ifdef PYTHON else if (wcsncmp(ctx->line, L"/run \"", wcslen(L"/run \"")) == 0) diff = dir_match(self, m, ctx->line, L"/run"); + #endif else if (wcsncmp(ctx->line, L"/status ", wcslen(L"/status ")) == 0) { diff --git a/src/toxic.c b/src/toxic.c index d5f3ec1..6fe014d 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -114,6 +114,7 @@ static time_t last_signal_time; static void catch_SIGINT(int sig) { time_t cur_time = get_unix_time(); + if (difftime(cur_time, last_signal_time) <= 1) { Winthread.sig_exit_toxic = 1; } else { @@ -398,7 +399,7 @@ static void first_time_encrypt(const char *msg) do { system("clear"); printf("%s ", msg); - fflush(stdout); + fflush(stdout); if (!strcasecmp(ch, "y\n") || !strcasecmp(ch, "n\n") || !strcasecmp(ch, "yes\n") || !strcasecmp(ch, "no\n") || !strcasecmp(ch, "q\n")) @@ -419,7 +420,7 @@ static void first_time_encrypt(const char *msg) printf("Enter a new password (must be at least %d characters) ", MIN_PASSWORD_LEN); while (valid_password == false) { - fflush(stdout); // Flush all before user input + fflush(stdout); // Flush all before user input len = password_prompt(user_password.pass, sizeof(user_password.pass)); user_password.len = len; @@ -645,7 +646,8 @@ static Tox *load_tox(char *data_path, struct Tox_Options *tox_opts, TOX_ERR_NEW char plain[plain_len]; while (true) { - fflush(stdout); // Flush before prompts so the user sees the question/message + fflush(stdout); // Flush before prompts so the user sees the question/message + if (pweval) { pwlen = password_eval(user_password.pass, sizeof(user_password.pass)); } else { @@ -1021,6 +1023,7 @@ static void parse_args(int argc, char *argv[]) case 'v': print_version(); exit(EXIT_SUCCESS); + case 'h': default: print_usage();