From dbe74871995912004bfa24d22c01205d4a8aa1cf Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 16 Nov 2017 14:51:38 +0900 Subject: 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 such a 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 --- editor.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/editor.c b/editor.c index 7519edecdc..9663593f80 100644 --- a/editor.c +++ b/editor.c @@ -40,6 +40,28 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en const char *args[] = { editor, real_path(path), NULL }; struct child_process p = CHILD_PROCESS_INIT; int ret, sig; + static const char *close_notice = NULL; + + if (isatty(2) && !close_notice) { + char *term = getenv("TERM"); + + if (term && strcmp(term, "dumb")) + /* + * go back to the beginning and erase the + * entire line if the terminal is capable + * to do so, to avoid wasting the vertical + * space. + */ + close_notice = "\r\033[K"; + else + /* otherwise, complete and waste the line */ + close_notice = "done.\n"; + } + + if (close_notice) { + fprintf(stderr, "Waiting for you to finish editing..."); + fflush(stderr); + } p.argv = args; p.env = env; @@ -58,6 +80,8 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en if (ret) return error("There was a problem with the editor '%s'.", editor); + if (close_notice) + fputs(close_notice, stderr); } if (!buffer) -- cgit v1.2.1