aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-10-17 12:22:51 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-10-17 12:22:51 +0200
commit9c4999fc9ee4a071bba068e68d690ba637ec28f5 (patch)
treede7dd0e0cd3d251b26f3fce477f3c937dfebb66a
parent9b06e28e2ce599a7a4911212e357b5d35fe0b08f (diff)
downloadvis-9c4999fc9ee4a071bba068e68d690ba637ec28f5.tar.gz
vis-9c4999fc9ee4a071bba068e68d690ba637ec28f5.tar.xz
Factor out editor main loop
-rw-r--r--vis.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/vis.c b/vis.c
index 6c35574..087ff08 100644
--- a/vis.c
+++ b/vis.c
@@ -1583,33 +1583,7 @@ static void die(const char *errstr, ...) {
exit(EXIT_FAILURE);
}
-int main(int argc, char *argv[]) {
- /* decide which key configuration to use based on argv[0] */
- char *arg0 = argv[0];
- while (*arg0 && (*arg0 == '.' || *arg0 == '/'))
- arg0++;
- for (int i = 0; i < LENGTH(editors); i++) {
- if (editors[i].name[0] == arg0[0]) {
- config = &editors[i];
- break;
- }
- }
-
- mode_prev = mode = config->mode;
- setup();
-
- if (!(vis = editor_new(screen.w, screen.h)))
- die("Could not allocate editor core\n");
- if (!editor_syntax_load(vis, syntaxes, colors))
- die("Could not load syntax highlighting definitions\n");
- editor_statusbar_set(vis, config->statusbar);
-
- for (int i = 1; i < MAX(argc, 2); i++) {
- const char *file = i < argc ? argv[i] : NULL;
- if (!editor_window_new(vis, file))
- die("Could not load `%s': %s\n", file, strerror(errno));
- }
-
+static void mainloop() {
struct timeval idle = { .tv_usec = 0 }, *timeout = NULL;
Key key, key_prev, *key_mod = NULL;
@@ -1674,7 +1648,36 @@ int main(int argc, char *argv[]) {
if (mode->idle)
timeout = &idle;
}
+}
+
+int main(int argc, char *argv[]) {
+ /* decide which key configuration to use based on argv[0] */
+ char *arg0 = argv[0];
+ while (*arg0 && (*arg0 == '.' || *arg0 == '/'))
+ arg0++;
+ for (int i = 0; i < LENGTH(editors); i++) {
+ if (editors[i].name[0] == arg0[0]) {
+ config = &editors[i];
+ break;
+ }
+ }
+
+ mode_prev = mode = config->mode;
+ setup();
+
+ if (!(vis = editor_new(screen.w, screen.h)))
+ die("Could not allocate editor core\n");
+ if (!editor_syntax_load(vis, syntaxes, colors))
+ die("Could not load syntax highlighting definitions\n");
+ editor_statusbar_set(vis, config->statusbar);
+
+ for (int i = 1; i < MAX(argc, 2); i++) {
+ const char *file = i < argc ? argv[i] : NULL;
+ if (!editor_window_new(vis, file))
+ die("Could not load `%s': %s\n", file, strerror(errno));
+ }
+ mainloop();
editor_free(vis);
endwin();
return 0;