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

script: expose theme_register to python, perl, ruby, lua, tcl, javascript, php, guile

Add weechat.theme_register (name, overrides) to all eight script
languages. Each binding is a mechanical translation of the same
signature:

  - name:      string
  - overrides: language-native dict / hash / associative array of
               full_option_name -> value strings
  - returns:   pointer-as-string of the registered t_theme (empty
               string on failure)

Each binding converts the dict to a struct t_hashtable using the
existing per-language helper (weechat_python_dict_to_hashtable,
weechat_perl_hash_to_hashtable, weechat_ruby_hash_to_hashtable,
weechat_lua_tohashtable, weechat_tcl_dict_to_hashtable,
weechat_js_object_to_hashtable, weechat_php_array_to_hashtable,
weechat_guile_alist_to_hashtable), calls weechat_theme_register,
frees the temporary hashtable, and returns the result. The new
function is registered right after the config_* functions so the API
listing stays grouped by topic.

PHP also receives a new arginfo entry (string, array -> string) in
both weechat-php_arginfo.h and weechat-php_legacy_arginfo.h.

This is plumbing only - the underlying theme_register function is
already covered by tests/unit/core/test-core-theme.cpp
(TEST(CoreTheme, Register)). No script-side tests are added here.
This commit is contained in:
Sébastien Helleu
2026-05-27 07:45:42 +02:00
parent 20df571749
commit 55b224427d
13 changed files with 224 additions and 0 deletions
+26
View File
@@ -2001,6 +2001,31 @@ API_FUNC(config_unset_plugin)
API_RETURN_INT(rc);
}
API_FUNC(theme_register)
{
char *name;
PyObject *dict;
struct t_hashtable *hashtable;
const char *result;
API_INIT_FUNC(1, "theme_register", API_RETURN_EMPTY);
name = NULL;
dict = NULL;
if (!PyArg_ParseTuple (args, "sO", &name, &dict))
API_WRONG_ARGS(API_RETURN_EMPTY);
hashtable = weechat_python_dict_to_hashtable (dict,
WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING);
result = API_PTR2STR(weechat_theme_register (name, hashtable));
weechat_hashtable_free (hashtable);
API_RETURN_STRING(result);
}
API_FUNC(key_bind)
{
char *context;
@@ -5727,6 +5752,7 @@ PyMethodDef weechat_python_funcs[] =
API_DEF_FUNC(config_set_plugin),
API_DEF_FUNC(config_set_desc_plugin),
API_DEF_FUNC(config_unset_plugin),
API_DEF_FUNC(theme_register),
API_DEF_FUNC(key_bind),
API_DEF_FUNC(key_unbind),
API_DEF_FUNC(prefix),
+13
View File
@@ -1143,6 +1143,19 @@ def config_unset_plugin(option_name: str) -> int:
...
def theme_register(name: str, overrides: Dict[str, str]) -> str:
"""`theme_register in WeeChat plugin API reference <https://weechat.org/doc/weechat/api/#_theme_register>`_
::
# example
weechat.theme_register("light", {
"irc.color.input_nick": "cyan",
"irc.color.topic_old": "darkgray",
})
"""
...
def key_bind(context: str, keys: Dict[str, str]) -> int:
"""`key_bind in WeeChat plugin API reference <https://weechat.org/doc/weechat/api/#_key_bind>`_
::