Make color render more robust
This commit is contained in:
parent
380a8deb31
commit
74597b6361
2 changed files with 22 additions and 10 deletions
|
@ -108,7 +108,6 @@ void *receive_worker(void *arg)
|
||||||
nonce, shared_key) != 0) {
|
nonce, shared_key) != 0) {
|
||||||
free(decrypted);
|
free(decrypted);
|
||||||
error(0, "Cannot decrypt data");
|
error(0, "Cannot decrypt data");
|
||||||
return NULL;
|
|
||||||
} else {
|
} else {
|
||||||
/* Terminate decrypted data so we don't print random bytes */
|
/* Terminate decrypted data so we don't print random bytes */
|
||||||
decrypted[data_len] = '\0';
|
decrypted[data_len] = '\0';
|
||||||
|
|
|
@ -173,10 +173,8 @@ void highlight_current_line()
|
||||||
long range = users->length;
|
long range = users->length;
|
||||||
/* not highlight if no files in directory */
|
/* not highlight if no files in directory */
|
||||||
if (range == 0 && errno == 0) {
|
if (range == 0 && errno == 0) {
|
||||||
#if DRAW_PREVIEW
|
|
||||||
wprintw(chat_content, "No users. Start a converstation.");
|
wprintw(chat_content, "No users. Start a converstation.");
|
||||||
wrefresh(chat_content);
|
wrefresh(chat_content);
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,6 +276,7 @@ void print_message(int flag, message_t *msg, int user_color)
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int n = strlen(msg->content);
|
int n = strlen(msg->content);
|
||||||
int in_bold = 0, in_italic = 0, in_underline = 0, in_block = 0;
|
int in_bold = 0, in_italic = 0, in_underline = 0, in_block = 0;
|
||||||
|
int last_active_color = -1;
|
||||||
|
|
||||||
while (i < n) {
|
while (i < n) {
|
||||||
/* Bold */
|
/* Bold */
|
||||||
|
@ -382,11 +381,22 @@ void print_message(int flag, message_t *msg, int user_color)
|
||||||
/* Handle color codes \1 to \8 */
|
/* Handle color codes \1 to \8 */
|
||||||
if (msg->content[i] >= '1' && msg->content[i] <= '8') {
|
if (msg->content[i] >= '1' && msg->content[i] <= '8') {
|
||||||
/* Convert char to int */
|
/* Convert char to int */
|
||||||
int color_pair = msg->content[i] - '0';
|
int new_color = msg->content[i] - '0';
|
||||||
wattron(chat_content, COLOR_PAIR(color_pair));
|
if (new_color == last_active_color) {
|
||||||
/* Skip the color code character */
|
/* Turn off current color */
|
||||||
|
wattroff(chat_content, COLOR_PAIR(last_active_color));
|
||||||
|
/* Reset last active color */
|
||||||
|
last_active_color = -1;
|
||||||
|
} else {
|
||||||
|
if (last_active_color != -1) {
|
||||||
|
/* Turn off previous color */
|
||||||
|
wattroff(chat_content, COLOR_PAIR(last_active_color));
|
||||||
|
}
|
||||||
|
last_active_color = new_color;
|
||||||
|
/* Turn on new color */
|
||||||
|
wattron(chat_content, COLOR_PAIR(new_color));
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
/* Handle new line */
|
/* Handle new line */
|
||||||
} else if (msg->content[i] == 'n') {
|
} else if (msg->content[i] == 'n') {
|
||||||
waddch(chat_content, '\n');
|
waddch(chat_content, '\n');
|
||||||
|
@ -410,6 +420,9 @@ void print_message(int flag, message_t *msg, int user_color)
|
||||||
wattroff(chat_content, A_ITALIC);
|
wattroff(chat_content, A_ITALIC);
|
||||||
wattroff(chat_content, A_UNDERLINE);
|
wattroff(chat_content, A_UNDERLINE);
|
||||||
wattroff(chat_content, A_STANDOUT);
|
wattroff(chat_content, A_STANDOUT);
|
||||||
|
for (int i = 1; i < 8; i++) {
|
||||||
|
wattroff(chat_content, COLOR_PAIR(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue