separate command handling
This commit is contained in:
parent
90db87bec9
commit
0be3768867
11 changed files with 143 additions and 52 deletions
|
|
@ -18,14 +18,6 @@
|
|||
|
||||
#include "kubo_context.h"
|
||||
|
||||
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},
|
||||
|
|
@ -40,7 +32,6 @@ void kubo_context_init(struct kubo_context *context) {
|
|||
}
|
||||
|
||||
kubo_wall_arr_init(&context->walls);
|
||||
kubo_char_arr_init(&context->command);
|
||||
context->wall_select_index = 0;
|
||||
context->exit_pending = false;
|
||||
|
||||
|
|
@ -49,17 +40,14 @@ void kubo_context_init(struct kubo_context *context) {
|
|||
|
||||
void kubo_context_cleanup(struct kubo_context *context) {
|
||||
kubo_wall_arr_free(&context->walls);
|
||||
kubo_char_arr_free(&context->command);
|
||||
}
|
||||
|
||||
void kubo_context_set_state(struct kubo_context *context,
|
||||
enum kubo_context_state state) {
|
||||
kubo_char_arr_clear(&context->command);
|
||||
context->state = kubo_context_states[state];
|
||||
|
||||
switch (context->state.id) {
|
||||
case KUBO_CONTEXT_COMMAND:
|
||||
kubo_char_arr_add(&context->command, ':');
|
||||
break;
|
||||
|
||||
case KUBO_CONTEXT_WALL_NEW:
|
||||
|
|
@ -74,18 +62,6 @@ void kubo_context_set_state(struct kubo_context *context,
|
|||
}
|
||||
}
|
||||
|
||||
void kubo_context_accept_cmd(struct kubo_context *context) {
|
||||
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);
|
||||
}
|
||||
|
||||
struct kubo_wall *kubo_context_get_pending_wall(struct kubo_context *context) {
|
||||
|
||||
if (context->state.id != KUBO_CONTEXT_WALL_NEW) {
|
||||
|
|
@ -155,7 +131,3 @@ 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