|
4 | 4 | #include "strvec.h"
|
5 | 5 | #include "run-command.h"
|
6 | 6 | #include "sigchain.h"
|
| 7 | +#include "compat/terminal.h" |
7 | 8 |
|
8 | 9 | #ifndef DEFAULT_EDITOR
|
9 | 10 | #define DEFAULT_EDITOR "vi"
|
@@ -55,6 +56,7 @@ static int launch_specified_editor(const char *editor, const char *path,
|
55 | 56 | return error("Terminal is dumb, but EDITOR unset");
|
56 | 57 |
|
57 | 58 | if (strcmp(editor, ":")) {
|
| 59 | + int save_and_restore_term = !strcmp(editor, "vi") || !strcmp(editor, "vim"); |
58 | 60 | struct strbuf realpath = STRBUF_INIT;
|
59 | 61 | struct child_process p = CHILD_PROCESS_INIT;
|
60 | 62 | int ret, sig;
|
@@ -83,14 +85,20 @@ static int launch_specified_editor(const char *editor, const char *path,
|
83 | 85 | strvec_pushv(&p.env, (const char **)env);
|
84 | 86 | p.use_shell = 1;
|
85 | 87 | p.trace2_child_class = "editor";
|
| 88 | + if (save_and_restore_term) |
| 89 | + save_and_restore_term = !save_term(1); |
86 | 90 | if (start_command(&p) < 0) {
|
| 91 | + if (save_and_restore_term) |
| 92 | + restore_term(); |
87 | 93 | strbuf_release(&realpath);
|
88 | 94 | return error("unable to start editor '%s'", editor);
|
89 | 95 | }
|
90 | 96 |
|
91 | 97 | sigchain_push(SIGINT, SIG_IGN);
|
92 | 98 | sigchain_push(SIGQUIT, SIG_IGN);
|
93 | 99 | ret = finish_command(&p);
|
| 100 | + if (save_and_restore_term) |
| 101 | + restore_term(); |
94 | 102 | strbuf_release(&realpath);
|
95 | 103 | sig = ret - 128;
|
96 | 104 | sigchain_pop(SIGINT);
|
|
0 commit comments