summaryrefslogtreecommitdiff
path: root/src/gui/curses/gui-curses-chat.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-12-04 20:03:21 +0100
committerSébastien Helleu <flashcode@flashtux.org>2022-12-10 16:05:14 +0100
commitf1cfd6f73f0f5cc16b9b919d64406a35aa81c7cf (patch)
tree96a6dfbea3772e65aeec1344b2cb4c7061c916ef /src/gui/curses/gui-curses-chat.c
parentd18f68e497c4244404ff8f4f50de82717b178e09 (diff)
downloadweechat-f1cfd6f73f0f5cc16b9b919d64406a35aa81c7cf.zip
core: do not display non printable chars, fix function utf8_char_size_screen
Now the function utf8_char_size_screen can return -1 when the char is not printable. It has a specific behavior for some chars: - U+0009: value of option weechat.look.tab_width - U+0001 to U+001F (except U+0009): 1 - U+00AD (soft hyphen): -1 - U+200B (zero width space): -1
Diffstat (limited to 'src/gui/curses/gui-curses-chat.c')
-rw-r--r--src/gui/curses/gui-curses-chat.c72
1 files changed, 40 insertions, 32 deletions
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index e106a43ef..40bc38577 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -373,7 +373,8 @@ gui_chat_display_word_raw (struct t_gui_window *window, struct t_gui_line *line,
int apply_style_inactive,
int nick_offline)
{
- char *output, utf_char[16], *ptr_char;
+ const char *ptr_char;
+ char *output, utf_char[16], utf_char2[16];
int x, chars_displayed, display_char, size_on_screen, reverse_video;
if (!simulate)
@@ -416,13 +417,6 @@ gui_chat_display_word_raw (struct t_gui_window *window, struct t_gui_line *line,
reverse_video = (gui_window_current_color_attr & A_REVERSE) ?
0 : 1;
}
- else
- {
- /* display non printable chars as spaces */
- if (!gui_chat_utf_char_valid (utf_char))
- snprintf (utf_char, sizeof (utf_char), " ");
-
- }
display_char = (window->buffer->type != GUI_BUFFER_TYPE_FREE)
|| (x >= window->scroll->start_col);
@@ -433,37 +427,51 @@ gui_chat_display_word_raw (struct t_gui_window *window, struct t_gui_line *line,
{
return chars_displayed;
}
- if (display_char && (size_on_screen >= 0))
+
+ if (display_char)
{
- if (!simulate)
+ while (ptr_char && ptr_char[0])
{
- output = string_iconv_from_internal (NULL, ptr_char);
- if (reverse_video)
+ utf8_strncpy (utf_char2, ptr_char, 1);
+ size_on_screen = utf8_char_size_screen (utf_char2);
+ if (size_on_screen >= 0)
{
- wattron (GUI_WINDOW_OBJECTS(window)->win_chat,
- A_REVERSE);
- }
- waddstr (GUI_WINDOW_OBJECTS(window)->win_chat,
- (output) ? output : ptr_char);
- if (reverse_video)
- {
- wattroff (GUI_WINDOW_OBJECTS(window)->win_chat,
- A_REVERSE);
- }
- if (output)
- free (output);
+ if (!simulate)
+ {
+ output = string_iconv_from_internal (NULL, utf_char2);
+ if (reverse_video)
+ {
+ wattron (GUI_WINDOW_OBJECTS(window)->win_chat,
+ A_REVERSE);
+ }
+ waddstr (GUI_WINDOW_OBJECTS(window)->win_chat,
+ (output) ? output : utf_char2);
+ if (reverse_video)
+ {
+ wattroff (GUI_WINDOW_OBJECTS(window)->win_chat,
+ A_REVERSE);
+ }
+ if (output)
+ free (output);
- if (gui_window_current_emphasis)
- {
- gui_window_emphasize (GUI_WINDOW_OBJECTS(window)->win_chat,
- x - window->scroll->start_col,
- window->win_chat_cursor_y,
- size_on_screen);
+ if (gui_window_current_emphasis)
+ {
+ gui_window_emphasize (GUI_WINDOW_OBJECTS(window)->win_chat,
+ x - window->scroll->start_col,
+ window->win_chat_cursor_y,
+ size_on_screen);
+ }
+ }
+ chars_displayed += size_on_screen;
+ x += size_on_screen;
}
+ ptr_char = utf8_next_char (ptr_char);
}
- chars_displayed += size_on_screen;
}
- x += size_on_screen;
+ else
+ {
+ x += size_on_screen;
+ }
}
string = utf8_next_char (string);