summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/irc/irc-color.c26
-rw-r--r--src/plugins/irc/irc-config.c74
-rw-r--r--src/plugins/irc/irc-config.h2
3 files changed, 96 insertions, 6 deletions
diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c
index 9b019e73f..34fe6589b 100644
--- a/src/plugins/irc/irc-color.c
+++ b/src/plugins/irc/irc-color.c
@@ -64,7 +64,8 @@ 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];
+ char str_fg[3], str_bg[3], str_color[128], str_key[128];
+ const char *remapped_color;
int fg, bg, bold, reverse, italic, underline, rc;
out_length = (strlen (string) * 2) + 1;
@@ -175,11 +176,24 @@ irc_color_decode (const char *string, int keep_colors)
bg %= IRC_NUM_COLORS;
}
}
- snprintf (str_color, sizeof (str_color),
- "|%s%s%s",
- (fg >= 0) ? irc_color_to_weechat[fg] : "",
- (bg >= 0) ? "," : "",
- (bg >= 0) ? irc_color_to_weechat[bg] : "");
+ /* search "fg,bg" in hashtable of remapped colors */
+ snprintf (str_key, sizeof (str_key), "%d,%d", fg, bg);
+ remapped_color = weechat_hashtable_get (
+ irc_config_hashtable_color_mirc_remap,
+ str_key);
+ if (remapped_color)
+ {
+ snprintf (str_color, sizeof (str_color),
+ "|%s", remapped_color);
+ }
+ else
+ {
+ snprintf (str_color, sizeof (str_color),
+ "|%s%s%s",
+ (fg >= 0) ? irc_color_to_weechat[fg] : "",
+ (bg >= 0) ? "," : "",
+ (bg >= 0) ? irc_color_to_weechat[bg] : "");
+ }
strcat ((char *)out, weechat_color(str_color));
}
else
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 1fede24b7..d711ff34d 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -99,6 +99,7 @@ struct t_config_option *irc_config_look_topic_strip_colors;
struct t_config_option *irc_config_color_message_join;
struct t_config_option *irc_config_color_message_quit;
+struct t_config_option *irc_config_color_mirc_remap;
struct t_config_option *irc_config_color_nick_prefixes;
struct t_config_option *irc_config_color_nick_prefix;
struct t_config_option *irc_config_color_nick_suffix;
@@ -135,6 +136,7 @@ char **irc_config_nick_colors = NULL;
int irc_config_num_nick_colors = 0;
struct t_hashtable *irc_config_hashtable_nick_color_force = NULL;
struct t_hashtable *irc_config_hashtable_nick_prefixes = NULL;
+struct t_hashtable *irc_config_hashtable_color_mirc_remap = NULL;
int irc_config_write_temp_servers = 0;
@@ -591,6 +593,51 @@ irc_config_change_color_item_lag (void *data,
}
/*
+ * irc_config_change_color_mirc_remap: called when the "mirc remap" option is
+ * changed
+ */
+
+void
+irc_config_change_color_mirc_remap (void *data, struct t_config_option *option)
+{
+ char **items, *pos;
+ int num_items, i;
+
+ /* make C compiler happy */
+ (void) data;
+ (void) option;
+
+ if (!irc_config_hashtable_color_mirc_remap)
+ {
+ irc_config_hashtable_color_mirc_remap = weechat_hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
+ }
+ else
+ weechat_hashtable_remove_all (irc_config_hashtable_color_mirc_remap);
+
+ items = weechat_string_split (weechat_config_string (irc_config_color_mirc_remap),
+ ";", 0, 0, &num_items);
+ if (items)
+ {
+ for (i = 0; i < num_items; i++)
+ {
+ pos = strchr (items[i], ':');
+ if (pos)
+ {
+ pos[0] = '\0';
+ weechat_hashtable_set (irc_config_hashtable_color_mirc_remap,
+ items[i],
+ pos + 1);
+ }
+ }
+ weechat_string_free_split (items);
+ }
+}
+
+/*
* irc_config_change_color_nick_prefixes: called when the string with color of
* nick prefixes is changed
*/
@@ -1903,6 +1950,11 @@ irc_config_init ()
{
struct t_config_section *ptr_section;
+ irc_config_hashtable_color_mirc_remap = weechat_hashtable_new (8,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL,
+ NULL);
irc_config_hashtable_nick_color_force = weechat_hashtable_new (8,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
@@ -2241,6 +2293,21 @@ irc_config_init ()
N_("color for text in part/quit messages"),
NULL, -1, 0, "red", NULL, 0, NULL, NULL,
NULL, NULL, NULL, NULL);
+ irc_config_color_mirc_remap = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "mirc_remap", "string",
+ /* TRANSLATORS: please do not translate the list of WeeChat color names at the end of string */
+ N_("remap mirc colors in messages using a hashtable: keys are \"fg,bg\" "
+ "as integers between -1 (not specified) and 15, values are WeeChat "
+ "color names or numbers (format is: \"1,-1:color1;2,7:color2\"), "
+ "example: \"1,-1:darkgray;1,2:white,blue\" to remap black on any bg "
+ "to \"darkgray\" and black on blue to \"white,blue\"; default "
+ "WeeChat colors for IRC codes: 0:white, 1:black, 2:blue, 3:green, "
+ "4:lightred, 5:red, 6:magenta, 7:brown, 8:yellow, 9: lightgreen, "
+ "10:cyan, 11:lightcyan, 12:lightblue, 13:lightmagenta, 14:gray, "
+ "15:white"),
+ NULL, 0, 0, "1,-1:darkgray", NULL, 0, NULL, NULL,
+ &irc_config_change_color_mirc_remap, NULL, NULL, NULL);
irc_config_color_nick_prefixes = weechat_config_new_option (
irc_config_file, ptr_section,
"nick_prefixes", "string",
@@ -2497,6 +2564,7 @@ irc_config_read ()
irc_notify_new_for_all_servers ();
irc_config_change_look_nick_color_force (NULL, NULL);
irc_config_change_color_nick_prefixes (NULL, NULL);
+ irc_config_change_color_mirc_remap (NULL, NULL);
irc_config_change_network_notify_check_ison (NULL, NULL);
irc_config_change_network_notify_check_whois (NULL, NULL);
}
@@ -2547,4 +2615,10 @@ irc_config_free ()
weechat_hashtable_free (irc_config_hashtable_nick_prefixes);
irc_config_hashtable_nick_prefixes = NULL;
}
+
+ if (irc_config_hashtable_color_mirc_remap)
+ {
+ weechat_hashtable_free (irc_config_hashtable_color_mirc_remap);
+ irc_config_hashtable_color_mirc_remap = NULL;
+ }
}
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
index 4dd024551..f23b4dbc6 100644
--- a/src/plugins/irc/irc-config.h
+++ b/src/plugins/irc/irc-config.h
@@ -122,6 +122,7 @@ extern struct t_config_option *irc_config_look_topic_strip_colors;
extern struct t_config_option *irc_config_color_message_join;
extern struct t_config_option *irc_config_color_message_quit;
+extern struct t_config_option *irc_config_color_mirc_remap;
extern struct t_config_option *irc_config_color_nick_prefixes;
extern struct t_config_option *irc_config_color_nick_prefix;
extern struct t_config_option *irc_config_color_nick_suffix;
@@ -154,6 +155,7 @@ extern int irc_config_num_nick_colors;
extern struct t_hashtable *irc_config_hashtable_nick_color_force;
extern struct t_hashtable *irc_config_hashtable_nick_prefixes;
+extern struct t_hashtable *irc_config_hashtable_color_mirc_remap;
extern void irc_config_set_nick_colors ();
extern int irc_config_server_check_value_cb (void *data,