mirror of
https://github.com/weechat/weechat.git
synced 2026-06-29 14:26:39 +02:00
irc: add option irc.color.term_remap (closes #2025)
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ New features::
|
||||
* core: display only version with command `/version`, add options `-o` and `-ol` in command `/upgrade`
|
||||
* core: add number of processes in command `/sys waitpid`
|
||||
* core, alias, trigger: allow wildcard in commands `/bar`, `/item`, `/proxy`, `/alias` and `/trigger` (issue #1956)
|
||||
* irc: add support of RGB colors in messages (issue #2025)
|
||||
* irc: add support of RGB colors in messages, add option irc.color.term_remap (issue #2025)
|
||||
* irc: add tags "nick_xxx" and "host_xxx" in all messages, including self and server messages
|
||||
* irc: add option irc.look.ignore_tag_messages (issue #989)
|
||||
* trigger: rename local variable "trigger_filter" to "filter" on monitor buffer (issue #2037)
|
||||
|
||||
+28
-18
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -877,6 +879,59 @@ irc_config_change_color_nick_prefixes (const void *pointer, void *data,
|
||||
weechat_bar_item_update ("input_prompt");
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ extern int irc_color_convert_term2irc (int color);
|
||||
IRC_COLOR_COLOR_STR "08,02" "bold_underline_yellow/blue" \
|
||||
IRC_COLOR_BOLD_STR IRC_COLOR_UNDERLINE_STR \
|
||||
"_normal_yellow/blue"
|
||||
#define STRING_IRC_COLOR_REMAPPED \
|
||||
#define STRING_IRC_COLOR_MIRC_REMAPPED \
|
||||
"test_" \
|
||||
IRC_COLOR_COLOR_STR "03,02" "remapped"
|
||||
#define STRING_IRC_COLOR_FG_ORANGE \
|
||||
@@ -78,6 +78,9 @@ extern int irc_color_convert_term2irc (int color);
|
||||
"test_" IRC_COLOR_HEX_COLOR_STR "FFFF00,8B008B" \
|
||||
"yellow/darkmagenta" \
|
||||
IRC_COLOR_HEX_COLOR_STR "_end"
|
||||
#define STRING_IRC_COLOR_TERM_REMAPPED \
|
||||
"test_" \
|
||||
IRC_COLOR_HEX_COLOR_STR "FFFF00,8B008B" "remapped"
|
||||
|
||||
/* tests on irc_color_encode(): command line -> IRC color */
|
||||
#define STRING_USER_BOLD \
|
||||
@@ -318,11 +321,11 @@ TEST(IrcColor, Decode)
|
||||
|
||||
/* color: 03,02 -> green (remapped via option irc.color.mirc_remap) */
|
||||
config_file_option_set (irc_config_color_mirc_remap, "3,2:green", 1);
|
||||
WEE_CHECK_DECODE("test_remapped", STRING_IRC_COLOR_REMAPPED, 0);
|
||||
WEE_CHECK_DECODE("test_remapped", STRING_IRC_COLOR_MIRC_REMAPPED, 0);
|
||||
snprintf (string, sizeof (string),
|
||||
"test_%sremapped",
|
||||
gui_color_get_custom ("|green"));
|
||||
WEE_CHECK_DECODE(string, STRING_IRC_COLOR_REMAPPED, 1);
|
||||
WEE_CHECK_DECODE(string, STRING_IRC_COLOR_MIRC_REMAPPED, 1);
|
||||
config_file_option_unset (irc_config_color_mirc_remap);
|
||||
|
||||
/* color: hex 0xFF7F00 (orange / 208) */
|
||||
@@ -342,6 +345,18 @@ TEST(IrcColor, Decode)
|
||||
gui_color_get_custom ("|11,90"),
|
||||
gui_color_get_custom ("resetcolor"));
|
||||
WEE_CHECK_DECODE(string, STRING_IRC_COLOR_FG_YELLOW_BG_DARKMAGENTA, 1);
|
||||
|
||||
/*
|
||||
* color: hex 0xFFFF00 (yellow / 11) on 0x8B008B (dark magenta / 90)
|
||||
* -> blue (remapped via option irc.color.term_remap)
|
||||
*/
|
||||
config_file_option_set (irc_config_color_term_remap, "11,90:blue", 1);
|
||||
WEE_CHECK_DECODE("test_remapped", STRING_IRC_COLOR_TERM_REMAPPED, 0);
|
||||
snprintf (string, sizeof (string),
|
||||
"test_%sremapped",
|
||||
gui_color_get_custom ("|blue"));
|
||||
WEE_CHECK_DECODE(string, STRING_IRC_COLOR_TERM_REMAPPED, 1);
|
||||
config_file_option_unset (irc_config_color_term_remap);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user