mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-14 05:23:01 +01:00
Fix UI bugs & format
This fixes a bug where lines would sometimes be incorrectly marked as unread, as well as a bug where inbound messages would sometimes be coloured incorrectly
This commit is contained in:
parent
c4ace288af
commit
0136f22076
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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];
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.");
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user