player/command: add "del" command

This commit is contained in:
rcombs 2022-12-16 15:01:54 -06:00
parent e1815789f7
commit 04241ab731
2 changed files with 27 additions and 0 deletions

View File

@ -334,6 +334,9 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_).
``set <name> <value>``
Set the given property or option to the given value.
``del <name>``
Delete the given property. Most properties cannot be deleted.
``add <name> [<value>]``
Add the given value to the property or option. On overflow or underflow,
clamp the property to the maximum. If ``<value>`` is omitted, assume ``1``.

View File

@ -4882,6 +4882,29 @@ static void cmd_set(void *p)
M_PROPERTY_SET_STRING, cmd->args[1].v.s);
}
static void cmd_del(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
const char *name = cmd->args[0].v.s;
int osdl = cmd->msg_osd ? 1 : OSD_LEVEL_INVISIBLE;
int osd_duration = mpctx->opts->osd_duration;
int r = mp_property_do(name, M_PROPERTY_DELETE, NULL, mpctx);
if (r == M_PROPERTY_OK) {
set_osd_msg(mpctx, osdl, osd_duration, "Deleted property: '%s'", name);
cmd->success = true;
} else if (r == M_PROPERTY_UNKNOWN) {
set_osd_msg(mpctx, osdl, osd_duration, "Unknown property: '%s'", name);
cmd->success = false;
} else if (r <= 0) {
set_osd_msg(mpctx, osdl, osd_duration, "Failed to set property '%s'",
name);
cmd->success = false;
}
}
static void cmd_change_list(void *p)
{
struct mp_cmd_ctx *cmd = p;
@ -6310,6 +6333,7 @@ const struct mp_cmd_def mp_cmds[] = {
},
{ "set", cmd_set, {{"name", OPT_STRING(v.s)}, {"value", OPT_STRING(v.s)}}},
{ "del", cmd_del, {{"name", OPT_STRING(v.s)}}},
{ "change-list", cmd_change_list, { {"name", OPT_STRING(v.s)},
{"operation", OPT_STRING(v.s)},
{"value", OPT_STRING(v.s)} }},