diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-05-28 14:34:38 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-05-29 17:10:25 +0200 |
commit | 96f41ce4bfdbd57aee7103479faff54d7093e087 (patch) | |
tree | b81e39aecfd0a6c727cfcd99257f9035f68c3d38 /src | |
parent | f1a826a1169a1b6a4d3d33aa280aaf117dd182a3 (diff) | |
download | weechat-96f41ce4bfdbd57aee7103479faff54d7093e087.zip |
core: fix chat colors at certain positions not being applied
The new rendering of multiline lines had some issues with colors at
certain positions not being applied. The color would not be applied if
the color code was at either of these positions:
- At the start of a line after a newline character
- At the end of a line after a space and before a newline character
- At a line by itself before a newline character
The way I had done it by considering newline characters as a word in
gui_chat_get_word_info with a variable specifying that it's newline
characters became messy and didn't really make sense, so rather than
doing this, I changed gui_chat_get_word_info to stop before the first
newline character. That way, we can just check if we are at a newline
character at the start of the loop, and don't need any more special
handling.
Fixes #1928
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/curses/gui-curses-chat.c | 106 | ||||
-rw-r--r-- | src/gui/gui-chat.c | 18 | ||||
-rw-r--r-- | src/gui/gui-chat.h | 3 |
3 files changed, 59 insertions, 68 deletions
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index 915009d67..b4fa4cc92 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -1385,7 +1385,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, int num_lines, x, y, pre_lines_displayed, lines_displayed, line_align; int read_marker_x, read_marker_y; int word_start_offset, word_end_offset; - int word_length_with_spaces, word_length, word_is_newlines; + int word_length_with_spaces, word_length; char *message_with_tags, *message_with_search; const char *ptr_data, *ptr_end_offset, *ptr_style, *next_char; struct t_gui_line *ptr_prev_line, *ptr_next_line; @@ -1521,11 +1521,24 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, { while (ptr_data && ptr_data[0]) { + if (ptr_data[0] == '\n') + { + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + ptr_data++; + gui_chat_display_prefix_suffix(window, line, + ptr_data, + pre_lines_displayed, &lines_displayed, + simulate, + CONFIG_BOOLEAN(config_look_color_inactive_message), + 0); + } + gui_chat_get_word_info (window, ptr_data, &word_start_offset, &word_end_offset, - &word_length_with_spaces, &word_length, &word_is_newlines); + &word_length_with_spaces, &word_length); ptr_end_offset = ptr_data + word_end_offset; @@ -1538,69 +1551,44 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, if (word_length >= 0) { - if (word_is_newlines) + line_align = gui_line_get_align (window->buffer, line, 1, + (lines_displayed == 0) ? 1 : 0); + if ((window->win_chat_cursor_x + word_length_with_spaces > gui_chat_get_real_width (window)) + && (word_length <= gui_chat_get_real_width (window) - line_align)) { - /* jump to start of word */ - ptr_data += word_start_offset; - - while (ptr_data && ptr_data[0] == '\n') + /* spaces + word too long for current line but OK for next line */ + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + /* apply styles before jumping to start of word */ + if (!simulate && (word_start_offset > 0)) { - gui_chat_display_new_line (window, num_lines, count, - &lines_displayed, simulate); - ptr_data++; - gui_chat_display_prefix_suffix(window, line, - ptr_data, - pre_lines_displayed, &lines_displayed, - simulate, - CONFIG_BOOLEAN(config_look_color_inactive_message), - 0); - } - - if (!ptr_data[0]) - gui_chat_display_new_line (window, num_lines, count, - &lines_displayed, simulate); - } - else - { - line_align = gui_line_get_align (window->buffer, line, 1, - (lines_displayed == 0) ? 1 : 0); - if ((window->win_chat_cursor_x + word_length_with_spaces > gui_chat_get_real_width (window)) - && (word_length <= gui_chat_get_real_width (window) - line_align)) - { - /* spaces + word too long for current line but OK for next line */ - gui_chat_display_new_line (window, num_lines, count, - &lines_displayed, simulate); - /* apply styles before jumping to start of word */ - if (!simulate && (word_start_offset > 0)) + ptr_style = ptr_data; + while (ptr_style < ptr_data + word_start_offset) { - ptr_style = ptr_data; - while (ptr_style < ptr_data + word_start_offset) - { - /* loop until no style/char available */ - ptr_style = gui_chat_string_next_char (window, line, - (unsigned char *)ptr_style, - 1, - CONFIG_BOOLEAN(config_look_color_inactive_message), - 0); - if (!ptr_style) - break; - ptr_style = utf8_next_char (ptr_style); - } + /* loop until no style/char available */ + ptr_style = gui_chat_string_next_char (window, line, + (unsigned char *)ptr_style, + 1, + CONFIG_BOOLEAN(config_look_color_inactive_message), + 0); + if (!ptr_style) + break; + ptr_style = utf8_next_char (ptr_style); } - /* jump to start of word */ - ptr_data += word_start_offset; } - - /* display word */ - gui_chat_display_word (window, line, ptr_data, - ptr_end_offset + 1, - 0, num_lines, count, - pre_lines_displayed, &lines_displayed, - simulate, - CONFIG_BOOLEAN(config_look_color_inactive_message), - 0); + /* jump to start of word */ + ptr_data += word_start_offset; } + /* display word */ + gui_chat_display_word (window, line, ptr_data, + ptr_end_offset + 1, + 0, num_lines, count, + pre_lines_displayed, &lines_displayed, + simulate, + CONFIG_BOOLEAN(config_look_color_inactive_message), + 0); + if ((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height)) ptr_data = NULL; else @@ -1610,7 +1598,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, if (*(ptr_data - 1) == '\0') ptr_data = NULL; - if (window->win_chat_cursor_x == 0 && !word_is_newlines) + if (window->win_chat_cursor_x == 0) { while (ptr_data && (ptr_data[0] == ' ')) { diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 30af928da..59c1e339f 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -304,6 +304,8 @@ gui_chat_string_pos (const char *string, int real_pos) /* * Returns info about next word: beginning, end, length. * + * Stops before the first newline character, even if no characters or only spaces and color codes precede it. + * * Note: the word_{start|end}_offset are in bytes, but word_length(_with_spaces) * are in number of chars on screen. */ @@ -312,8 +314,7 @@ void gui_chat_get_word_info (struct t_gui_window *window, const char *data, int *word_start_offset, int *word_end_offset, - int *word_length_with_spaces, int *word_length, - int *word_is_newlines) + int *word_length_with_spaces, int *word_length) { const char *start_data, *next_char, *next_char2; int leading_spaces, char_size_screen; @@ -322,7 +323,6 @@ gui_chat_get_word_info (struct t_gui_window *window, *word_end_offset = 0; *word_length_with_spaces = 0; *word_length = -1; - *word_is_newlines = 0; start_data = data; @@ -336,11 +336,15 @@ gui_chat_get_word_info (struct t_gui_window *window, next_char2 = utf8_next_char (next_char); if (next_char2) { - if (next_char[0] != ' ' && - (leading_spaces || (next_char[0] == '\n') == *word_is_newlines)) + if (next_char[0] == '\n') + { + *word_end_offset = next_char - start_data - 1; + if (*word_length < 0) + *word_length = 0; + return; + } + else if (next_char[0] != ' ') { - if (next_char[0] == '\n') - *word_is_newlines = 1; if (leading_spaces) *word_start_offset = next_char - start_data; leading_spaces = 0; diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index 28c222a69..0971b93f9 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -83,8 +83,7 @@ extern void gui_chat_get_word_info (struct t_gui_window *window, const char *data, int *word_start_offset, int *word_end_offset, int *word_length_with_spaces, - int *word_length, - int *word_is_newlines); + int *word_length); extern char *gui_chat_get_time_string (time_t date); extern int gui_chat_get_time_length (); extern void gui_chat_change_time_format (); |