summaryrefslogtreecommitdiff
path: root/src/gui/curses/gui-curses-chat.c
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-03-29 16:36:51 +0200
committerSebastien Helleu <flashcode@flashtux.org>2012-03-29 16:36:51 +0200
commit10df976e53a4bf131bc9905b30237e2ffeb33a9a (patch)
tree671872a9a29cfc8e030a2f1c698c37dc193c2db9 /src/gui/curses/gui-curses-chat.c
parentae2c97b8cb912bf043e70e4972ede125955b47f5 (diff)
downloadweechat-10df976e53a4bf131bc9905b30237e2ffeb33a9a.zip
core: fix display bug with prefix when length is greater than max and prefix is ending with a wide char (bug #36032)
Diffstat (limited to 'src/gui/curses/gui-curses-chat.c')
-rw-r--r--src/gui/curses/gui-curses-chat.c83
1 files changed, 55 insertions, 28 deletions
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 37560cb06..fdd4b13c7 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -395,9 +395,10 @@ gui_chat_display_word_raw (struct t_gui_window *window, struct t_gui_line *line,
/*
* gui_chat_display_word: display a word on chat buffer
+ * return number of chars displayed on screen
*/
-void
+int
gui_chat_display_word (struct t_gui_window *window,
struct t_gui_line *line,
const char *word, const char *word_end,
@@ -406,23 +407,25 @@ gui_chat_display_word (struct t_gui_window *window,
int apply_style_inactive)
{
char *data, *ptr_data, *end_line, saved_char, str_space[] = " ";
- int pos_saved_char, chars_to_display, num_displayed;
+ int chars_displayed, pos_saved_char, chars_to_display, num_displayed;
int length_align;
attr_t attrs;
attr_t *ptr_attrs;
short pair;
short *ptr_pair;
+ chars_displayed = 0;
+
if (!word ||
((!simulate) && (window->win_chat_cursor_y >= window->win_chat_height)))
- return;
+ return chars_displayed;
if (!simulate && (window->win_chat_cursor_y < window->coords_size))
window->coords[window->win_chat_cursor_y].line = line;
data = strdup (word);
if (!data)
- return;
+ return chars_displayed;
end_line = data + strlen (data);
@@ -463,15 +466,18 @@ gui_chat_display_word (struct t_gui_window *window,
gui_window_save_style ();
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
GUI_COLOR_CHAT_PREFIX_SUFFIX);
- gui_chat_display_word_raw (window, line,
- CONFIG_STRING(config_look_prefix_suffix),
- 0, 1, apply_style_inactive);
+ chars_displayed += gui_chat_display_word_raw (window, line,
+ CONFIG_STRING(config_look_prefix_suffix),
+ 0, 1,
+ apply_style_inactive);
}
window->win_chat_cursor_x += gui_chat_strlen_screen (CONFIG_STRING(config_look_prefix_suffix));
if (!simulate)
{
- gui_chat_display_word_raw (window, line, str_space, 0, 1,
- apply_style_inactive);
+ chars_displayed += gui_chat_display_word_raw (window, line,
+ str_space,
+ 0, 1,
+ apply_style_inactive);
}
window->win_chat_cursor_x += gui_chat_strlen_screen (str_space);
if (!simulate)
@@ -497,13 +503,17 @@ gui_chat_display_word (struct t_gui_window *window,
ptr_data[pos_saved_char] = '\0';
if ((count == 0) || (*lines_displayed >= num_lines - count))
{
- gui_chat_display_word_raw (window, line, ptr_data, 0, 1,
- apply_style_inactive);
+ chars_displayed += gui_chat_display_word_raw (window, line,
+ ptr_data,
+ 0, 1,
+ apply_style_inactive);
}
else
{
- gui_chat_display_word_raw (window, line, ptr_data, 0, 0,
- apply_style_inactive);
+ chars_displayed += gui_chat_display_word_raw (window, line,
+ ptr_data,
+ 0, 0,
+ apply_style_inactive);
}
ptr_data[pos_saved_char] = saved_char;
}
@@ -516,13 +526,17 @@ gui_chat_display_word (struct t_gui_window *window,
{
if ((count == 0) || (*lines_displayed >= num_lines - count))
{
- gui_chat_display_word_raw (window, line, ptr_data, 0, 1,
- apply_style_inactive);
+ chars_displayed += gui_chat_display_word_raw (window, line,
+ ptr_data,
+ 0, 1,
+ apply_style_inactive);
}
else
{
- gui_chat_display_word_raw (window, line, ptr_data, 0, 0,
- apply_style_inactive);
+ chars_displayed += gui_chat_display_word_raw (window, line,
+ ptr_data,
+ 0, 0,
+ apply_style_inactive);
}
}
ptr_data += strlen (ptr_data);
@@ -544,6 +558,8 @@ gui_chat_display_word (struct t_gui_window *window,
}
free (data);
+
+ return chars_displayed;
}
/*
@@ -561,7 +577,8 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
char str_space[] = " ", str_plus[] = "+";
char *prefix_no_color, *prefix_highlighted, *ptr_prefix;
const char *short_name;
- int i, length, length_allowed, num_spaces, prefix_length;
+ int i, length, length_allowed, num_spaces, prefix_length, extra_spaces;
+ int chars_displayed;
struct t_gui_lines *mixed_lines;
if (!simulate)
@@ -804,19 +821,22 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
window->coords[window->win_chat_cursor_y].prefix_x1 = window->win_chat_cursor_x;
/* not enough space to display full prefix? => truncate it! */
+ extra_spaces = 0;
if ((CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)
&& (num_spaces < 0))
{
- gui_chat_display_word (window, line,
- (prefix_highlighted) ? prefix_highlighted : ptr_prefix,
- (prefix_highlighted) ?
- prefix_highlighted + gui_chat_string_real_pos (prefix_highlighted,
- length_allowed) :
- ptr_prefix + gui_chat_string_real_pos (ptr_prefix,
- length_allowed),
- 1, num_lines, count, lines_displayed,
- simulate,
- CONFIG_BOOLEAN(config_look_color_inactive_prefix));
+ chars_displayed = gui_chat_display_word (window, line,
+ (prefix_highlighted) ? prefix_highlighted : ptr_prefix,
+ (prefix_highlighted) ?
+ prefix_highlighted + gui_chat_string_real_pos (prefix_highlighted,
+ length_allowed) :
+ ptr_prefix + gui_chat_string_real_pos (ptr_prefix,
+ length_allowed),
+ 1, num_lines, count, lines_displayed,
+ simulate,
+ CONFIG_BOOLEAN(config_look_color_inactive_prefix));
+ if (chars_displayed < length_allowed)
+ extra_spaces = length_allowed - chars_displayed;
}
else
{
@@ -876,6 +896,13 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
CONFIG_BOOLEAN(config_look_color_inactive_prefix));
}
}
+ for (i = 0; i < extra_spaces; i++)
+ {
+ gui_chat_display_word (window, line, str_space,
+ NULL, 1, num_lines, count, lines_displayed,
+ simulate,
+ CONFIG_BOOLEAN(config_look_color_inactive_prefix));
+ }
if ((CONFIG_INTEGER(config_look_prefix_align) != CONFIG_LOOK_PREFIX_ALIGN_NONE)
&& (CONFIG_STRING(config_look_prefix_suffix)
&& CONFIG_STRING(config_look_prefix_suffix)[0]))