From ae2384bce0e8dc55b1f8892e85f330aa872aaa7a Mon Sep 17 00:00:00 2001 From: zenodity <262299845+zenodity@users.noreply.github.com> Date: Sat, 7 Mar 2026 11:27:52 +0000 Subject: [PATCH] player/command: add default-value/choices arg fields to command-list Add optional 'default-value' and 'choices' fields where appropriate for command arguments in the 'command-list' property. Update documentation to reflect the command-list schema change. DOCS/interface-changes/command-list: add changes --- DOCS/interface-changes/command-list.txt | 1 + DOCS/man/input.rst | 9 ++++++--- player/command.c | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 DOCS/interface-changes/command-list.txt diff --git a/DOCS/interface-changes/command-list.txt b/DOCS/interface-changes/command-list.txt new file mode 100644 index 0000000000..be74e2e627 --- /dev/null +++ b/DOCS/interface-changes/command-list.txt @@ -0,0 +1 @@ +'command-list' now also returns a default value and available choices where applicable for each command argument. \ No newline at end of file diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index b655b5ed4e..a2553d2aef 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -4209,9 +4209,12 @@ Property list "vararg" MPV_FORMAT_FLAG "args" MPV_FORMAT_NODE_ARRAY MPV_FORMAT_NODE_MAP - "name" MPV_FORMAT_STRING - "type" MPV_FORMAT_STRING - "optional" MPV_FORMAT_FLAG + "name" MPV_FORMAT_STRING + "type" MPV_FORMAT_STRING + "optional" MPV_FORMAT_FLAG + "default-value" MPV_FORMAT_NODE (optional, value of "type") + "choices" MPV_FORMAT_NODE_ARRAY (optional) + MPV_FORMAT_STRING ``input-bindings`` The list of current input key bindings. This returns an array of maps, diff --git a/player/command.c b/player/command.c index 42915dc404..72cae252d4 100644 --- a/player/command.c +++ b/player/command.c @@ -4035,6 +4035,29 @@ static int mp_property_commands(void *ctx, struct m_property *prop, node_map_add_string(ae, "name", a->name); node_map_add_string(ae, "type", a->type->name); node_map_add_flag(ae, "optional", a->flags & MP_CMD_OPT_ARG); + if (a->type == &m_option_type_choice || + a->type == &m_option_type_flags) { + const struct m_opt_choice_alternatives *alt = a->priv; + if (alt) { + if (a->defval) { + const int ival = *(const int *)a->defval; + const char *val = m_opt_choice_str_def(alt, ival, NULL); + if (val) + node_map_add_string(ae, "default-value", val); + } + struct mpv_node *choices = + node_map_add(ae, "choices", MPV_FORMAT_NODE_ARRAY); + for (int j = 0; alt[j].name; j++) { + struct mpv_node *ce = node_array_add(choices, MPV_FORMAT_NONE); + ce->format = MPV_FORMAT_STRING; + ce->u.string = talloc_strdup(choices->u.list, alt[j].name); + } + } + } else if (a->defval) { + struct mpv_node *def = + node_map_add(ae, "default-value", MPV_FORMAT_NONE); + m_option_get_node(a, ae->u.list, def, (void *)a->defval); + } } node_map_add_flag(entry, "vararg", cmd->vararg);