|
3 | 3 | #include "strbuf.h" |
4 | 4 | #include "run-command.h" |
5 | 5 | #include "sigchain.h" |
| 6 | +#include "compat/terminal.h" |
6 | 7 |
|
7 | 8 | #ifndef DEFAULT_EDITOR |
8 | 9 | #define DEFAULT_EDITOR "vi" |
@@ -54,6 +55,7 @@ static int launch_specified_editor(const char *editor, const char *path, |
54 | 55 | return error("Terminal is dumb, but EDITOR unset"); |
55 | 56 |
|
56 | 57 | if (strcmp(editor, ":")) { |
| 58 | + int save_and_restore_term = !strcmp(editor, "vi") || !strcmp(editor, "vim"); |
57 | 59 | struct strbuf realpath = STRBUF_INIT; |
58 | 60 | const char *args[] = { editor, NULL, NULL }; |
59 | 61 | struct child_process p = CHILD_PROCESS_INIT; |
@@ -83,14 +85,20 @@ static int launch_specified_editor(const char *editor, const char *path, |
83 | 85 | p.env = 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