summaryrefslogtreecommitdiff
path: root/editor.c
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2023-01-31 10:46:21 -0700
committercflip <cflip@cflip.net>2023-01-31 12:20:03 -0700
commit757efb85045408e2601da0f53547941a40d2e960 (patch)
tree0ab46da5222222971d3dd4bd7319262c6842be8a /editor.c
parentc3da108c2d41853beb49a90a1f43a2a9a158c385 (diff)
Start implementing editor commands
This first step allows you to press the semicolon key to enter command mode, where you can type into a command line. Currently, pressing enter when in command mode will clear the command line but since there are no commands implemented it doesn't matter what you type in there.
Diffstat (limited to 'editor.c')
-rw-r--r--editor.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/editor.c b/editor.c
index d7d92a1..bba0ab9 100644
--- a/editor.c
+++ b/editor.c
@@ -34,6 +34,7 @@ void init_editor(struct editor_state* editor)
editor->status_message_time = 0;
editor->syntax = NULL;
editor->mode = EDITOR_MODE_NORMAL;
+ editor->cmdline = textbuf_init();
editor_update_screen_size(editor);
window_set_filename("[New]");
@@ -58,6 +59,13 @@ char* editor_prompt(struct editor_state* editor, char* prompt, void (*callback)(
return NULL;
}
+void editor_run_command(struct editor_state *editor)
+{
+ /* TODO: Do something here */
+ editor->mode = EDITOR_MODE_NORMAL;
+ textbuf_clear(&editor->cmdline);
+}
+
void editor_try_quit(struct editor_state *editor)
{
if (editor->dirty && quit_message_time == 0) {
@@ -308,6 +316,11 @@ void editor_draw_message_bar(struct editor_state* editor, struct textbuf *buffer
return;
}
+ if (editor->mode == EDITOR_MODE_COMMAND) {
+ textbuf_append(buffer, editor->cmdline.buffer, editor->cmdline.length);
+ return;
+ }
+
int message_length = strlen(editor->status_message);
if (message_length > editor->screen_cols)
@@ -326,4 +339,5 @@ void editor_destroy(struct editor_state *editor)
for (int i = 0; i < editor->num_lines; i++)
free_line(&editor->lines[i]);
free(editor->lines);
+ textbuf_free(&editor->cmdline);
}