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