aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-06-04 15:17:18 -0600
committernytpu <alex@nytpu.com>2021-06-04 15:17:18 -0600
commit74cab1e3b6c0419b7c156786f4a116d3a23e1193 (patch)
tree35a2c2a23f72ecb0973adcdfcb7834df656185fc
parentadd insert mode (diff)
downloaded-74cab1e3b6c0419b7c156786f4a116d3a23e1193.tar.bz2
ed-74cab1e3b6c0419b7c156786f4a116d3a23e1193.zip
add framework for commands
-rw-r--r--main.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/main.c b/main.c
index 513f386..1c97f9c 100644
--- a/main.c
+++ b/main.c
@@ -91,20 +91,37 @@ main(int argc, char *argv[])
char *line;
while ((line = linenoise(E.prompt_enabled ? E.prompt : "")) != NULL) {
struct command cmd;
- parse_command(&cmd, line);
- printf("start address: %ld\n", cmd.start);
- if (cmd.cnt > 1) printf("end address: %ld\n", cmd.end);
- if (line[0] == 'q') break;
- if (line[0] == 'P') {
- E.prompt_enabled = !E.prompt_enabled;
- free(line);
- continue;
+ int ret = parse_command(&cmd, line);
+ if (ret < 0) continue;
+
+ // DEBUG
+ printf("s: %ld; e: %ld\n", cmd.start, cmd.end);
+
+ switch (cmd.command) {
+ case 'a':
+ insert_mode(cmd.end+1);
+ break;
+ case 'n':
+ print_rows_numbered(cmd.start, cmd.end);
+ break;
+ case 'q':
+ if (E.dirty) {
+ error("Buffer modified");
+ break;
+ }
+ // fallthrough
+ case 'Q':
+ goto quit;
+ default:
+ error("Unknown command");
+ break;
}
- printf("echo: %s\n", line);
+
linenoiseHistoryAdd(line);
free(line);
}
+quit:
editor_deinit();
return EXIT_SUCCESS;
}