summaryrefslogtreecommitdiff
path: root/src/command.h
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2023-01-26 13:07:07 +0100
committerAlbert Cervin <albert@acervin.com>2023-01-26 13:07:07 +0100
commite65158a0326108d1fc724ee683b7fa900ef2671a (patch)
tree9bad30b377a326e0d0e3101c4f96228ae7a41673 /src/command.h
parent9a2b138a03e27d0f04101fe6ae3977d79518c513 (diff)
downloaddged-e65158a0326108d1fc724ee683b7fa900ef2671a.tar.gz
dged-e65158a0326108d1fc724ee683b7fa900ef2671a.tar.xz
dged-e65158a0326108d1fc724ee683b7fa900ef2671a.zip
More tests and documentation
Also, split out platform-specific parts and add mocks for tests.
Diffstat (limited to 'src/command.h')
-rw-r--r--src/command.h54
1 files changed, 48 insertions, 6 deletions
diff --git a/src/command.h b/src/command.h
index 278a894..20c7d74 100644
--- a/src/command.h
+++ b/src/command.h
@@ -1,4 +1,4 @@
-/**
+/** @file command.h
* Commands and command registries
*/
#include <stdint.h>
@@ -7,28 +7,70 @@ struct buffer;
struct buffers;
struct window;
+/**
+ * Execution context for a command
+ */
struct command_ctx {
+ /**
+ * The current list of buffers.
+ *
+ * Can be used to insert new buffers or
+ * inspect existing.
+ */
struct buffers *buffers;
+
+ /**
+ * The currently active window.
+ */
struct window *active_window;
+
+ /**
+ * A registry of available commands.
+ *
+ * Can be used to execute other commands as part of a command implementation.
+ */
struct commands *commands;
+
+ /**
+ * The command that is currently being executed
+ */
struct command *self;
+
+ /**
+ * User data set up by the command currently being executed.
+ */
void *userdata;
};
+/** A command function callback which holds the implementation of a command */
typedef int32_t (*command_fn)(struct command_ctx ctx, int argc,
const char *argv[]);
+/**
+ * A command that can be bound to a key or executed directly
+ */
struct command {
+ /**
+ * Name of the command
+ *
+ * Used to look the command up for execution and keybinds.
+ */
const char *name;
+
+ /**
+ * Implementation of command behavior
+ */
command_fn fn;
- void *userdata;
-};
-struct hashed_command {
- uint32_t hash;
- struct command command;
+ /**
+ * Userdata passed to each invocation of the command.
+ */
+ void *userdata;
};
+/**
+ * A command registry
+ */
struct commands {
struct hashed_command *commands;
uint32_t ncommands;