summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
Diffstat (limited to 'input')
-rw-r--r--input/cmd.c12
-rw-r--r--input/cmd.h1
-rw-r--r--input/input.c19
3 files changed, 27 insertions, 5 deletions
diff --git a/input/cmd.c b/input/cmd.c
index 093e97dbb4..93baa52f43 100644
--- a/input/cmd.c
+++ b/input/cmd.c
@@ -449,7 +449,6 @@ mp_cmd_t *mp_input_parse_cmd_str(struct mp_log *log, bstr str, const char *loc)
*list = (struct mp_cmd) {
.name = (char *)mp_cmd_list.name,
.def = &mp_cmd_list,
- .original = bstrto0(list, original),
};
talloc_steal(list, cmd);
struct mp_cmd_arg arg = {0};
@@ -469,6 +468,16 @@ mp_cmd_t *mp_input_parse_cmd_str(struct mp_log *log, bstr str, const char *loc)
p_prev = &sub->queue_next;
}
+ cmd->original = bstrto0(cmd, bstr_strip(
+ bstr_splice(original, 0, str.start - original.start)));
+
+ str = bstr_strip(str);
+ if (bstr_eatstart0(&str, "#") && !bstr_startswith0(str, "#")) {
+ str = bstr_strip(str);
+ if (str.len)
+ cmd->desc = bstrto0(cmd, str);
+ }
+
done:
talloc_free(tmp);
return cmd;
@@ -510,6 +519,7 @@ mp_cmd_t *mp_cmd_clone(mp_cmd_t *cmd)
m_option_copy(ret->args[i].type, &ret->args[i].v, &cmd->args[i].v);
}
ret->original = talloc_strdup(ret, cmd->original);
+ ret->desc = talloc_strdup(ret, cmd->desc);
ret->sender = NULL;
ret->key_name = talloc_strdup(ret, ret->key_name);
ret->key_text = talloc_strdup(ret, ret->key_text);
diff --git a/input/cmd.h b/input/cmd.h
index 72824dffc8..c63e0bdd6c 100644
--- a/input/cmd.h
+++ b/input/cmd.h
@@ -100,6 +100,7 @@ typedef struct mp_cmd {
int nargs;
int flags; // mp_cmd_flags bitfield
char *original;
+ char *desc; // (usually NULL since stripped away later)
char *input_section;
bool is_up_down : 1;
bool is_up : 1;
diff --git a/input/input.c b/input/input.c
index 77e882a2f2..80457fcd5c 100644
--- a/input/input.c
+++ b/input/input.c
@@ -64,6 +64,7 @@ struct cmd_bind {
int num_keys;
char *cmd;
char *location; // filename/line number of definition
+ char *desc; // human readable description
bool is_builtin;
struct cmd_bind_section *owner;
};
@@ -1149,7 +1150,7 @@ static bool bind_matches_key(struct cmd_bind *bind, int num_keys, const int *key
static void bind_keys(struct input_ctx *ictx, bool builtin, bstr section,
const int *keys, int num_keys, bstr command,
- const char *loc)
+ const char *loc, const char *desc)
{
struct cmd_bind_section *bs = get_bind_section(ictx, section);
struct cmd_bind *bind = NULL;
@@ -1175,6 +1176,7 @@ static void bind_keys(struct input_ctx *ictx, bool builtin, bstr section,
*bind = (struct cmd_bind) {
.cmd = bstrdup0(bs->binds, command),
.location = talloc_strdup(bs->binds, loc),
+ .desc = talloc_strdup(bs->binds, desc),
.owner = bs,
.is_builtin = builtin,
.num_keys = num_keys,
@@ -1250,11 +1252,18 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data,
}
}
- bind_keys(ictx, builtin, section, keys, num_keys, command, cur_loc);
+ // Print warnings if invalid commands are encountered.
+ struct mp_cmd *cmd = mp_input_parse_cmd(ictx, command, cur_loc);
+ const char *desc = NULL;
+ if (cmd) {
+ desc = cmd->desc;
+ command = bstr0(cmd->original);
+ }
+
+ bind_keys(ictx, builtin, section, keys, num_keys, command, cur_loc, desc);
n_binds++;
- // Print warnings if invalid commands are encountered.
- talloc_free(mp_input_parse_cmd(ictx, command, cur_loc));
+ talloc_free(cmd);
}
talloc_free(cur_loc);
@@ -1524,6 +1533,8 @@ struct mpv_node mp_input_get_bindings(struct input_ctx *ictx)
node_map_add_string(entry, "cmd", b->cmd);
node_map_add_flag(entry, "is_weak", b->is_builtin);
node_map_add_int64(entry, "priority", b_priority);
+ if (b->desc)
+ node_map_add_string(entry, "comment", b->desc);
char *key = mp_input_get_key_combo_name(b->keys, b->num_keys);
node_map_add_string(entry, "key", key);