command: add a change-list command
Requested. See manpage additions. The main reason why this goes through the trouble to keep the action/operation parameter separate is so that we don't expose some option parser implementation details to the command (although that is a relatively weak reason), and also to make it more different from the "set" command, which can't support this type of option as it goes through the property layer. Fixes #5435.
This commit is contained in:
1 parent
9e64b93822
commit
0d359879c9
5 files changed
+53
No files matched your search
@@ -732,6 +732,23 @@ Input Commands that are Possibly Subject to Change
|
||||
``load-script "<path>"``
|
||||
Load a script, similar to the ``--script`` option.
|
||||
|
||||
``change-list "<option>" "<operation>" "<value>"``
|
||||
This command changes list options as described in `List Options`_. The
|
||||
``<option>`` parameter is the normal option name, while ``<operation>`` is
|
||||
the suffix or action used on the option.
|
||||
|
||||
Some operations take no value, but the command still requires the value
|
||||
parameter. In these cases, the value must be an empty string.
|
||||
|
||||
.. admonition:: Example
|
||||
|
||||
``change-list glsl-shaders append file.glsl``
|
||||
|
||||
Add a filename to the ``glsl-shaders`` list. The command line
|
||||
equivalent is ``--glsl-shaders-append=file.glsl`` or alternatively
|
||||
``--glsl-shader=file.glsl``.
|
||||
|
||||
|
||||
Undocumented commands: ``tv-last-channel`` (TV/DVB only),
|
||||
``ao-reload`` (experimental/internal).
|
||||
|
||||
|
||||
@@ -448,6 +448,9 @@ aliases for the proper option with ``-append`` action. For example,
|
||||
|
||||
Some options only support a subset of the above.
|
||||
|
||||
Options of this type can be changed at runtime using the ``change-list``
|
||||
command, which takes the suffix as separate operation parameter.
|
||||
|
||||
Playing DVDs
|
||||
------------
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ const struct mp_cmd_def mp_cmds[] = {
|
||||
{ MP_CMD_RUN, "run", { ARG_STRING, ARG_STRING }, .vararg = true },
|
||||
|
||||
{ MP_CMD_SET, "set", { ARG_STRING, ARG_STRING } },
|
||||
{ MP_CMD_CHANGE_LIST, "change-list", { ARG_STRING, ARG_STRING, ARG_STRING } },
|
||||
{ MP_CMD_ADD, "add", { ARG_STRING, OARG_DOUBLE(1) },
|
||||
.allow_auto_repeat = true,
|
||||
.scalable = true,
|
||||
|
||||
@@ -65,6 +65,7 @@ enum mp_command_type {
|
||||
MP_CMD_SUB_REMOVE,
|
||||
MP_CMD_SUB_RELOAD,
|
||||
MP_CMD_SET,
|
||||
MP_CMD_CHANGE_LIST,
|
||||
MP_CMD_PRINT_TEXT,
|
||||
MP_CMD_SHOW_TEXT,
|
||||
MP_CMD_EXPAND_TEXT,
|
||||
|
||||
@@ -4918,6 +4918,37 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
|
||||
break;
|
||||
}
|
||||
|
||||
case MP_CMD_CHANGE_LIST: {
|
||||
char *name = cmd->args[0].v.s;
|
||||
char *op = cmd->args[1].v.s;
|
||||
char *value = cmd->args[2].v.s;
|
||||
struct m_config_option *co = m_config_get_co(mpctx->mconfig, bstr0(name));
|
||||
if (!co) {
|
||||
set_osd_msg(mpctx, osdl, osd_duration, "Unknown option: '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
const struct m_option_type *type = co->opt->type;
|
||||
bool found = false;
|
||||
for (int i = 0; type->actions && type->actions[i].name; i++) {
|
||||
const struct m_option_action *action = &type->actions[i];
|
||||
if (strcmp(action->name, op) == 0)
|
||||
found = true;
|
||||
}
|
||||
if (!found) {
|
||||
set_osd_msg(mpctx, osdl, osd_duration, "Unknown action: '%s'", op);
|
||||
return -1;
|
||||
}
|
||||
char *optname = mp_tprintf(80, "%s-%s", name, op); // the dirty truth
|
||||
int r = m_config_set_option_cli(mpctx->mconfig, bstr0(optname),
|
||||
bstr0(value), M_SETOPT_RUNTIME);
|
||||
if (r < 0) {
|
||||
set_osd_msg(mpctx, osdl, osd_duration,
|
||||
"Failed setting option: '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MP_CMD_ADD:
|
||||
case MP_CMD_CYCLE:
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user