1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 18:23:13 +02:00

core: add support of date and tags in messages displayed in buffers with free content, add function printf_y_date_tags (closes #1746)

This commit is contained in:
Sébastien Helleu
2022-01-30 11:41:06 +01:00
parent bf3241208b
commit 9259442dbf
43 changed files with 752 additions and 60 deletions
+22
View File
@@ -1922,6 +1922,27 @@ weechat_guile_api_print_y (SCM buffer, SCM y, SCM message)
API_RETURN_OK;
}
SCM
weechat_guile_api_print_y_date_tags (SCM buffer, SCM y, SCM date, SCM tags,
SCM message)
{
API_INIT_FUNC(1, "print_y_date_tags", API_RETURN_ERROR);
if (!scm_is_string (buffer) || !scm_is_integer (y)
|| !scm_is_integer (date) || !scm_is_string (tags)
|| !scm_is_string (message))
API_WRONG_ARGS(API_RETURN_ERROR);
plugin_script_api_printf_y_date_tags (weechat_guile_plugin,
guile_current_script,
API_STR2PTR(API_SCM_TO_STRING(buffer)),
scm_to_int (y),
scm_to_int (date),
API_SCM_TO_STRING(tags),
"%s", API_SCM_TO_STRING(message));
API_RETURN_OK;
}
SCM
weechat_guile_api_log_print (SCM message)
{
@@ -5121,6 +5142,7 @@ weechat_guile_api_module_init (void *data)
API_DEF_FUNC(print, 2);
API_DEF_FUNC(print_date_tags, 4);
API_DEF_FUNC(print_y, 3);
API_DEF_FUNC(print_y_date_tags, 5);
API_DEF_FUNC(log_print, 1);
API_DEF_FUNC(hook_command, 7);
API_DEF_FUNC(hook_completion, 4);
+24
View File
@@ -1812,6 +1812,29 @@ API_FUNC(print_y)
API_RETURN_OK;
}
API_FUNC(print_y_date_tags)
{
int y, date;
API_INIT_FUNC(1, "print_y_date_tags", "siiss", API_RETURN_ERROR);
v8::String::Utf8Value buffer(args[0]);
y = args[1]->IntegerValue();
date = args[2]->IntegerValue();
v8::String::Utf8Value tags(args[3]);
v8::String::Utf8Value message(args[4]);
plugin_script_api_printf_y_date_tags (weechat_js_plugin,
js_current_script,
(struct t_gui_buffer *)API_STR2PTR(*buffer),
y,
date,
*tags,
"%s", *message);
API_RETURN_OK;
}
API_FUNC(log_print)
{
API_INIT_FUNC(1, "log_print", "s", API_RETURN_ERROR);
@@ -5051,6 +5074,7 @@ WeechatJsV8::loadLibs()
API_DEF_FUNC(print);
API_DEF_FUNC(print_date_tags);
API_DEF_FUNC(print_y);
API_DEF_FUNC(print_y_date_tags);
API_DEF_FUNC(log_print);
API_DEF_FUNC(hook_command);
API_DEF_FUNC(hook_completion);
+27
View File
@@ -2024,6 +2024,32 @@ API_FUNC(print_y)
API_RETURN_OK;
}
API_FUNC(print_y_date_tags)
{
const char *buffer, *tags, *message;
int y, date;
API_INIT_FUNC(1, "print_y_date_tags", API_RETURN_ERROR);
if (lua_gettop (L) < 5)
API_WRONG_ARGS(API_RETURN_ERROR);
buffer = lua_tostring (L, -5);
y = lua_tonumber (L, -4);
date = lua_tonumber (L, -3);
tags = lua_tostring (L, -2);
message = lua_tostring (L, -1);
plugin_script_api_printf_y_date_tags (weechat_lua_plugin,
lua_current_script,
API_STR2PTR(buffer),
y,
date,
tags,
"%s", message);
API_RETURN_OK;
}
API_FUNC(log_print)
{
const char *message;
@@ -5415,6 +5441,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
API_DEF_FUNC(print),
API_DEF_FUNC(print_date_tags),
API_DEF_FUNC(print_y),
API_DEF_FUNC(print_y_date_tags),
API_DEF_FUNC(log_print),
API_DEF_FUNC(hook_command),
API_DEF_FUNC(hook_completion),
+25
View File
@@ -1937,6 +1937,30 @@ API_FUNC(print_y)
API_RETURN_OK;
}
API_FUNC(print_y_date_tags)
{
char *buffer, *tags, *message;
dXSARGS;
API_INIT_FUNC(1, "print_y_date_tags", API_RETURN_ERROR);
if (items < 5)
API_WRONG_ARGS(API_RETURN_ERROR);
buffer = SvPV_nolen (ST (0));
tags = SvPV_nolen (ST (3));
message = SvPV_nolen (ST (4));
plugin_script_api_printf_y_date_tags (weechat_perl_plugin,
perl_current_script,
API_STR2PTR(buffer),
SvIV (ST (1)),
SvIV (ST (2)),
tags,
"%s", message);
API_RETURN_OK;
}
API_FUNC(log_print)
{
dXSARGS;
@@ -5370,6 +5394,7 @@ weechat_perl_api_init (pTHX)
API_DEF_FUNC(print);
API_DEF_FUNC(print_date_tags);
API_DEF_FUNC(print_y);
API_DEF_FUNC(print_y_date_tags);
API_DEF_FUNC(log_print);
API_DEF_FUNC(hook_command);
API_DEF_FUNC(hook_completion);
+32
View File
@@ -2097,6 +2097,38 @@ API_FUNC(print_y)
API_RETURN_OK;
}
API_FUNC(print_y_date_tags)
{
zend_string *z_buffer, *z_tags, *z_message;
zend_long z_y, z_date;
struct t_gui_buffer *buffer;
int y;
time_t date;
char *tags, *message;
API_INIT_FUNC(1, "print_y_date_tags", API_RETURN_ERROR);
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SllSS", &z_buffer, &z_y,
&z_date, &z_tags, &z_message) == FAILURE)
API_WRONG_ARGS(API_RETURN_ERROR);
buffer = (struct t_gui_buffer *)API_STR2PTR(ZSTR_VAL(z_buffer));
y = (int)z_y;
date = (time_t)z_date;
tags = ZSTR_VAL(z_tags);
message = ZSTR_VAL(z_message);
plugin_script_api_printf_y_date_tags (weechat_php_plugin,
php_current_script,
buffer,
y,
date,
(const char *)tags,
"%s",
message);
API_RETURN_OK;
}
API_FUNC(log_print)
{
zend_string *z_message;
+1
View File
@@ -126,6 +126,7 @@ PHP_FUNCTION(weechat_color);
PHP_FUNCTION(weechat_print);
PHP_FUNCTION(weechat_print_date_tags);
PHP_FUNCTION(weechat_print_y);
PHP_FUNCTION(weechat_print_y_date_tags);
PHP_FUNCTION(weechat_log_print);
PHP_FUNCTION(weechat_hook_command);
PHP_FUNCTION(weechat_hook_completion);
+1
View File
@@ -184,6 +184,7 @@ const zend_function_entry weechat_functions[] = {
PHP_FE(weechat_print, arginfo_weechat_print)
PHP_FE(weechat_print_date_tags, arginfo_weechat_print_date_tags)
PHP_FE(weechat_print_y, arginfo_weechat_print_y)
PHP_FE(weechat_print_y_date_tags, arginfo_weechat_print_y_date_tags)
PHP_FE(weechat_log_print, arginfo_weechat_log_print)
PHP_FE(weechat_hook_command, arginfo_weechat_hook_command)
PHP_FE(weechat_hook_completion, arginfo_weechat_hook_completion)
+1
View File
@@ -87,6 +87,7 @@ function weechat_color(): mixed {}
function weechat_print(): mixed {}
function weechat_print_date_tags(): mixed {}
function weechat_print_y(): mixed {}
function weechat_print_y_date_tags(): mixed {}
function weechat_log_print(): mixed {}
function weechat_hook_command(): mixed {}
function weechat_hook_completion(): mixed {}
+2
View File
@@ -164,6 +164,8 @@ ZEND_END_ARG_INFO()
#define arginfo_weechat_print_y arginfo_weechat_register
#define arginfo_weechat_print_y_date_tags arginfo_weechat_register
#define arginfo_weechat_log_print arginfo_weechat_register
#define arginfo_weechat_hook_command arginfo_weechat_register
@@ -164,6 +164,8 @@ ZEND_END_ARG_INFO()
#define arginfo_weechat_print_y arginfo_weechat_register
#define arginfo_weechat_print_y_date_tags arginfo_weechat_register
#define arginfo_weechat_log_print arginfo_weechat_register
#define arginfo_weechat_hook_command arginfo_weechat_register
+28 -1
View File
@@ -326,7 +326,7 @@ plugin_script_api_printf (struct t_weechat_plugin *weechat_plugin,
}
/*
* Prints a message with optional date and tags.
* Prints a message, with optional date and tags.
*/
void
@@ -377,6 +377,33 @@ plugin_script_api_printf_y (struct t_weechat_plugin *weechat_plugin,
free (vbuffer);
}
/*
* Prints a message on a buffer with free content, with optional date and tags.
*/
void
plugin_script_api_printf_y_date_tags (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer, int y,
time_t date, const char *tags,
const char *format, ...)
{
char *buf2;
weechat_va_format (format);
if (!vbuffer)
return;
buf2 = (script && script->charset && script->charset[0]) ?
weechat_iconv_to_internal (script->charset, vbuffer) : NULL;
weechat_printf_y_date_tags (buffer, y, date, tags,
"%s", (buf2) ? buf2 : vbuffer);
if (buf2)
free (buf2);
free (vbuffer);
}
/*
* Prints a message in WeeChat log file.
*/
+6
View File
@@ -119,6 +119,12 @@ extern void plugin_script_api_printf_y (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
int y, const char *format, ...);
extern void plugin_script_api_printf_y_date_tags (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
int y, time_t date,
const char *tags,
const char *format, ...);
extern void plugin_script_api_log_printf (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *format, ...);
+1 -1
View File
@@ -772,7 +772,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
new_plugin->prefix = &plugin_api_prefix;
new_plugin->color = &plugin_api_color;
new_plugin->printf_date_tags = &gui_chat_printf_date_tags;
new_plugin->printf_y = &gui_chat_printf_y;
new_plugin->printf_y_date_tags = &gui_chat_printf_y_date_tags;
new_plugin->log_printf = &log_printf;
new_plugin->hook_command = &hook_command;
+26
View File
@@ -1930,6 +1930,31 @@ API_FUNC(prnt_y)
API_RETURN_OK;
}
API_FUNC(prnt_y_date_tags)
{
char *buffer, *tags, *message;
int y, date;
API_INIT_FUNC(1, "prnt_y_date_tags", API_RETURN_ERROR);
buffer = NULL;
y = 0;
date = 0;
tags = NULL;
message = NULL;
if (!PyArg_ParseTuple (args, "siiss", &buffer, &y, &date, &tags, &message))
API_WRONG_ARGS(API_RETURN_ERROR);
plugin_script_api_printf_y_date_tags (weechat_python_plugin,
python_current_script,
API_STR2PTR(buffer),
y,
date,
tags,
"%s", message);
API_RETURN_OK;
}
API_FUNC(log_print)
{
char *message;
@@ -5279,6 +5304,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(prnt),
API_DEF_FUNC(prnt_date_tags),
API_DEF_FUNC(prnt_y),
API_DEF_FUNC(prnt_y_date_tags),
API_DEF_FUNC(log_print),
API_DEF_FUNC(hook_command),
API_DEF_FUNC(hook_completion),
+5
View File
@@ -444,6 +444,11 @@ def prnt_y(buffer: str, y: int, message: str) -> int:
...
def prnt_y_date_tags(buffer: str, y: int, date: int, tags: str, message: str) -> int:
"""`prnt_y_date_tags in WeeChat plugin API reference <https://weechat.org/doc/api#_prnt_y_date_tags>`_"""
...
def log_print(message: str) -> int:
"""`log_print in WeeChat plugin API reference <https://weechat.org/doc/api#_log_print>`_"""
...
+37
View File
@@ -2387,6 +2387,42 @@ weechat_ruby_api_print_y (VALUE class, VALUE buffer, VALUE y, VALUE message)
API_RETURN_OK;
}
static VALUE
weechat_ruby_api_print_y_date_tags (VALUE class, VALUE buffer, VALUE y,
VALUE date, VALUE tags, VALUE message)
{
char *c_buffer, *c_tags, *c_message;
int c_y;
time_t c_date;
API_INIT_FUNC(1, "print_y_date_tags", API_RETURN_ERROR);
if (NIL_P (buffer) || NIL_P (y) || NIL_P (date) || NIL_P (tags)
|| NIL_P (message))
API_WRONG_ARGS(API_RETURN_ERROR);
Check_Type (buffer, T_STRING);
CHECK_INTEGER(y);
CHECK_INTEGER(date);
Check_Type (tags, T_STRING);
Check_Type (message, T_STRING);
c_buffer = StringValuePtr (buffer);
c_y = NUM2INT (y);
c_date = NUM2ULONG (date);
c_tags = StringValuePtr (tags);
c_message = StringValuePtr (message);
plugin_script_api_printf_y_date_tags (weechat_ruby_plugin,
ruby_current_script,
API_STR2PTR(c_buffer),
c_y,
c_date,
c_tags,
"%s", c_message);
API_RETURN_OK;
}
static VALUE
weechat_ruby_api_log_print (VALUE class, VALUE message)
{
@@ -6540,6 +6576,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
API_DEF_FUNC(print, 2);
API_DEF_FUNC(print_date_tags, 4);
API_DEF_FUNC(print_y, 3);
API_DEF_FUNC(print_y_date_tags, 5);
API_DEF_FUNC(log_print, 1);
API_DEF_FUNC(hook_command, 7);
API_DEF_FUNC(hook_completion, 4);
+35 -3
View File
@@ -2134,13 +2134,13 @@ API_FUNC(print_date_tags)
{
Tcl_Obj *objp;
char *buffer, *tags, *message;
int i, tdate;
int i, date;
API_INIT_FUNC(1, "print_date_tags", API_RETURN_ERROR);
if (objc < 5)
API_WRONG_ARGS(API_RETURN_ERROR);
if (Tcl_GetIntFromObj (interp, objv[2], &tdate) != TCL_OK)
if (Tcl_GetIntFromObj (interp, objv[2], &date) != TCL_OK)
API_WRONG_ARGS(API_RETURN_ERROR);
buffer = Tcl_GetStringFromObj (objv[1], &i);
@@ -2150,7 +2150,7 @@ API_FUNC(print_date_tags)
plugin_script_api_printf_date_tags (weechat_tcl_plugin,
tcl_current_script,
API_STR2PTR(buffer),
tdate,
date,
tags,
"%s", message);
@@ -2182,6 +2182,37 @@ API_FUNC(print_y)
API_RETURN_OK;
}
API_FUNC(print_y_date_tags)
{
Tcl_Obj *objp;
char *buffer, *tags, *message;
int i, y, date;
API_INIT_FUNC(1, "print_y_date_tags", API_RETURN_ERROR);
if (objc < 6)
API_WRONG_ARGS(API_RETURN_ERROR);
if (Tcl_GetIntFromObj (interp, objv[2], &y) != TCL_OK)
API_WRONG_ARGS(API_RETURN_ERROR);
if (Tcl_GetIntFromObj (interp, objv[3], &date) != TCL_OK)
API_WRONG_ARGS(API_RETURN_ERROR);
buffer = Tcl_GetStringFromObj (objv[1], &i);
tags = Tcl_GetStringFromObj (objv[4], &i);
message = Tcl_GetStringFromObj (objv[5], &i);
plugin_script_api_printf_y_date_tags (weechat_tcl_plugin,
tcl_current_script,
API_STR2PTR(buffer),
y,
date,
tags,
"%s", message);
API_RETURN_OK;
}
API_FUNC(log_print)
{
Tcl_Obj *objp;
@@ -5843,6 +5874,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
API_DEF_FUNC(print);
API_DEF_FUNC(print_date_tags);
API_DEF_FUNC(print_y);
API_DEF_FUNC(print_y_date_tags);
API_DEF_FUNC(log_print);
API_DEF_FUNC(hook_command);
API_DEF_FUNC(hook_completion);
+10 -4
View File
@@ -68,7 +68,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20211106-01"
#define WEECHAT_PLUGIN_API_VERSION "20220130-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -653,8 +653,9 @@ struct t_weechat_plugin
const char *(*color) (const char *color_name);
void (*printf_date_tags) (struct t_gui_buffer *buffer, time_t date,
const char *tags, const char *message, ...);
void (*printf_y) (struct t_gui_buffer *buffer, int y,
const char *message, ...);
void (*printf_y_date_tags) (struct t_gui_buffer *buffer, int y,
time_t date, const char *tags,
const char *message, ...);
void (*log_printf) (const char *message, ...);
/* hooks */
@@ -1689,7 +1690,12 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
(weechat_plugin->printf_date_tags)(__buffer, __date, __tags, \
__message, ##__argz)
#define weechat_printf_y(__buffer, __y, __message, __argz...) \
(weechat_plugin->printf_y)(__buffer, __y, __message, ##__argz)
(weechat_plugin->printf_y_date_tags)(__buffer, __y, 0, NULL, \
__message, ##__argz)
#define weechat_printf_y_date_tags(__buffer, __y, __date, __tags, \
__message, __argz...) \
(weechat_plugin->printf_y_date_tags)(__buffer, __y, __date, __tags, \
__message, ##__argz)
#define weechat_log_printf(__message, __argz...) \
(weechat_plugin->log_printf)(__message, ##__argz)