Command stacking

This commit is contained in:
Night Kaly 2024-11-15 09:50:58 +00:00
parent a92c9cd07a
commit f072889a49
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM
2 changed files with 33 additions and 4 deletions

View file

@ -46,11 +46,17 @@ enum keys {
PAGE_DOWN PAGE_DOWN
}; };
enum actions {
COUNTING,
DELETE
};
enum modes { enum modes {
NORMAL, NORMAL,
INSERT, INSERT,
VISUAL, VISUAL,
COMMAND COMMAND,
PENDING0,
}; };
enum highlight { enum highlight {
@ -121,4 +127,4 @@ language_t langs[] = {
#define LANGS_LEN (sizeof(langs) / sizeof(langs[0])) #define LANGS_LEN (sizeof(langs) / sizeof(langs[0]))
#define CTRL_KEY(k) ((k) & 0x1f) #define CTRL_KEY(k) ((k) & 0x1f)
#define COLOR_LEN 19 #define MAX_COMMAND_SIZE 512

23
vip.c
View file

@ -23,6 +23,9 @@ int rows, cols;
editor_t editor[9]; editor_t editor[9];
int editors = 0; int editors = 0;
editor_t *cur_editor; editor_t *cur_editor;
int action = DEFAULT;
char cmd[MAX_COMMAND_SIZE];
int cmd_len = 0;
void draw_status_bar(void); void draw_status_bar(void);
void refresh_screen(void); void refresh_screen(void);
@ -1076,6 +1079,12 @@ int main(int argc, char **argv)
insert_new_line(); insert_new_line();
break; break;
case '1': case '2': case '3': case '4': case '5': case '6': case '7':
case '8': case '9':
action = COUNTING;
cmd[cmd_len++] = c;
break;
case HOME_KEY: case HOME_KEY:
cur_editor->x = 0; cur_editor->x = 0;
break; break;
@ -1211,7 +1220,16 @@ int main(int argc, char **argv)
case 'j': /* PASSTHROUGH */ case 'j': /* PASSTHROUGH */
if (cur_editor->mode != INSERT) { if (cur_editor->mode != INSERT) {
if (action == COUNTING) {
for (int i = 0; i < atoi(cmd); i++) {
move_xy(ARROW_DOWN); move_xy(ARROW_DOWN);
}
action = DEFAULT;
cmd_len = 0;
memset(&cmd, 0, MAX_COMMAND_SIZE);
} else {
move_xy(ARROW_DOWN);
}
break; break;
} }
@ -1243,7 +1261,12 @@ int main(int argc, char **argv)
case '0': /* PASSTHROUGH */ case '0': /* PASSTHROUGH */
if (cur_editor->mode == NORMAL) { if (cur_editor->mode == NORMAL) {
if (cmd_len == 0) {
cur_editor->x = 0; cur_editor->x = 0;
} else {
action = COUNTING;
cmd[cmd_len++] = c;
}
break; break;
} }