Commit a915003aad0755429a02502b3e298874c3f0d072

Stefan Sperling 2019-02-05T18:51:59

delay initialization of curses in tog until after usage()

diff --git a/tog/tog.c b/tog/tog.c
index 812afe0..5361782 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1636,6 +1636,20 @@ apply_unveil(const char *repo_path, const char *worktree_path)
 	return NULL;
 }
 
+static void
+init_curses(void)
+{
+	initscr();
+	cbreak();
+	halfdelay(1); /* Do fast refresh while initial view is loading. */
+	noecho();
+	nonl();
+	intrflush(stdscr, FALSE);
+	keypad(stdscr, TRUE);
+	curs_set(0);
+	signal(SIGWINCH, tog_sigwinch);
+}
+
 static const struct got_error *
 cmd_log(int argc, char *argv[])
 {
@@ -1703,6 +1717,8 @@ cmd_log(int argc, char *argv[])
 		}
 	}
 
+	init_curses();
+
 	error = apply_unveil(repo_path, NULL);
 	if (error)
 		goto done;
@@ -2155,6 +2171,8 @@ cmd_diff(int argc, char *argv[])
 	} else
 		usage_diff();
 
+	init_curses();
+
 	error = apply_unveil(repo_path, NULL);
 	if (error)
 		goto done;
@@ -2856,6 +2874,8 @@ cmd_blame(int argc, char *argv[])
 		}
 	}
 
+	init_curses();
+
 	error = apply_unveil(repo_path, NULL);
 	if (error)
 		goto done;
@@ -3484,6 +3504,8 @@ cmd_tree(int argc, char *argv[])
 	} else
 		usage_log();
 
+	init_curses();
+
 	error = apply_unveil(repo_path, NULL);
 	if (error)
 		goto done;
@@ -3530,20 +3552,6 @@ done:
 	return error;
 }
 
-static void
-init_curses(void)
-{
-	initscr();
-	cbreak();
-	halfdelay(1); /* Do fast refresh while initial view is loading. */
-	noecho();
-	nonl();
-	intrflush(stdscr, FALSE);
-	keypad(stdscr, TRUE);
-	curs_set(0);
-	signal(SIGWINCH, tog_sigwinch);
-}
-
 __dead static void
 usage(void)
 {
@@ -3655,8 +3663,6 @@ main(int argc, char *argv[])
 		}
 	}
 
-	init_curses();
-
 	error = cmd->cmd_main(argc, cmd_argv ? cmd_argv : argv);
 	if (error)
 		goto done;