git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 0/2] launch_editor(): indicate that Git waits for user input

From
lars.schneider@autodesk.com <lars.schneider@autodesk.com>
Date
Nov 29, 2017, 14:37 UTC
Message-ID
<20171129143752.60553-1-lars.schneider@autodesk.com>
From: Lars Schneider <larsxschneider@gmail.com>
Hi,

I simplified the code and enabled the "Git is waiting for editor input" message only for "intelligent" terminals. The rational is, that today's novice Git users are likely to have an "intelligent" terminal. People working with "dumb" terminals have their reasons and are likely not the target audience for this hint.

In addition, I added "advice.waitingForEditor" as an easy way to disable the hint for experienced users.

I refactored the detection of dumb terminals in a preparation commit.

Thanks, Lars

RFC: https://public-inbox.org/git/274B4850-2EB7-4BFA-A42C-25A573254969@gmail.com/
 v1: https://public-inbox.org/git/xmqqr2syvjxb.fsf@gitster.mtv.corp.google.com/
 v2: https://public-inbox.org/git/20171117135109.18071-1-lars.schneider@autodesk.com/
 v3: https://public-inbox.org/git/20171127134716.69471-1-lars.schneider@autodesk.com/
Base Ref: master
Web-Diff: https://github.com/larsxschneider/git/commit/9639e931bf
Checkout: git fetch https://github.com/larsxschneider/git editor-v4 && git checkout 9639e931bf
### Interdiff (v3..v4):
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 671fcbaa0f..de64201e82 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -354,6 +354,9 @@ advice.*::
 	ignoredHook::
 		Advice shown if an hook is ignored because the hook is not
 		set as executable.
+	waitingForEditor::
+		Print a message to the terminal whenever Git is waiting for
+		editor input from the user.
 --

 core.fileMode::
diff --git a/advice.c b/advice.c
index c6169bcb52..406efc183b 100644
--- a/advice.c
+++ b/advice.c
@@ -18,6 +18,7 @@ int advice_object_name_warning = 1;
 int advice_rm_hints = 1;
 int advice_add_embedded_repo = 1;
 int advice_ignored_hook = 1;
+int advice_waiting_for_editor = 1;

 static struct {
 	const char *name;
@@ -40,6 +41,7 @@ static struct {
 	{ "rmhints", &advice_rm_hints },
 	{ "addembeddedrepo", &advice_add_embedded_repo },
 	{ "ignoredhook", &advice_ignored_hook },
+	{ "waitingforeditor", &advice_waiting_for_editor },

 	/* make this an alias for backward compatibility */
 	{ "pushnonfastforward", &advice_push_update_rejected }
diff --git a/advice.h b/advice.h
index f525d6f89c..70568fa792 100644
--- a/advice.h
+++ b/advice.h
@@ -20,6 +20,7 @@ extern int advice_object_name_warning;
 extern int advice_rm_hints;
 extern int advice_add_embedded_repo;
 extern int advice_ignored_hook;
+extern int advice_waiting_for_editor;

 int git_default_advice_config(const char *var, const char *value);
 __attribute__((format (printf, 1, 2)))
diff --git a/cache.h b/cache.h
index 89f5d24579..3842fc097c 100644
--- a/cache.h
+++ b/cache.h
@@ -1469,6 +1469,7 @@ extern const char *ident_default_name(void);
 extern const char *ident_default_email(void);
 extern const char *git_editor(void);
 extern const char *git_pager(int stdout_is_tty);
+extern int is_terminal_dumb(void);
 extern int git_ident_config(const char *, const char *, void *);
 extern void reset_ident_date(void);

diff --git a/color.c b/color.c
index 9a9261ac16..d48dd947c9 100644
--- a/color.c
+++ b/color.c
@@ -329,8 +329,7 @@ static int check_auto_color(void)
 	if (color_stdout_is_tty < 0)
 		color_stdout_is_tty = isatty(1);
 	if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) {
-		char *term = getenv("TERM");
-		if (term && strcmp(term, "dumb"))
+		if (!is_terminal_dumb())
 			return 1;
 	}
 	return 0;
diff --git a/editor.c b/editor.c
index 4251ae9d7a..cdad4f74ec 100644
--- a/editor.c
+++ b/editor.c
@@ -7,11 +7,16 @@
 #define DEFAULT_EDITOR "vi"
 #endif

+int is_terminal_dumb(void)
+{
+	const char *terminal = getenv("TERM");
+	return !terminal || !strcmp(terminal, "dumb");
+}
+
 const char *git_editor(void)
 {
 	const char *editor = getenv("GIT_EDITOR");
-	const char *terminal = getenv("TERM");
-	int terminal_is_dumb = !terminal || !strcmp(terminal, "dumb");
+	int terminal_is_dumb = is_terminal_dumb();

 	if (!editor && editor_program)
 		editor = editor_program;
@@ -40,33 +45,11 @@ 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");
-		}
+		int print_waiting_for_editor = advice_waiting_for_editor &&
+			isatty(2) && !is_terminal_dumb();

-		if (close_notice) {
-			fprintf(stderr, _("Launched editor. Waiting for your input... "));
+		if (print_waiting_for_editor) {
+			fprintf(stderr, _("hint: Waiting for your editor input..."));
 			fflush(stderr);
 		}

@@ -82,14 +65,19 @@ 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 (print_waiting_for_editor)
+			/*
+			 * go back to the beginning and erase the
+			 * entire line to avoid wasting the vertical
+			 * space.
+			 */
+			fputs("\r\033[K", stderr);
 	}

 	if (!buffer)
diff --git a/sideband.c b/sideband.c
index 1e4d684d6c..6d7f943e43 100644
--- a/sideband.c
+++ b/sideband.c
@@ -20,13 +20,12 @@

 int recv_sideband(const char *me, int in_stream, int out)
 {
-	const char *term, *suffix;
+	const char *suffix;
 	char buf[LARGE_PACKET_MAX + 1];
 	struct strbuf outbuf = STRBUF_INIT;
 	int retval = 0;

-	term = getenv("TERM");
-	if (isatty(2) && term && strcmp(term, "dumb"))
+	if (isatty(2) && !is_terminal_dumb())
 		suffix = ANSI_SUFFIX;
 	else
 		suffix = DUMB_SUFFIX;


### Patches

Lars Schneider (2):
  refactor "dumb" terminal determination
  launch_editor(): indicate that Git waits for user input

 Documentation/config.txt |  3 +++
 advice.c                 |  2 ++
 advice.h                 |  1 +
 cache.h                  |  1 +
 color.c                  |  3 +--
 editor.c                 | 24 ++++++++++++++++++++++--
 sideband.c               |  5 ++---
 7 files changed, 32 insertions(+), 7 deletions(-)


base-commit: 89ea799ffcc5c8a0547d3c9075eb979256ee95b8
--
2.15.0
Next: lars.schneider@autodesk.com
Message 1 of 31 in “launch_editor(): indicate that Git waits for user input”
  1. 0/2 launch_editor(): indicate that Git waits for user inputlars.schneider@autodesk.com, Nov 29, 2017
  2. 1/2 refactor "dumb" terminal determinationlars.schneider@autodesk.com, Nov 29, 2017
  3. Jeff KingNov 30, 2017
  4. Kaartic SivaraamDec 1, 2017
  5. 2/2 launch_editor(): indicate that Git waits for user inputlars.schneider@autodesk.com, Nov 29, 2017
  6. Jeff KingNov 30, 2017
  7. Kaartic SivaraamDec 1, 2017
  8. Lars SchneiderDec 1, 2017
  9. Jeff KingDec 1, 2017
  10. Kaartic SivaraamDec 2, 2017
  11. Lars SchneiderDec 3, 2017
  12. Kaartic SivaraamDec 4, 2017
  13. Jeff KingDec 4, 2017
  14. Lars SchneiderDec 4, 2017
  15. Jeff KingDec 4, 2017
  16. Lars SchneiderDec 4, 2017
  17. Jeff KingDec 4, 2017
  18. Jeff KingDec 4, 2017
  19. Junio C HamanoDec 3, 2017
  20. Lars SchneiderDec 3, 2017
  21. Jeff KingDec 4, 2017
  22. Lars SchneiderDec 4, 2017
  23. Junio C HamanoDec 4, 2017
  24. Jeff KingDec 4, 2017
  25. Thomas AdamNov 29, 2017
  26. Lars SchneiderNov 30, 2017
  27. Thomas AdamNov 30, 2017
  28. Andreas SchwabNov 30, 2017
  29. Kaartic SivaraamDec 1, 2017
  30. Jeff KingNov 30, 2017
  31. Thomas AdamNov 30, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.