diff options
-rw-r--r-- | src/common/completion.c | 5 | ||||
-rw-r--r-- | src/gui/curses/gui-display.c | 67 | ||||
-rw-r--r-- | src/gui/gui.h | 1 | ||||
-rw-r--r-- | weechat/src/common/completion.c | 5 | ||||
-rw-r--r-- | weechat/src/gui/curses/gui-display.c | 67 | ||||
-rw-r--r-- | weechat/src/gui/gui.h | 1 |
6 files changed, 142 insertions, 4 deletions
diff --git a/src/common/completion.c b/src/common/completion.c index b4cc9ae56..d62ae7294 100644 --- a/src/common/completion.c +++ b/src/common/completion.c @@ -647,7 +647,10 @@ completion_build_list (t_completion *completion, void *channel) completion_stop (completion); else { - string = (char *)gui_color_decode ((unsigned char *)((t_irc_channel *)channel)->topic, 0); + if (cfg_irc_colors_send) + string = (char *)gui_color_decode_for_user_entry ((unsigned char *)((t_irc_channel *)channel)->topic); + else + string = (char *)gui_color_decode ((unsigned char *)((t_irc_channel *)channel)->topic, 0); string2 = weechat_convert_encoding ((local_utf8) ? cfg_look_charset_decode_iso : cfg_look_charset_decode_utf, (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c index 8aad508a6..905de88fc 100644 --- a/src/gui/curses/gui-display.c +++ b/src/gui/curses/gui-display.c @@ -129,7 +129,7 @@ gui_get_color_name (int num_color) * - remove any color/style in message * or: * - change colors by codes to be compatible with - * other IRC clients + * other IRC clients * After use, string returned has to be free() */ @@ -273,6 +273,71 @@ gui_color_decode (unsigned char *string, int keep_colors) } /* + * gui_color_decode_for_user_entry: parses a message (coming from IRC server), + * and replaces colors/bold/.. by %C, %B, .. + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode_for_user_entry (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'B'; + string++; + break; + case GUI_ATTR_RESET_CHAR: + string++; + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_REVERSE2_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'C'; + string++; + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* * gui_color_encode: parses a message (entered by user), and * encode special chars (%B, %C, ..) in IRC colors * After use, string returned has to be free() diff --git a/src/gui/gui.h b/src/gui/gui.h index fb69c9a35..dbca23c64 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -458,6 +458,7 @@ extern void gui_key_free_all (); extern int gui_assign_color (int *, char *); extern char *gui_get_color_name (int); extern unsigned char *gui_color_decode (unsigned char *, int); +extern unsigned char *gui_color_decode_for_user_entry (unsigned char *); extern unsigned char *gui_color_encode (unsigned char *); extern int gui_buffer_has_nicklist (t_gui_buffer *); extern void gui_calculate_pos_size (t_gui_window *); diff --git a/weechat/src/common/completion.c b/weechat/src/common/completion.c index b4cc9ae56..d62ae7294 100644 --- a/weechat/src/common/completion.c +++ b/weechat/src/common/completion.c @@ -647,7 +647,10 @@ completion_build_list (t_completion *completion, void *channel) completion_stop (completion); else { - string = (char *)gui_color_decode ((unsigned char *)((t_irc_channel *)channel)->topic, 0); + if (cfg_irc_colors_send) + string = (char *)gui_color_decode_for_user_entry ((unsigned char *)((t_irc_channel *)channel)->topic); + else + string = (char *)gui_color_decode ((unsigned char *)((t_irc_channel *)channel)->topic, 0); string2 = weechat_convert_encoding ((local_utf8) ? cfg_look_charset_decode_iso : cfg_look_charset_decode_utf, (cfg_look_charset_internal && cfg_look_charset_internal[0]) ? diff --git a/weechat/src/gui/curses/gui-display.c b/weechat/src/gui/curses/gui-display.c index 8aad508a6..905de88fc 100644 --- a/weechat/src/gui/curses/gui-display.c +++ b/weechat/src/gui/curses/gui-display.c @@ -129,7 +129,7 @@ gui_get_color_name (int num_color) * - remove any color/style in message * or: * - change colors by codes to be compatible with - * other IRC clients + * other IRC clients * After use, string returned has to be free() */ @@ -273,6 +273,71 @@ gui_color_decode (unsigned char *string, int keep_colors) } /* + * gui_color_decode_for_user_entry: parses a message (coming from IRC server), + * and replaces colors/bold/.. by %C, %B, .. + * After use, string returned has to be free() + */ + +unsigned char * +gui_color_decode_for_user_entry (unsigned char *string) +{ + unsigned char *out; + int out_length, out_pos; + + out_length = (strlen ((char *)string) * 2) + 1; + out = (unsigned char *)malloc (out_length); + if (!out) + return NULL; + + out_pos = 0; + while (string[0] && (out_pos < out_length - 1)) + { + switch (string[0]) + { + case GUI_ATTR_BOLD_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'B'; + string++; + break; + case GUI_ATTR_RESET_CHAR: + string++; + break; + case GUI_ATTR_FIXED_CHAR: + string++; + break; + case GUI_ATTR_REVERSE_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_REVERSE2_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_ITALIC_CHAR: + string++; + break; + case GUI_ATTR_UNDERLINE_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'R'; + string++; + break; + case GUI_ATTR_COLOR_CHAR: + out[out_pos++] = '%'; + out[out_pos++] = 'C'; + string++; + break; + default: + out[out_pos++] = string[0]; + string++; + } + } + out[out_pos] = '\0'; + return out; +} + +/* * gui_color_encode: parses a message (entered by user), and * encode special chars (%B, %C, ..) in IRC colors * After use, string returned has to be free() diff --git a/weechat/src/gui/gui.h b/weechat/src/gui/gui.h index fb69c9a35..dbca23c64 100644 --- a/weechat/src/gui/gui.h +++ b/weechat/src/gui/gui.h @@ -458,6 +458,7 @@ extern void gui_key_free_all (); extern int gui_assign_color (int *, char *); extern char *gui_get_color_name (int); extern unsigned char *gui_color_decode (unsigned char *, int); +extern unsigned char *gui_color_decode_for_user_entry (unsigned char *); extern unsigned char *gui_color_encode (unsigned char *); extern int gui_buffer_has_nicklist (t_gui_buffer *); extern void gui_calculate_pos_size (t_gui_window *); |