From ff02ed8ea5e32a1016c710f4625145e3abcc062b Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 3 Jul 2023 07:42:05 -0700 Subject: til: make til_modlue_setup() nested usage aware When setting up a nested module, the HERMETIC modules shouldn't be considered as eligible nor should one be the preffered option (rtv). This uses the presence of a parent on the settings as a heuristic for if it's a nested scenario (no parent == root). When nested the default changes to "compose" from "rtv", and HERMETIC modules are omitted from the listed values. --- src/til.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/til.c b/src/til.c index c5c5eae..bf454ca 100644 --- a/src/til.c +++ b/src/til.c @@ -22,7 +22,8 @@ /* Copyright (C) 2016 Vito Caputo */ -#define DEFAULT_MODULE "rtv" +#define TIL_DEFAULT_ROOT_MODULE "rtv" +#define TIL_DEFAULT_NESTED_MODULE "compose" static til_threads_t *til_threads; @@ -468,19 +469,31 @@ int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting name = til_settings_get_value_by_idx(settings, 0, &setting); if (!name || !setting->desc) { - const char *values[nelems(modules) + 1] = {}; - const char *annotations[nelems(modules) + 1] = {}; - int r; + const char *values[nelems(modules) + 1] = {}; + const char *annotations[nelems(modules) + 1] = {}; + const til_settings_t *parent; + int r; + + parent = til_settings_get_parent(settings); for (unsigned i = 0, j = 0; i < nelems(modules); i++) { /* XXX: This only skips experimental modules when no module setting was pre-specified, * which allows accessing the experimental modules via the CLI without showing them * in the interactive setup where the desc provides the displayed list of values before - * the module setting gets added. It seems a big kludge-y and fragile, but works well + * the module setting gets added. It seems a bit kludge-y and fragile, but works well * enough for now to get at the experimental modules during testing/development. + * + * XXX: To enable using this in nested setup scenarios, where HERMETIC modules really + * shouldn't be listed, it now skips hermetic if settings->parent is set. That's + * used to imply this isn't the "root" module setup, hence hermetic is inappropriate. */ - if (!name && (modules[i]->flags & TIL_MODULE_EXPERIMENTAL)) - continue; + if (!name) { + if (modules[i]->flags & TIL_MODULE_EXPERIMENTAL) + continue; + + if (modules[i]->flags & (parent ? TIL_MODULE_HERMETIC : 0)) + continue; + } values[j] = modules[i]->name; annotations[j] = modules[i]->description; @@ -492,7 +505,7 @@ int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting .name = "Renderer module", .key = NULL, .regex = "[a-zA-Z0-9]+", - .preferred = DEFAULT_MODULE, + .preferred = parent ? TIL_DEFAULT_NESTED_MODULE : TIL_DEFAULT_ROOT_MODULE, .values = values, .annotations = annotations, .as_label = 1 -- cgit v1.2.3