diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-03-07 00:18:19 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-03-07 00:18:19 +0100 |
commit | 997434ef8b1706d47274ede37a009dc883003c82 (patch) | |
tree | 94e01f55f8601faaf6a02dbaafdba292c4407bb6 | |
parent | 780a7478ee02952c23ff7b71d1ec7bc02fdad5ce (diff) | |
download | weechat-997434ef8b1706d47274ede37a009dc883003c82.zip |
Fix bug with text attribute in IRC messages: toggle attribute instead of always forcing it to on (bug #25770)
-rw-r--r-- | doc/en/dev/plugin_c_api.en.xml | 6 | ||||
-rw-r--r-- | src/gui/gui-color.c | 28 | ||||
-rw-r--r-- | src/plugins/irc/irc-color.c | 29 |
3 files changed, 55 insertions, 8 deletions
diff --git a/doc/en/dev/plugin_c_api.en.xml b/doc/en/dev/plugin_c_api.en.xml index 9f4f123e4..f7acfd393 100644 --- a/doc/en/dev/plugin_c_api.en.xml +++ b/doc/en/dev/plugin_c_api.en.xml @@ -4674,8 +4674,10 @@ const char *weechat_color (const char *color_name); <listitem> <para> <option>color_name</option>: name of color: may be a WeeChat - color name (from weechat.color.xxx), or a color with optional - background (separated by comma). + color name (from weechat.color.xxx), a color with optional + background (separated by comma), attribute ("bold", "-bold", + "reverse", "-reverse", "italic", "-italic", "underline", + "-underline", ) or a bar color ("bar_fg", "bar_delim", "bar_bg"). </para> </listitem> </itemizedlist> diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c index 8c4e307ef..3766dc217 100644 --- a/src/gui/gui-color.c +++ b/src/gui/gui-color.c @@ -104,6 +104,13 @@ gui_color_get_custom (const char *color_name) GUI_COLOR_SET_WEECHAT_STR, GUI_COLOR_ATTR_BOLD_STR); } + else if (string_strcasecmp (color_name, "-bold") == 0) + { + snprintf (color[index_color], sizeof (color[index_color]), + "%s%s", + GUI_COLOR_REMOVE_WEECHAT_STR, + GUI_COLOR_ATTR_BOLD_STR); + } else if (string_strcasecmp (color_name, "reverse") == 0) { snprintf (color[index_color], sizeof (color[index_color]), @@ -111,6 +118,13 @@ gui_color_get_custom (const char *color_name) GUI_COLOR_SET_WEECHAT_STR, GUI_COLOR_ATTR_REVERSE_STR); } + else if (string_strcasecmp (color_name, "-reverse") == 0) + { + snprintf (color[index_color], sizeof (color[index_color]), + "%s%s", + GUI_COLOR_REMOVE_WEECHAT_STR, + GUI_COLOR_ATTR_REVERSE_STR); + } else if (string_strcasecmp (color_name, "italic") == 0) { snprintf (color[index_color], sizeof (color[index_color]), @@ -118,6 +132,13 @@ gui_color_get_custom (const char *color_name) GUI_COLOR_SET_WEECHAT_STR, GUI_COLOR_ATTR_ITALIC_STR); } + else if (string_strcasecmp (color_name, "-italic") == 0) + { + snprintf (color[index_color], sizeof (color[index_color]), + "%s%s", + GUI_COLOR_REMOVE_WEECHAT_STR, + GUI_COLOR_ATTR_ITALIC_STR); + } else if (string_strcasecmp (color_name, "underline") == 0) { snprintf (color[index_color], sizeof (color[index_color]), @@ -125,6 +146,13 @@ gui_color_get_custom (const char *color_name) GUI_COLOR_SET_WEECHAT_STR, GUI_COLOR_ATTR_UNDERLINE_STR); } + else if (string_strcasecmp (color_name, "-underline") == 0) + { + snprintf (color[index_color], sizeof (color[index_color]), + "%s%s", + GUI_COLOR_REMOVE_WEECHAT_STR, + GUI_COLOR_ATTR_UNDERLINE_STR); + } else if (string_strcasecmp (color_name, "bar_fg") == 0) { snprintf (color[index_color], sizeof (color[index_color]), diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c index f1f06eeec..6e1fe3d4c 100644 --- a/src/plugins/irc/irc-color.c +++ b/src/plugins/irc/irc-color.c @@ -54,7 +54,7 @@ char *irc_color_to_weechat[IRC_NUM_COLORS] = * irc_color_decode: replace IRC colors by WeeChat colors * if keep_colors == 0: remove any color/style in message * otherwise: keep colors - * Note: after use, string returned has to be free() +x * Note: after use, string returned has to be free() */ char * @@ -63,13 +63,18 @@ irc_color_decode (const char *string, int keep_colors) unsigned char *out, *ptr_string; int out_length, length, out_pos; char str_fg[3], str_bg[3], str_color[128]; - int fg, bg; + int fg, bg, bold, reverse, italic, underline; out_length = (strlen (string) * 2) + 1; out = malloc (out_length); if (!out) return NULL; + bold = 0; + reverse = 0; + italic = 0; + underline = 0; + ptr_string = (unsigned char *)string; out[0] = '\0'; while (ptr_string && ptr_string[0]) @@ -78,12 +83,18 @@ irc_color_decode (const char *string, int keep_colors) { case IRC_COLOR_BOLD_CHAR: if (keep_colors) - strcat ((char *)out, weechat_color("bold")); + strcat ((char *)out, + weechat_color((bold) ? "-bold" : "bold")); + bold ^= 1; ptr_string++; break; case IRC_COLOR_RESET_CHAR: if (keep_colors) strcat ((char *)out, weechat_color("reset")); + bold = 0; + reverse = 0; + italic = 0; + underline = 0; ptr_string++; break; case IRC_COLOR_FIXED_CHAR: @@ -92,17 +103,23 @@ irc_color_decode (const char *string, int keep_colors) case IRC_COLOR_REVERSE_CHAR: case IRC_COLOR_REVERSE2_CHAR: if (keep_colors) - strcat ((char *)out, weechat_color("reverse")); + strcat ((char *)out, + weechat_color((reverse) ? "-reverse" : "reverse")); + reverse ^= 1; ptr_string++; break; case IRC_COLOR_ITALIC_CHAR: if (keep_colors) - strcat ((char *)out, weechat_color("italic")); + strcat ((char *)out, + weechat_color((italic) ? "-italic" : "italic")); + italic ^= 1; ptr_string++; break; case IRC_COLOR_UNDERLINE_CHAR: if (keep_colors) - strcat ((char *)out, weechat_color("underline")); + strcat ((char *)out, + weechat_color((underline) ? "-underline" : "underline")); + underline ^= 1; ptr_string++; break; case IRC_COLOR_COLOR_CHAR: |