From 04241ab731432f9d13c3cfa160c39f98f1d36ba2 Mon Sep 17 00:00:00 2001 From: rcombs Date: Fri, 16 Dec 2022 15:01:54 -0600 Subject: [PATCH] player/command: add "del" command --- DOCS/man/input.rst | 3 +++ player/command.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index e11beae92c..280e30cc8c 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -334,6 +334,9 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_). ``set `` Set the given property or option to the given value. +``del `` + Delete the given property. Most properties cannot be deleted. + ``add []`` Add the given value to the property or option. On overflow or underflow, clamp the property to the maximum. If ```` is omitted, assume ``1``. diff --git a/player/command.c b/player/command.c index c3a6729805..f6a0c9d33f 100644 --- a/player/command.c +++ b/player/command.c @@ -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)} }},