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