-
Notifications
You must be signed in to change notification settings - Fork 3.2k
command: add msg command #16854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
command: add msg command #16854
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add `msg-prefix` command |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add `msg` command |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -814,6 +814,20 @@ Text Manipulation | |
|
|
||
| This line of Lua prints "foo \\{bar}" on the OSD. | ||
|
|
||
| ``msg <level> <message> [...]`` | ||
| Write a log message. ``level`` must be one of the log levels accepted by the | ||
| ``mp.msg.log`` Lua function. The ``message`` arguments are separated from | ||
| each other with a space. A newline is added to the end of the message. | ||
|
|
||
| This command has a variable number of arguments, and cannot be used with | ||
| named arguments. | ||
|
|
||
| .. note:: Lua and JS code should use the provided ``mp.msg`` modules. | ||
|
|
||
| ``msg-prefix <level> <prefix> <message> [...]`` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want that? I would say we don't let clients to change their prefix. Or it may be additional arg in |
||
| Same as ``msg``, but allows writing messages using ``prefix`` as the prefix | ||
| instead of the name of the client that sent the command. | ||
|
|
||
| Configuration Commands | ||
| ~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7104,6 +7104,44 @@ static void cmd_notify_property(void *p) | |
| mp_notify_property(mpctx, cmd->args[0].v.s); | ||
| } | ||
|
|
||
| static void cmd_msg(void *p) | ||
| { | ||
| struct mp_cmd_ctx *cmd = p; | ||
| struct MPContext *mpctx = cmd->mpctx; | ||
|
|
||
| if (cmd->num_args < 2) | ||
| return; | ||
|
|
||
| int level = mp_msg_find_level(cmd->args[0].v.s); | ||
| if (level < 0) | ||
| return; | ||
|
|
||
| struct mp_log *log = mp_log_new(NULL, mpctx->log, cmd->cmd->sender); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to create logger during client init and set it in cmd, same as |
||
| for (int i = 1; i < cmd->num_args; i++) | ||
| mp_msg(log, level, (i == 1 ? "%s" : " %s"), cmd->args[i].v.s); | ||
| mp_msg(log, level, "\n"); | ||
| talloc_free(log); | ||
| } | ||
|
|
||
| static void cmd_msg_prefix(void *p) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated code above, it should be made single function/command. |
||
| { | ||
| struct mp_cmd_ctx *cmd = p; | ||
| struct MPContext *mpctx = cmd->mpctx; | ||
|
|
||
| if (cmd->num_args < 3) | ||
| return; | ||
|
|
||
| int level = mp_msg_find_level(cmd->args[0].v.s); | ||
| if (level < 0) | ||
| return; | ||
|
|
||
| struct mp_log *log = mp_log_new(NULL, mpctx->log, cmd->args[1].v.s); | ||
| for (int i = 2; i < cmd->num_args; i++) | ||
| mp_msg(log, level, (i == 2 ? "%s" : " %s"), cmd->args[i].v.s); | ||
| mp_msg(log, level, "\n"); | ||
| talloc_free(log); | ||
| } | ||
|
|
||
| /* This array defines all known commands. | ||
| * The first field the command name used in libmpv and input.conf. | ||
| * The second field is the handler function (see mp_cmd_def.handler and | ||
|
|
@@ -7623,6 +7661,13 @@ const struct mp_cmd_def mp_cmds[] = { | |
|
|
||
| { "notify-property", cmd_notify_property, { {"property", OPT_STRING(v.s)} } }, | ||
|
|
||
| { "msg", cmd_msg, { {"level", OPT_STRING(v.s)}, {"message", OPT_STRING(v.s)} }, | ||
| .is_noisy = true, .vararg = true }, | ||
| { "msg-prefix", cmd_msg_prefix, { {"level", OPT_STRING(v.s)}, | ||
| {"prefix", OPT_STRING(v.s)}, | ||
| {"message", OPT_STRING(v.s)} }, | ||
| .is_noisy = true, .vararg = true }, | ||
|
|
||
| {0} | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not extend
print-textcommand with optional arguments? It can be aliased tomsgif preferred, but both do the same thing.