api: add modifier "color_encode_ansi" (issue #528)

v2.8-utf8proc
Sébastien Helleu 2019-09-29 21:11:24 +02:00
parent 90f711a965
commit e386965aba
6 changed files with 50 additions and 1 deletions

View File

@ -22,6 +22,7 @@ New features::
* core: add length of string (number of chars and on screen) in evaluation of expressions with "length:xxx" and "lengthscr:xxx"
* core: add calculation of expression in evaluation of expressions with "calc:xxx" (issue #997)
* api: add modifier "color_encode_ansi" (issue #528)
* irc: add "user" in output of irc_message_parse (issue #136)
* irc: add options irc.color.message_kick and irc.color.reason_kick (issue #683, issue #684)
* script: add options "-ol" and "-il" in command /script to send translated string with list of scripts loaded, display "No scripts loaded" if no scripts are loaded

View File

@ -11375,6 +11375,12 @@ List of modifiers defined by WeeChat and plugins that can be used:
"1" to keep colors, "0" to remove colors |
Any string. |
String with ANSI colors converted to WeeChat colors (or ANSI colors removed).
| [[hook_modifier_color_encode_ansi]] color_encode_ansi +
_(WeeChat ≥ 2.7)_ |
- |
Any string. |
String with WeeChat colors converted to ANSI colors.
|===
C example:

View File

@ -11619,6 +11619,12 @@ utilisés :
Toute chaîne. |
Chaîne avec les couleurs ANSI converties en couleurs WeeChat (ou avec les
couleurs ANSI supprimées).
| [[hook_modifier_color_encode_ansi]] color_encode_ansi +
_(WeeChat ≥ 2.7)_ |
- |
Toute chaîne. |
Chaîne avec les couleurs WeeChat converties en couleurs ANSI.
|===
Exemple en C :

View File

@ -11835,6 +11835,13 @@ List of modifiers defined by WeeChat and plugins that can be used:
"1" per mantenere i colori, "0" per rimuovere i colori |
Qualsiasi stringa. |
String with ANSI colors converted to WeeChat colors (or ANSI colors removed).
// TRANSLATION MISSING
| [[hook_modifier_color_encode_ansi]] color_encode_ansi +
_(WeeChat ≥ 2.7)_ |
- |
Any string. |
String with WeeChat colors converted to ANSI colors.
|===
Esempio in C:

View File

@ -11347,6 +11347,13 @@ WeeChat とプラグインが定義する修飾子のリスト:
色を保持する場合は "1"、削除する場合は "0" |
任意の文字列 |
WeeChat 色コードに変換された ANSI 色コードを含む (または ANSI 色コードを削除された) 文字列
// TRANSLATION MISSING
| [[hook_modifier_color_encode_ansi]] color_encode_ansi +
_(WeeChat バージョン 2.7 以上で利用可)_ |
- |
任意の文字列 |
String with WeeChat colors converted to ANSI colors.
|===
C 言語での使用例:

View File

@ -352,7 +352,8 @@ plugin_api_command (struct t_weechat_plugin *plugin,
}
/*
* Modifier to decode ANSI colors.
* Modifier to decode ANSI colors: convert ANSI color codes to WeeChat colors
* (or removes them)
*/
char *
@ -372,6 +373,25 @@ plugin_api_modifier_color_decode_ansi_cb (const void *pointer, void *data,
1: 0);
}
/*
* Modifier to encode ANSI colors: convert WeeChat colors to ANSI color codes
*/
char *
plugin_api_modifier_color_encode_ansi_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;
(void) modifier_data;
return gui_color_encode_ansi (string);
}
/*
* Moves item pointer to next item in an infolist.
*
@ -521,6 +541,8 @@ plugin_api_init ()
/* WeeChat core modifiers */
hook_modifier (NULL, "color_decode_ansi",
&plugin_api_modifier_color_decode_ansi_cb, NULL, NULL);
hook_modifier (NULL, "color_encode_ansi",
&plugin_api_modifier_color_encode_ansi_cb, NULL, NULL);
/* WeeChat core info/infolist hooks */
plugin_api_info_init ();