Skip to content

Commit 0d43814

Browse files
gitsterlarsxschneider
authored andcommitted
launch_editor(): indicate that Git waits for user input
When a graphical GIT_EDITOR is spawned by a Git command that opens and waits for user input (e.g. "git rebase -i"), then the editor window might be obscured by other windows. The user may be left staring at the original Git terminal window without even realizing that s/he needs to interact with another window before Git can proceed. To this user Git appears hanging. Show a message in the original terminal and get rid of it when the editor returns. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
1 parent 89ea799 commit 0d43814

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

editor.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,35 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
4040
const char *args[] = { editor, real_path(path), NULL };
4141
struct child_process p = CHILD_PROCESS_INIT;
4242
int ret, sig;
43+
static const char *close_notice = NULL;
44+
45+
if (isatty(2) && !close_notice) {
46+
char *term = getenv("TERM");
47+
48+
if (term && strcmp(term, "dumb"))
49+
/*
50+
* go back to the beginning and erase the
51+
* entire line if the terminal is capable
52+
* to do so, to avoid wasting the vertical
53+
* space.
54+
*/
55+
close_notice = "\r\033[K";
56+
else if (term && strstr(term, "emacsclient"))
57+
/*
58+
* `emacsclient` (or `emacsclientw` on Windows) already prints
59+
* ("Waiting for Emacs...") if a file is opened for editing.
60+
* Therefore, we don't need to print the editor launch info.
61+
*/
62+
;
63+
else
64+
/* otherwise, complete and waste the line */
65+
close_notice = _("done.\n");
66+
}
67+
68+
if (close_notice) {
69+
fprintf(stderr, _("Launched editor. Waiting for your input... "));
70+
fflush(stderr);
71+
}
4372

4473
p.argv = args;
4574
p.env = env;
@@ -53,11 +82,14 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
5382
sig = ret - 128;
5483
sigchain_pop(SIGINT);
5584
sigchain_pop(SIGQUIT);
85+
5686
if (sig == SIGINT || sig == SIGQUIT)
5787
raise(sig);
5888
if (ret)
5989
return error("There was a problem with the editor '%s'.",
6090
editor);
91+
if (close_notice)
92+
fputs(close_notice, stderr);
6193
}
6294

6395
if (!buffer)

0 commit comments

Comments
 (0)