From 1ab62e37cb5bfb774b064a44818cce00259009b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 10 Mar 2024 09:31:32 +0100 Subject: [PATCH] api: add modifier "color_decode" to decode WeeChat colors with a replacement string --- ChangeLog.adoc | 1 + doc/en/weechat_plugin_api.en.adoc | 6 ++++++ doc/fr/weechat_plugin_api.fr.adoc | 6 ++++++ doc/it/weechat_plugin_api.it.adoc | 7 +++++++ doc/ja/weechat_plugin_api.ja.adoc | 7 +++++++ doc/sr/weechat_plugin_api.sr.adoc | 7 +++++++ src/plugins/plugin-api.c | 21 +++++++++++++++++++++ 7 files changed, 55 insertions(+) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index c6f3a46b3..3961a6644 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -21,6 +21,7 @@ New features:: * core: add option `-s` in command `/command` to execute multiple commands separated by semicolons * core: allow case insensitive search of partial buffer name with `(?i)name` in command `/buffer` * core: use function util_strftimeval in evaluation of expression `date:xxx` + * api: add modifier "color_decode" to decode WeeChat colors with a replacement string * api: use whole replacement string instead of first char in function string_remove_color * api: add functions config_option_get_{string|pointer} and config_{boolean|integer|string|color|enum}_inherited in scripting API * api: add info "plugin_loaded" diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 99e6595c3..5f47df843 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -13286,6 +13286,12 @@ List of modifiers defined by WeeChat and plugins that can be used: | String with IRC tag value unescaped, see https://ircv3.net/specs/extensions/message-tags#escaping-values[this page ^↗^^]. +| [[hook_modifier_color_decode]] color_decode | 4.3.0 +| Replacement string for colors removed +| Any string. +| String with WeeChat colors converted to a replacement string + (colors stripped if the replacement string is empty). + | [[hook_modifier_color_decode_ansi]] color_decode_ansi | 1.0 | "1" to keep colors, "0" to remove colors | Any string. diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index e3120718b..ebfd68376 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -13574,6 +13574,12 @@ utilisés : | Chaîne avec la valeur de l'étiquette IRC sans échappements, voir https://ircv3.net/specs/extensions/message-tags#escaping-values[cette page ^↗^^]. +| [[hook_modifier_color_decode]] color_decode | 4.3.0 +| Chaîne de remplacement pour les couleurs supprimées +| Toute chaîne. +| Chaîne avec les couleurs WeeChat converties vers la chaîne de remplacement + (couleurs supprimées si la chaîne de remplacement est vide). + | [[hook_modifier_color_decode_ansi]] color_decode_ansi | 1.0 | "1" pour garder les couleurs, "0" pour les supprimer | Toute chaîne. diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index a0058a13e..f18010656 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -13883,6 +13883,13 @@ List of modifiers defined by WeeChat and plugins that can be used: | String with IRC tag value unescaped, see https://ircv3.net/specs/extensions/message-tags#escaping-values[this page ^↗^^]. +// TRANSLATION MISSING +| [[hook_modifier_color_decode]] color_decode | 4.3.0 +| Replacement string for colors removed +| Any string. +| String with WeeChat colors converted to a replacement string + (colors stripped if the replacement string is empty). + // TRANSLATION MISSING | [[hook_modifier_color_decode_ansi]] color_decode_ansi | 1.0 | "1" per mantenere i colori, "0" per rimuovere i colori diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 71c038796..1b7189d77 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -13471,6 +13471,13 @@ WeeChat とプラグインが定義する修飾子のリスト: | String with IRC tag value unescaped, see https://ircv3.net/specs/extensions/message-tags#escaping-values[this page ^↗^^]. +// TRANSLATION MISSING +| [[hook_modifier_color_decode]] color_decode | 4.3.0 +| Replacement string for colors removed +| Any string. +| String with WeeChat colors converted to a replacement string + (colors stripped if the replacement string is empty). + | [[hook_modifier_color_decode_ansi]] color_decode_ansi | 1.0 | 色を保持する場合は "1"、削除する場合は "0" | 任意の文字列 diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index 6ab324e67..4fef6bb08 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -12930,6 +12930,13 @@ char *weechat_hook_modifier_exec (const char *modifier, | Стринг са неозначеном вредности IRC ознаке, погледајте https://ircv3.net/specs/extensions/message-tags#escaping-values[ову страницу ^↗^^]. +// TRANSLATION MISSING +| [[hook_modifier_color_decode]] color_decode | 4.3.0 +| Replacement string for colors removed +| Any string. +| String with WeeChat colors converted to a replacement string + (colors stripped if the replacement string is empty). + | [[hook_modifier_color_decode_ansi]] color_decode_ansi | 1.0 | "1" да се боје задрже, "0" да се боје уклоне | Било који стринг. diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index e2168301e..9f1797874 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -450,6 +450,25 @@ plugin_api_command (struct t_weechat_plugin *plugin, return plugin_api_command_options (plugin, buffer, command, NULL); } +/* + * Modifier callback: decodes WeeChat colors: converts WeeChat color codes to + * WeeChat a replacement string. + */ + +char * +plugin_api_modifier_color_decode_cb (const void *pointer, void *data, + const char *modifier, + const char *modifier_data, + const char *string) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) modifier; + + return gui_color_decode (string, modifier_data); +} + /* * Modifier callback: decodes ANSI colors: converts ANSI color codes to WeeChat * colors (or removes them). @@ -681,6 +700,8 @@ void plugin_api_init () { /* WeeChat core modifiers */ + hook_modifier (NULL, "color_decode", + &plugin_api_modifier_color_decode_cb, NULL, NULL); hook_modifier (NULL, "color_decode_ansi", &plugin_api_modifier_color_decode_ansi_cb, NULL, NULL); hook_modifier (NULL, "color_encode_ansi",