git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v3] launch_editor(): indicate that Git waits for user input
@ 2017-11-27 13:47 lars.schneider
  2017-11-27 17:17 ` Kaartic Sivaraam
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: lars.schneider @ 2017-11-27 13:47 UTC (permalink / raw)
  To: git; +Cc: gitster, sbeller, sunshine, kaartic.sivaraam, Lars Schneider

From: Junio C Hamano <gitster@pobox.com>

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>
---


Hi,

diff to v2:
    - shortened and localized the "waiting" message
    - detect "emacsclient" and suppress "waiting" message

I did not add a newline after the "waiting" message in case of an error.
Junio indicated [1] that it is not necessary with the shorter "waiting"
message.

Thanks,
Lars


[1] https://public-inbox.org/git/xmqqk1ygnpu7.fsf@gitster.mtv.corp.google.com/

Notes:
    Base Commit: 89ea799ffc (89ea799ffcc5c8a0547d3c9075eb979256ee95b8)
    Diff on Web: https://github.com/larsxschneider/git/commit/0d43814931
    Checkout:    git fetch https://github.com/larsxschneider/git editor-v3 && git checkout 0d43814931

 editor.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/editor.c b/editor.c
index 7519edecdc..4251ae9d7a 100644
--- a/editor.c
+++ b/editor.c
@@ -40,6 +40,35 @@ 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 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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-11-29  2:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 13:47 [PATCH v3] launch_editor(): indicate that Git waits for user input lars.schneider
2017-11-27 17:17 ` Kaartic Sivaraam
2017-11-27 18:36 ` Eric Sunshine
2017-11-27 20:04   ` Lars Schneider
2017-11-27 20:09 ` brian m. carlson
2017-11-27 23:05   ` Jeff King
2017-11-28  4:29     ` Junio C Hamano
2017-11-28 12:31     ` Lars Schneider
2017-11-29  2:06     ` brian m. carlson
2017-11-27 23:18 ` Junio C Hamano
2017-11-28 12:39   ` Lars Schneider

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).