From d24ef76cf48b2f63c7cf173200f4cf522c119ec9 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 28 Sep 2007 17:59:47 +0200 Subject: [PATCH] Refactor code to open_external_viewer This way there is only one place calling system. In addition, files opened in an editor will now wait for the user to press Enter to continue. Whether this is good or bad can be discussed but it feels more consistent and could help the user spot any errors printed by the editor. --- tig.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tig.c b/tig.c index cc7f6b8..b9fd89c 100644 --- a/tig.c +++ b/tig.c @@ -2146,7 +2146,19 @@ open_view(struct view *prev, enum request request, enum open_flags flags) } static void -open_editor(bool from_root, char *file) +open_external_viewer(const char *cmd) +{ + def_prog_mode(); /* save current tty modes */ + endwin(); /* restore original tty modes */ + system(cmd); + fprintf(stderr, "Press Enter to continue"); + getc(stdin); + reset_prog_mode(); + redraw_display(); +} + +static void +open_editor(bool from_root, const char *file) { char cmd[SIZEOF_STR]; char file_sq[SIZEOF_STR]; @@ -2165,11 +2177,7 @@ open_editor(bool from_root, char *file) if (sq_quote(file_sq, 0, file) < sizeof(file_sq) && string_format(cmd, "%s %s%s", editor, prefix, file_sq)) { - def_prog_mode(); /* save current tty modes */ - endwin(); /* restore original tty modes */ - system(cmd); - reset_prog_mode(); - redraw_display(); + open_external_viewer(cmd); } } @@ -4038,13 +4046,7 @@ cherry_pick_commit(struct commit *commit) cherry_pick = "git cherry-pick"; if (string_format(cmd, "%s %s", cherry_pick, commit->id)) { - def_prog_mode(); /* save current tty modes */ - endwin(); /* restore original tty modes */ - system(cmd); - fprintf(stderr, "Press Enter to continue"); - getc(stdin); - reset_prog_mode(); - redraw_display(); + open_external_viewer(cmd); } } -- 2.30.2