On Monday 27 November 2017 07:17 PM, lars.schnei...@autodesk.com wrote:

Show a message in the original terminal and get rid of it when the
editor returns.


"... except in the case when an error occurs." could  be included if needed.
+               static const char *close_notice = NULL;
+

IIRC, this variable is bound to be `static` for sake of future proofing. So, I guess you could use the following suggestion of Eric Sunshine in the below conditional.

    If you reverse this condition to say (!close_notice && isatty(2)),
    then you save an isatty() invocation each time if close_notice is
    already assigned.

+               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 if (term && strstr(term, "emacsclient"))
+                               /*
+                                * `emacsclient` (or `emacsclientw` on Windows) 
already prints
+                                * ("Waiting for Emacs...") if a file is opened 
for editing.
+                                * Therefore, we don't need to print the editor 
launch info.
+                                */
+                               ;
+                       else
+                               /* otherwise, complete and waste the line */
+                               close_notice = _("done.\n");
+               }
+
+               if (close_notice) {
+                       fprintf(stderr, _("Launched editor. Waiting for your 
input... "));
+                       fflush(stderr);
+               }

                p.argv = args;
                p.env = env;
@@ -53,11 +82,14 @@ int launch_editor(const char *path, struct strbuf *buffer, 
const char *const *en
                sig = ret - 128;
                sigchain_pop(SIGINT);
                sigchain_pop(SIGQUIT);
+
                if (sig == SIGINT || sig == SIGQUIT)
                        raise(sig);
                if (ret)
                        return error("There was a problem with the editor 
'%s'.",
                                        editor);
+               if (close_notice)
+                       fputs(close_notice, stderr);
        }

        if (!buffer)
--
2.15.0


Reply via email to