write to location
This commit is contained in:
parent
fe34c61b12
commit
d273544702
3 changed files with 19 additions and 8 deletions
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
#include "kubo_command.h"
|
||||
|
||||
static inline void kubo_command_exit(struct kubo_context *context);
|
||||
static inline void kubo_command_write(struct kubo_context *context);
|
||||
static inline void kubo_command_exit(struct kubo_context *context, char *rest);
|
||||
static inline void kubo_command_write(struct kubo_context *context, char *rest);
|
||||
|
||||
static const struct kubo_command_data kubo_commands[] = {
|
||||
{":q", kubo_command_exit}, {":w", kubo_command_write}};
|
||||
|
|
@ -42,23 +42,31 @@ void kubo_command_pop() {
|
|||
}
|
||||
|
||||
void kubo_command_accept_cmd(struct kubo_context *context) {
|
||||
char *cmd = kubo_command_get_str();
|
||||
cmd = strtok(cmd, " ");
|
||||
char *rest = strtok(NULL, " ");
|
||||
for (size_t i = 0; i < kubo_commands_size; i++) {
|
||||
if (strcmp(kubo_commands[i].input, kubo_char_arr_build_str(&command)) ==
|
||||
0) {
|
||||
kubo_commands[i].function(context);
|
||||
if (strcmp(cmd, kubo_commands[i].input) == 0) {
|
||||
kubo_commands[i].function(context, rest);
|
||||
return;
|
||||
}
|
||||
}
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
char *kubo_command_get_str() { return kubo_char_arr_build_str(&command); }
|
||||
|
||||
void kubo_command_clear() { kubo_char_arr_clear(&command); }
|
||||
|
||||
static inline void kubo_command_exit(struct kubo_context *context) {
|
||||
static inline void kubo_command_exit(struct kubo_context *context, char *rest) {
|
||||
(void)rest;
|
||||
context->exit_pending = true;
|
||||
}
|
||||
|
||||
static inline void kubo_command_write(struct kubo_context *context) {
|
||||
static inline void kubo_command_write(struct kubo_context *context, char *rest) {
|
||||
if (rest) {
|
||||
context->file_name = rest;
|
||||
}
|
||||
|
||||
kubo_file_write(context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#include "kubo_context.h"
|
||||
#include "kubo_file.h"
|
||||
|
||||
typedef void (*kubo_command_function)(struct kubo_context *context);
|
||||
typedef void (*kubo_command_function)(struct kubo_context *context, char *rest);
|
||||
|
||||
struct kubo_command_data {
|
||||
const char *input;
|
||||
|
|
@ -40,6 +40,7 @@ void kubo_command_append_char(int c);
|
|||
void kubo_command_pop();
|
||||
void kubo_command_accept_cmd(struct kubo_context *context);
|
||||
void kubo_command_clear();
|
||||
|
||||
char *kubo_command_get_str();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,4 +25,6 @@ void kubo_command_bar_render(int x, int y, int font_size) {
|
|||
x += MeasureText(cmd, font_size);
|
||||
x += 2;
|
||||
DrawRectangle(x, y, MeasureText("x", font_size), font_size, WHITE);
|
||||
|
||||
free(cmd);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue