mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:13: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:
parent
c4c0c0d1f4
commit
8d9d51640c
@ -109,7 +109,7 @@ static int complete_line_helper(ToxWindow *self, const char **list, const size_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *endchrs = " ";
|
const char *endchrs = " ";
|
||||||
char ubuf[MAX_STR_SIZE] = {0};
|
char ubuf[MAX_STR_SIZE];
|
||||||
|
|
||||||
/* work with multibyte string copy of buf for simplicity */
|
/* work with multibyte string copy of buf for simplicity */
|
||||||
if (wcs_to_mbs_buf(ubuf, ctx->line, sizeof(ubuf)) == -1) {
|
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 */
|
/* isolate substring from space behind pos to pos */
|
||||||
char tmp[MAX_STR_SIZE];
|
char tmp[MAX_STR_SIZE];
|
||||||
snprintf(tmp, sizeof(tmp), "%s", ubuf);
|
memcpy(tmp, ubuf, ctx->pos);
|
||||||
tmp[ctx->pos] = '\0';
|
tmp[ctx->pos] = 0;
|
||||||
|
|
||||||
const char *s = dir_search ? strchr(tmp, ' ') : strrchr(tmp, ' ');
|
const char *s = dir_search ? strchr(tmp, ' ') : strrchr(tmp, ' ');
|
||||||
char *sub = calloc(1, strlen(ubuf) + 1);
|
char *sub = calloc(1, strlen(ubuf) + 1);
|
||||||
|
@ -242,11 +242,7 @@ static void print_wrap(WINDOW *win, struct line_info *line, int max_x)
|
|||||||
print_n_chars(win, msg, space_idx);
|
print_n_chars(win, msg, space_idx);
|
||||||
msg += space_idx + 1;
|
msg += space_idx + 1;
|
||||||
length -= (space_idx + 1);
|
length -= (space_idx + 1);
|
||||||
|
waddch(win, '\n');
|
||||||
// replace last space on current line with newline if we intend to split it
|
|
||||||
if (win && length >= x_limit - space_idx) {
|
|
||||||
waddch(win, '\n');
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
print_n_chars(win, msg, x_limit);
|
print_n_chars(win, msg, x_limit);
|
||||||
msg += x_limit;
|
msg += x_limit;
|
||||||
@ -263,6 +259,22 @@ static void print_wrap(WINDOW *win, struct line_info *line, int max_x)
|
|||||||
++lines;
|
++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;
|
line->format_lines = lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,14 +534,9 @@ void line_info_print(ToxWindow *self)
|
|||||||
wattroff(win, COLOR_PAIR(RED));
|
wattroff(win, COLOR_PAIR(RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == OUT_MSG && timed_out(line->timestamp, NOREAD_FLAG_TIMEOUT)) {
|
if (type == OUT_MSG && !line->read_flag) {
|
||||||
wattron(win, COLOR_PAIR(RED));
|
if (timed_out(line->timestamp, NOREAD_FLAG_TIMEOUT)) {
|
||||||
wprintw(win, " x");
|
|
||||||
wattroff(win, COLOR_PAIR(RED));
|
|
||||||
|
|
||||||
if (line->noread_flag == false) {
|
|
||||||
line->noread_flag = true;
|
line->noread_flag = true;
|
||||||
line->len += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,15 +559,9 @@ void line_info_print(ToxWindow *self)
|
|||||||
print_wrap(win, line, max_x);
|
print_wrap(win, line, max_x);
|
||||||
wattroff(win, COLOR_PAIR(YELLOW));
|
wattroff(win, COLOR_PAIR(YELLOW));
|
||||||
|
|
||||||
if (type == OUT_ACTION && timed_out(line->timestamp, NOREAD_FLAG_TIMEOUT)) {
|
if (type == OUT_ACTION && !line->read_flag) {
|
||||||
wattron(win, COLOR_PAIR(RED));
|
if (timed_out(line->timestamp, NOREAD_FLAG_TIMEOUT)) {
|
||||||
wprintw(win, " x");
|
|
||||||
wattroff(win, COLOR_PAIR(RED));
|
|
||||||
|
|
||||||
if (line->noread_flag == false) {
|
|
||||||
line->noread_flag = true;
|
line->noread_flag = true;
|
||||||
line->len += 2;
|
|
||||||
line->msg_len += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,8 @@ struct line_info {
|
|||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t bold;
|
uint8_t bold;
|
||||||
uint8_t colour;
|
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;
|
uint32_t id;
|
||||||
uint16_t len; /* combined length of entire line */
|
uint16_t len; /* combined length of entire line */
|
||||||
uint16_t msg_len; /* length of the message */
|
uint16_t msg_len; /* length of the message */
|
||||||
|
@ -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;
|
line->type = msg->type == OUT_ACTION ? OUT_ACTION_READ : OUT_MSG_READ;
|
||||||
|
|
||||||
if (line->noread_flag == true) {
|
if (line->noread_flag) {
|
||||||
line->len -= 2;
|
|
||||||
line->noread_flag = false;
|
line->noread_flag = false;
|
||||||
|
line->read_flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user