parse command input
This commit is contained in:
parent
9911031f98
commit
b7b8bd8b1e
7 changed files with 39 additions and 13 deletions
|
|
@ -18,7 +18,15 @@
|
|||
|
||||
#include "kubo_context.h"
|
||||
|
||||
const struct kubo_context_state_data kubo_context_states[] = {
|
||||
static inline void kubo_command_exit(struct kubo_context *context);
|
||||
|
||||
static const struct kubo_command_data kubo_commands[] = {
|
||||
{":q", kubo_command_exit}};
|
||||
|
||||
static const size_t kubo_commands_size =
|
||||
sizeof(kubo_commands) / sizeof(kubo_commands[0]);
|
||||
|
||||
static const struct kubo_context_state_data kubo_context_states[] = {
|
||||
{.id = KUBO_CONTEXT_NORMAL, .label = "Normal", .color = BLACK},
|
||||
{.id = KUBO_CONTEXT_COMMAND, .label = "Command", .color = RED},
|
||||
{.id = KUBO_CONTEXT_WALL_NEW, .label = "Wall New", .color = GREEN},
|
||||
|
|
@ -67,7 +75,14 @@ void kubo_context_set_state(struct kubo_context *context,
|
|||
}
|
||||
|
||||
void kubo_context_accept_cmd(struct kubo_context *context) {
|
||||
printf("accepting cmd %s\n", kubo_char_arr_build_str(&context->command));
|
||||
for (size_t i = 0; i < kubo_commands_size; i++) {
|
||||
if (strcmp(kubo_commands[i].input,
|
||||
kubo_char_arr_build_str(&context->command)) == 0) {
|
||||
kubo_commands[i].function(context);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
kubo_context_set_state(context, KUBO_CONTEXT_NORMAL);
|
||||
}
|
||||
|
||||
|
|
@ -129,3 +144,7 @@ static inline void wall_select_refresh(struct kubo_context *context) {
|
|||
: KUBO_WALL_DONE;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void kubo_command_exit(struct kubo_context *context) {
|
||||
context->exit_pending = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue