Skip to content

Commit

Permalink
Fix suspension capability when calling out to external commands
Browse files Browse the repository at this point in the history
Clear the terminal before calling out to an external command so the
altscreen won't mess up any downstream subshell management. Restore
terminal settings as per init_display when restoring. Reproducible with
example from[0]:

 - Run `tig status`
 - Press 'e' to open Vim
 - Press Ctrl-Z to suspend Vim
 - Run `fg`
 - Quit Vim

 [0] #232 (comment)

Refs: #232
  • Loading branch information
jonas committed Jul 17, 2017
1 parent 02e952c commit c883298
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ open_external_viewer(const char *argv[], const char *dir, bool silent, bool conf
ok = io_run_bg(argv, dir);

} else {
clear();
refresh();
endwin(); /* restore original tty modes */
ok = io_run_fg(argv, dir);
if (confirm || !ok) {
Expand All @@ -66,6 +68,11 @@ open_external_viewer(const char *argv[], const char *dir, bool silent, bool conf
getc(opt_tty);
fseek(opt_tty, 0, SEEK_END);
}
nonl(); /* Disable conversion and detect newlines from input. */
raw(); /* Take input chars one at a time, no wait for \n */
noecho(); /* Don't echo input */
curs_set(0);
leaveok(stdscr, false);
}

if (watch_update(WATCH_EVENT_AFTER_COMMAND) && refresh) {
Expand Down Expand Up @@ -547,10 +554,7 @@ init_display(void)
die("Failed to register done_display");

/* Initialize the curses library */
if (!no_display && isatty(STDIN_FILENO)) {
cursed = !!initscr();
opt_tty = stdin;
} else {
{
/* Leave stdin and stdout alone when acting as a pager. */
FILE *out_tty;

Expand Down

0 comments on commit c883298

Please sign in to comment.