| 
11 | 11 | #include "strvec.h"  | 
12 | 12 | #include "run-command.h"  | 
13 | 13 | #include "sigchain.h"  | 
 | 14 | +#include "compat/terminal.h"  | 
14 | 15 | 
 
  | 
15 | 16 | #ifndef DEFAULT_EDITOR  | 
16 | 17 | #define DEFAULT_EDITOR "vi"  | 
@@ -62,6 +63,7 @@ static int launch_specified_editor(const char *editor, const char *path,  | 
62 | 63 | 		return error("Terminal is dumb, but EDITOR unset");  | 
63 | 64 | 
 
  | 
64 | 65 | 	if (strcmp(editor, ":")) {  | 
 | 66 | +		int save_and_restore_term = !strcmp(editor, "vi") || !strcmp(editor, "vim");  | 
65 | 67 | 		struct strbuf realpath = STRBUF_INIT;  | 
66 | 68 | 		struct child_process p = CHILD_PROCESS_INIT;  | 
67 | 69 | 		int ret, sig;  | 
@@ -90,14 +92,20 @@ static int launch_specified_editor(const char *editor, const char *path,  | 
90 | 92 | 			strvec_pushv(&p.env, (const char **)env);  | 
91 | 93 | 		p.use_shell = 1;  | 
92 | 94 | 		p.trace2_child_class = "editor";  | 
 | 95 | +		if (save_and_restore_term)  | 
 | 96 | +			save_and_restore_term = !save_term(1);  | 
93 | 97 | 		if (start_command(&p) < 0) {  | 
 | 98 | +			if (save_and_restore_term)  | 
 | 99 | +				restore_term();  | 
94 | 100 | 			strbuf_release(&realpath);  | 
95 | 101 | 			return error("unable to start editor '%s'", editor);  | 
96 | 102 | 		}  | 
97 | 103 | 
 
  | 
98 | 104 | 		sigchain_push(SIGINT, SIG_IGN);  | 
99 | 105 | 		sigchain_push(SIGQUIT, SIG_IGN);  | 
100 | 106 | 		ret = finish_command(&p);  | 
 | 107 | +		if (save_and_restore_term)  | 
 | 108 | +			restore_term();  | 
101 | 109 | 		strbuf_release(&realpath);  | 
102 | 110 | 		sig = ret - 128;  | 
103 | 111 | 		sigchain_pop(SIGINT);  | 
 | 
0 commit comments