diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-08-06 19:02:25 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-08-06 19:02:25 +0200 |
commit | f11549f654ddedb7073744e1d1591c8c3086220d (patch) | |
tree | 424b95c996209dc02daf6c2e5c87676500334961 /src/gui | |
parent | 2fb864b8f8ea6fbc9508075797bab641dc0f91e2 (diff) | |
download | weechat-f11549f654ddedb7073744e1d1591c8c3086220d.zip |
Fix display bug with special chars (ascii value below 32) (bug #30602)
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/curses/gui-curses-bar-window.c | 4 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-chat.c | 38 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 18 | ||||
-rw-r--r-- | src/gui/curses/gui-curses.h | 1 | ||||
-rw-r--r-- | src/gui/gui-chat.c | 24 | ||||
-rw-r--r-- | src/gui/gui-chat.h | 1 |
6 files changed, 40 insertions, 46 deletions
diff --git a/src/gui/curses/gui-curses-bar-window.c b/src/gui/curses/gui-curses-bar-window.c index e9ff8c582..8b1eb336c 100644 --- a/src/gui/curses/gui-curses-bar-window.c +++ b/src/gui/curses/gui-curses-bar-window.c @@ -356,8 +356,8 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window, else { low_char = 0; - if (!gui_window_utf_char_valid (utf_char)) - snprintf (utf_char, sizeof (utf_char), "."); + if (!gui_chat_utf_char_valid (utf_char)) + snprintf (utf_char, sizeof (utf_char), " "); } size_on_screen = utf8_char_size_screen (utf_char); diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index f2649f3da..3653c1d78 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -377,33 +377,23 @@ gui_chat_display_word_raw (struct t_gui_window *window, const char *string, { memcpy (utf_char, string, next_char - string); utf_char[next_char - string] = '\0'; - if (gui_window_utf_char_valid (utf_char)) + if (!gui_chat_utf_char_valid (utf_char)) + snprintf (utf_char, sizeof (utf_char), " "); + + size_on_screen = utf8_strlen_screen (utf_char); + if (max_chars_on_screen > 0) { - size_on_screen = utf8_strlen_screen (utf_char); - if (max_chars_on_screen > 0) - { - if (chars_displayed + size_on_screen > max_chars_on_screen) - return chars_displayed; - chars_displayed += size_on_screen; - } - if (size_on_screen > 0) - { - output = string_iconv_from_internal (NULL, utf_char); - wprintw (GUI_WINDOW_OBJECTS(window)->win_chat, - "%s", (output) ? output : utf_char); - if (output) - free (output); - } + if (chars_displayed + size_on_screen > max_chars_on_screen) + return chars_displayed; + chars_displayed += size_on_screen; } - else + if (size_on_screen > 0) { - if (max_chars_on_screen > 0) - { - if (chars_displayed + 1 > max_chars_on_screen) - return chars_displayed; - chars_displayed++; - } - wprintw (GUI_WINDOW_OBJECTS(window)->win_chat, "."); + output = string_iconv_from_internal (NULL, utf_char); + wprintw (GUI_WINDOW_OBJECTS(window)->win_chat, + "%s", (output) ? output : utf_char); + if (output) + free (output); } } diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index ca3699911..aa2d0a1f3 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -145,24 +145,6 @@ gui_window_objects_free (struct t_gui_window *window, int free_separator) } /* - * gui_window_utf_char_valid: return 1 if utf char is valid for screen - * otherwise return 0 - */ - -int -gui_window_utf_char_valid (const char *utf_char) -{ - /* 146 or 0x7F are not valid */ - if ((((unsigned char)(utf_char[0]) == 146) - || ((unsigned char)(utf_char[0]) == 0x7F)) - && (!utf_char[1])) - return 0; - - /* any other char is valid */ - return 1; -} - -/* * gui_window_get_hline_char: get char used to draw horizontal lines * Note: ACS_HLINE from ncurses is better for * render, but it introduces bug with URLs diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h index e826790cc..133d4fa02 100644 --- a/src/gui/curses/gui-curses.h +++ b/src/gui/curses/gui-curses.h @@ -78,7 +78,6 @@ extern int gui_keyboard_read_cb (void *data, int fd); /* window functions */ extern void gui_window_read_terminal_size (); extern void gui_window_redraw_buffer (struct t_gui_buffer *buffer); -extern int gui_window_utf_char_valid (const char *utf_char); extern int gui_window_get_hline_char (); extern void gui_window_clear (WINDOW *window, int bg); extern void gui_window_reset_style (WINDOW *window, int num_color); diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index e036f48db..734e7228a 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -119,6 +119,28 @@ gui_chat_prefix_build () } /* + * gui_chat_utf_char_valid: return 1 if utf char is valid for screen + * otherwise return 0 + */ + +int +gui_chat_utf_char_valid (const char *utf_char) +{ + /* chars below 32 are not valid */ + if ((unsigned char)utf_char[0] < 32) + return 0; + + /* 146 or 0x7F are not valid */ + if ((((unsigned char)(utf_char[0]) == 146) + || ((unsigned char)(utf_char[0]) == 0x7F)) + && (!utf_char[1])) + return 0; + + /* any other char is valid */ + return 1; +} + +/* * gui_chat_strlen_screen: returns number of char needed on sreen to display a * word special chars like color, bold, .. are ignored */ @@ -134,7 +156,7 @@ gui_chat_strlen_screen (const char *string) string = gui_chat_string_next_char (NULL, (unsigned char *)string, 0); if (string) { - size_on_screen = (((unsigned char)string[0]) < 32) ? 1 : utf8_char_size_screen (string); + size_on_screen = (gui_chat_utf_char_valid (string)) ? utf8_char_size_screen (string) : 1; if (size_on_screen > 0) length += size_on_screen; string = utf8_next_char (string); diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index 545823527..5851b6535 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -59,6 +59,7 @@ extern struct t_gui_buffer *gui_chat_mute_buffer; extern void gui_chat_init (); extern void gui_chat_prefix_build (); +extern int gui_chat_utf_char_valid (const char *utf_char); extern int gui_chat_strlen_screen (const char *string); extern char *gui_chat_string_add_offset (const char *string, int offset); extern int gui_chat_string_real_pos (const char *string, int pos); |