1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-14 05:43:02 +01:00

Fix display bug caused by noread flag appended to unread messages

A line's line count now increments without messing up the formatting in cases where
the noread flag wraps to the next line.

Additionally, the way noread flags are handled has been refactored and made
more efficient.
This commit is contained in:
jfreegman 2020-11-25 13:27:47 -05:00
parent c4c0c0d1f4
commit 8d9d51640c
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
4 changed files with 28 additions and 26 deletions

View File

@ -109,7 +109,7 @@ static int complete_line_helper(ToxWindow *self, const char **list, const size_t
}
const char *endchrs = " ";
char ubuf[MAX_STR_SIZE] = {0};
char ubuf[MAX_STR_SIZE];
/* work with multibyte string copy of buf for simplicity */
if (wcs_to_mbs_buf(ubuf, ctx->line, sizeof(ubuf)) == -1) {
@ -118,8 +118,8 @@ static int complete_line_helper(ToxWindow *self, const char **list, const size_t
/* isolate substring from space behind pos to pos */
char tmp[MAX_STR_SIZE];
snprintf(tmp, sizeof(tmp), "%s", ubuf);
tmp[ctx->pos] = '\0';
memcpy(tmp, ubuf, ctx->pos);
tmp[ctx->pos] = 0;
const char *s = dir_search ? strchr(tmp, ' ') : strrchr(tmp, ' ');
char *sub = calloc(1, strlen(ubuf) + 1);

View File

@ -242,11 +242,7 @@ static void print_wrap(WINDOW *win, struct line_info *line, int max_x)
print_n_chars(win, msg, space_idx);
msg += space_idx + 1;
length -= (space_idx + 1);
// replace last space on current line with newline if we intend to split it
if (win && length >= x_limit - space_idx) {
waddch(win, '\n');
}
waddch(win, '\n');
} else {
print_n_chars(win, msg, x_limit);
msg += x_limit;
@ -263,6 +259,22 @@ static void print_wrap(WINDOW *win, struct line_info *line, int max_x)
++lines;
}
if (win && line->noread_flag) {
int x;
int y;
UNUSED_VAR(y);
getyx(win, y, x);
if (x >= max_x - 1 || x == x_start) {
++lines;
}
wattron(win, COLOR_PAIR(RED));
wprintw(win, " x");
wattroff(win, COLOR_PAIR(RED));
}
line->format_lines = lines;
}
@ -522,14 +534,9 @@ void line_info_print(ToxWindow *self)
wattroff(win, COLOR_PAIR(RED));
}
if (type == OUT_MSG && timed_out(line->timestamp, NOREAD_FLAG_TIMEOUT)) {
wattron(win, COLOR_PAIR(RED));
wprintw(win, " x");
wattroff(win, COLOR_PAIR(RED));
if (line->noread_flag == false) {
if (type == OUT_MSG && !line->read_flag) {
if (timed_out(line->timestamp, NOREAD_FLAG_TIMEOUT)) {
line->noread_flag = true;
line->len += 2;
}
}
@ -552,15 +559,9 @@ void line_info_print(ToxWindow *self)
print_wrap(win, line, max_x);
wattroff(win, COLOR_PAIR(YELLOW));
if (type == OUT_ACTION && timed_out(line->timestamp, NOREAD_FLAG_TIMEOUT)) {
wattron(win, COLOR_PAIR(RED));
wprintw(win, " x");
wattroff(win, COLOR_PAIR(RED));
if (line->noread_flag == false) {
if (type == OUT_ACTION && !line->read_flag) {
if (timed_out(line->timestamp, NOREAD_FLAG_TIMEOUT)) {
line->noread_flag = true;
line->len += 2;
line->msg_len += 2;
}
}

View File

@ -54,7 +54,8 @@ struct line_info {
uint8_t type;
uint8_t bold;
uint8_t colour;
uint8_t noread_flag; /* true if a line should be flagged as unread */
bool noread_flag; /* true if a line should be flagged as unread */
bool read_flag; /* true if a message has been flagged as read */
uint32_t id;
uint16_t len; /* combined length of entire line */
uint16_t msg_len; /* length of the message */

View File

@ -86,9 +86,9 @@ static void cqueue_mark_read(ToxWindow *self, struct cqueue_msg *msg)
line->type = msg->type == OUT_ACTION ? OUT_ACTION_READ : OUT_MSG_READ;
if (line->noread_flag == true) {
line->len -= 2;
if (line->noread_flag) {
line->noread_flag = false;
line->read_flag = true;
}
return;