summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-color.c46
-rw-r--r--src/plugins/irc/irc-config.c81
-rw-r--r--src/plugins/irc/irc-config.h2
3 files changed, 111 insertions, 18 deletions
diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c
index b110fcfbc..dc031f19c 100644
--- a/src/plugins/irc/irc-color.c
+++ b/src/plugins/irc/irc-color.c
@@ -214,7 +214,7 @@ irc_color_decode (const char *string, int keep_colors)
char str_fg[16], str_bg[16], str_color[128], str_key[128], str_to_add[128];
const char *remapped_color;
unsigned char *ptr_string;
- int length, fg, bg, bold, reverse, italic, underline, color_number;
+ int length, fg, bg, fg_term, bg_term, bold, reverse, italic, underline;
long fg_rgb, bg_rgb;
if (!string)
@@ -426,29 +426,39 @@ irc_color_decode (const char *string, int keep_colors)
}
str_fg[0] = '\0';
str_bg[0] = '\0';
+ fg_term = -1;
+ bg_term = -1;
if (fg_rgb >= 0)
{
- color_number = irc_color_convert_rgb2term (fg_rgb);
- if (color_number >= 0)
- {
- snprintf (str_fg, sizeof (str_fg),
- "%d", color_number);
- }
+ fg_term = irc_color_convert_rgb2term (fg_rgb);
+ if (fg_term >= 0)
+ snprintf (str_fg, sizeof (str_fg), "%d", fg_term);
}
if (bg_rgb >= 0)
{
- color_number = irc_color_convert_rgb2term (bg_rgb);
- if (color_number >= 0)
- {
- snprintf (str_bg, sizeof (str_bg),
- "%d", color_number);
- }
+ bg_term = irc_color_convert_rgb2term (bg_rgb);
+ if (bg_term >= 0)
+ snprintf (str_bg, sizeof (str_bg), "%d", bg_term);
+ }
+ /* search "fg_term,bg_term" in hashtable of remapped colors */
+ snprintf (str_key, sizeof (str_key),
+ "%d,%d", fg_term, bg_term);
+ remapped_color = weechat_hashtable_get (
+ irc_config_hashtable_color_term_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",
+ str_fg,
+ (str_bg[0]) ? "," : "",
+ str_bg);
}
- snprintf (str_color, sizeof (str_color),
- "|%s%s%s",
- str_fg,
- (str_bg[0]) ? "," : "",
- str_bg);
snprintf (str_to_add, sizeof (str_to_add), "%s",
weechat_color (str_color));
}
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 7da53f06a..92fb7a6fe 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -153,6 +153,7 @@ struct t_config_option *irc_config_color_nick_prefixes = NULL;
struct t_config_option *irc_config_color_notice = NULL;
struct t_config_option *irc_config_color_reason_kick = NULL;
struct t_config_option *irc_config_color_reason_quit = NULL;
+struct t_config_option *irc_config_color_term_remap = NULL;
struct t_config_option *irc_config_color_topic_current = NULL;
struct t_config_option *irc_config_color_topic_new = NULL;
struct t_config_option *irc_config_color_topic_old = NULL;
@@ -188,6 +189,7 @@ struct t_hook *irc_config_hook_config_chat_nick_colors = NULL;
struct t_hashtable *irc_config_hashtable_display_join_message = NULL;
struct t_hashtable *irc_config_hashtable_nick_prefixes = NULL;
struct t_hashtable *irc_config_hashtable_color_mirc_remap = NULL;
+struct t_hashtable *irc_config_hashtable_color_term_remap = NULL;
char **irc_config_nicks_hide_password = NULL;
int irc_config_num_nicks_hide_password = 0;
@@ -878,6 +880,59 @@ irc_config_change_color_nick_prefixes (const void *pointer, void *data,
}
/*
+ * Callback for changes on option "irc.color.term_remap".
+ */
+
+void
+irc_config_change_color_term_remap (const void *pointer, void *data,
+ struct t_config_option *option)
+{
+ char **items, *pos;
+ int num_items, i;
+
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) option;
+
+ if (!irc_config_hashtable_color_term_remap)
+ {
+ irc_config_hashtable_color_term_remap = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
+ }
+ else
+ weechat_hashtable_remove_all (irc_config_hashtable_color_term_remap);
+
+ items = weechat_string_split (
+ weechat_config_string (irc_config_color_term_remap),
+ ";",
+ NULL,
+ WEECHAT_STRING_SPLIT_STRIP_LEFT
+ | WEECHAT_STRING_SPLIT_STRIP_RIGHT
+ | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
+ 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_term_remap,
+ items[i],
+ pos + 1);
+ }
+ }
+ weechat_string_free_split (items);
+ }
+}
+
+/*
* Callback for changes on option "irc.network.lag_check".
*/
@@ -2969,6 +3024,11 @@ irc_config_init ()
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
+ irc_config_hashtable_color_term_remap = weechat_hashtable_new (
+ 32,
+ WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_STRING,
+ NULL, NULL);
irc_config_file = weechat_config_new (IRC_CONFIG_PRIO_NAME,
&irc_config_reload, NULL, NULL);
@@ -3753,6 +3813,20 @@ irc_config_init ()
N_("color for reason in part/quit messages"),
NULL, -1, 0, "244", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ irc_config_color_term_remap = weechat_config_new_option (
+ irc_config_file, irc_config_section_color,
+ "term_remap", "string",
+ N_("remap terminal color numbers in messages using a hashtable "
+ "(used for RGB colors as hexadecimal, which are first translated "
+ "to terminal color numbers): keys are \"fg,bg\" as integers "
+ "between -1 (not specified) and 255, values are WeeChat color "
+ "names or numbers (format is: \"1,-1:color1;2,7:color2\"), example: "
+ "\"0,-1:darkgray;0,90:white,blue\" to remap black to "
+ "\"darkgray\" and black on dark magenta to \"white,blue\""),
+ NULL, 0, 0, "0,-1:darkgray", NULL, 0,
+ NULL, NULL, NULL,
+ &irc_config_change_color_term_remap, NULL, NULL,
+ NULL, NULL, NULL);
irc_config_color_topic_current = weechat_config_new_option (
irc_config_file, irc_config_section_color,
"topic_current", "color",
@@ -3991,6 +4065,7 @@ irc_config_read ()
irc_config_change_look_nicks_hide_password (NULL, NULL, NULL);
irc_config_change_color_nick_prefixes (NULL, NULL, NULL);
irc_config_change_color_mirc_remap (NULL, NULL, NULL);
+ irc_config_change_color_term_remap (NULL, NULL, NULL);
irc_config_change_network_notify_check_ison (NULL, NULL, NULL);
irc_config_change_network_notify_check_whois (NULL, NULL, NULL);
}
@@ -4055,4 +4130,10 @@ irc_config_free ()
weechat_hashtable_free (irc_config_hashtable_color_mirc_remap);
irc_config_hashtable_color_mirc_remap = NULL;
}
+
+ if (irc_config_hashtable_color_term_remap)
+ {
+ weechat_hashtable_free (irc_config_hashtable_color_term_remap);
+ irc_config_hashtable_color_term_remap = NULL;
+ }
}
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
index 8b0fdc1a2..333f8c712 100644
--- a/src/plugins/irc/irc-config.h
+++ b/src/plugins/irc/irc-config.h
@@ -186,6 +186,7 @@ extern struct t_config_option *irc_config_color_nick_prefixes;
extern struct t_config_option *irc_config_color_notice;
extern struct t_config_option *irc_config_color_reason_kick;
extern struct t_config_option *irc_config_color_reason_quit;
+extern struct t_config_option *irc_config_color_term_remap;
extern struct t_config_option *irc_config_color_topic_current;
extern struct t_config_option *irc_config_color_topic_new;
extern struct t_config_option *irc_config_color_topic_old;
@@ -211,6 +212,7 @@ extern struct t_config_option *irc_config_server_default[];
extern struct t_hashtable *irc_config_hashtable_display_join_message;
extern struct t_hashtable *irc_config_hashtable_nick_prefixes;
extern struct t_hashtable *irc_config_hashtable_color_mirc_remap;
+extern struct t_hashtable *irc_config_hashtable_color_term_remap;
extern char **irc_config_nicks_hide_password;
extern int irc_config_num_nicks_hide_password;