summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-04-04 13:10:39 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-04-04 13:10:39 +0100
commitdde16b00a91af805cd382dbccce115569ab9b1f0 (patch)
treed760eb354e4ec4e442f79fc822868f3b6646090d /src
parentac70b3e6d76dc5c8f8c3619ca953e41bcf22d325 (diff)
Add onkey command for executing commands after reading a key
This completes the various user interaction primitives, on_next_key was the last not to be available through a command.
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/commands.cc b/src/commands.cc
index e1cfcb10..682e191b 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -1300,6 +1300,26 @@ const CommandDesc menu_cmd = {
}
};
+const CommandDesc onkey_cmd = {
+ "onkey",
+ nullptr,
+ "onkey <register> <command>: wait for next user key, store it in <register> and execute <command>",
+ ParameterDesc{ {}, ParameterDesc::Flags::None, 2, 2 },
+ CommandFlags::None,
+ CommandHelper{},
+ CommandCompleter{},
+ [](const ParametersParser& parser, Context& context)
+ {
+ String reg = parser[0];
+ String command = parser[1];
+ context.input_handler().on_next_key(KeymapMode::None,
+ [=](Key key, Context& context) {
+ RegisterManager::instance()[reg] = key_to_str(key);
+ CommandManager::instance().execute(command, context);
+ });
+ }
+};
+
const CommandDesc info_cmd = {
"info",
nullptr,
@@ -1517,6 +1537,7 @@ void register_commands()
register_command(eval_string_cmd);
register_command(prompt_cmd);
register_command(menu_cmd);
+ register_command(onkey_cmd);
register_command(info_cmd);
register_command(try_catch_cmd);
register_command(face_cmd);