{"thread":{"id":"47395","subject":"[PATCH v5 0/2] launch_editor(): indicate that Git waits for user input","startedAt":"2017-12-07T15:17:29Z","lastAt":"2017-12-07T17:57:17Z","messageCount":10,"participants":["lars.schneider@autodesk.com","Junio C Hamano","Lars Schneider","Kaartic Sivaraam"],"isPatch":true,"patchVersion":5,"patchTotal":2},"messages":[{"id":"334319","messageId":"20171207151641.75065-1-lars.schneider@autodesk.com","threadId":"47395","inReplyTo":null,"subject":"[PATCH v5 0/2] launch_editor(): indicate that Git waits for user input","fromName":"","fromEmail":"lars.schneider@autodesk.com","sentAt":"2017-12-07T15:16:39Z","receivedAt":"2017-12-07T15:17:29Z","isPatch":true,"sender":{"key":"lars.schneider@autodesk.com","avatar":"https://gravatar.com/avatar/524188df3a38b02692619777bb90d9cc735db1ad75f5304e0bf09f8efd299775?d=mp&s=160"},"body":"From: Lars Schneider <larsxschneider@gmail.com>\n\nHi,\n\nPatch 1/2: No change. The patch got \"looks good to me\" from Peff [1]\n\nPatch 2/2: I changed the waiting message to our bikeshedding result [2] and\n           I enabled the waiting message on dumb terminals for consistency.\n\nI also tested the patch on OS X and Windows with smart and dumb terminals.\n\nThanks for the reviews,\nLars\n\n\n[1] https://public-inbox.org/git/20171130203042.GB3313@sigill.intra.peff.net/\n[2] https://public-inbox.org/git/20171204220908.GA8184@sigill.intra.peff.net/\n\nRFC: https://public-inbox.org/git/274B4850-2EB7-4BFA-A42C-25A573254969@gmail.com/\n v1: https://public-inbox.org/git/xmqqr2syvjxb.fsf@gitster.mtv.corp.google.com/\n v2: https://public-inbox.org/git/20171117135109.18071-1-lars.schneider@autodesk.com/\n v3: https://public-inbox.org/git/20171127134716.69471-1-lars.schneider@autodesk.com/\n v4: https://public-inbox.org/git/20171129143752.60553-1-lars.schneider@autodesk.com/\n\n\nBase Ref: master\nWeb-Diff: https://github.com/larsxschneider/git/commit/c00d4de8cf\nCheckout: git fetch https://github.com/larsxschneider/git editor-v5 && git checkout c00d4de8cf\n\n\n### Interdiff (v4..v5):\n\ndiff --git a/editor.c b/editor.c\nindex cdad4f74ec..d52017363c 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -45,11 +45,17 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\tconst char *args[] = { editor, real_path(path), NULL };\n \t\tstruct child_process p = CHILD_PROCESS_INIT;\n \t\tint ret, sig;\n-\t\tint print_waiting_for_editor = advice_waiting_for_editor &&\n-\t\t\tisatty(2) && !is_terminal_dumb();\n+\t\tint print_waiting_for_editor = advice_waiting_for_editor && isatty(2);\n\n \t\tif (print_waiting_for_editor) {\n-\t\t\tfprintf(stderr, _(\"hint: Waiting for your editor input...\"));\n+\t\t\tfprintf(stderr,\n+\t\t\t\t_(\"hint: Waiting for your editor to close the file... \"));\n+\t\t\tif (is_terminal_dumb())\n+\t\t\t\t/*\n+\t\t\t\t * A dumb terminal cannot erase the line later on. Add a\n+\t\t\t\t * newline to separate the hint from subsequent output.\n+\t\t\t\t */\n+\t\t\t\tfprintf(stderr, \"\\n\");\n \t\t\tfflush(stderr);\n \t\t}\n\n@@ -71,11 +77,10 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\t\treturn error(\"There was a problem with the editor '%s'.\",\n \t\t\t\t\teditor);\n\n-\t\tif (print_waiting_for_editor)\n+\t\tif (print_waiting_for_editor && !is_terminal_dumb())\n \t\t\t/*\n-\t\t\t * go back to the beginning and erase the\n-\t\t\t * entire line to avoid wasting the vertical\n-\t\t\t * space.\n+\t\t\t * Go back to the beginning and erase the entire line to\n+\t\t\t * avoid wasting the vertical space.\n \t\t\t */\n \t\t\tfputs(\"\\r\\033[K\", stderr);\n \t}\n\n\n### Patches\n\nLars Schneider (2):\n  refactor \"dumb\" terminal determination\n  launch_editor(): indicate that Git waits for user input\n\n Documentation/config.txt |  3 +++\n advice.c                 |  2 ++\n advice.h                 |  1 +\n cache.h                  |  1 +\n color.c                  |  3 +--\n editor.c                 | 29 +++++++++++++++++++++++++++--\n sideband.c               |  5 ++---\n 7 files changed, 37 insertions(+), 7 deletions(-)\n\n\nbase-commit: 89ea799ffcc5c8a0547d3c9075eb979256ee95b8\n--\n2.15.1\n\n"},{"id":"334320","messageId":"20171207151641.75065-2-lars.schneider@autodesk.com","threadId":"47395","inReplyTo":"20171207151641.75065-1-lars.schneider@autodesk.com","subject":"[PATCH v5 1/2] refactor \"dumb\" terminal determination","fromName":"","fromEmail":"lars.schneider@autodesk.com","sentAt":"2017-12-07T15:16:40Z","receivedAt":"2017-12-07T15:17:41Z","isPatch":true,"sender":{"key":"lars.schneider@autodesk.com","avatar":"https://gravatar.com/avatar/524188df3a38b02692619777bb90d9cc735db1ad75f5304e0bf09f8efd299775?d=mp&s=160"},"body":"From: Lars Schneider <larsxschneider@gmail.com>\n\nMove the code to detect \"dumb\" terminals into a single location. This\navoids duplicating the terminal detection code yet again in a subsequent\ncommit.\n\nSigned-off-by: Lars Schneider <larsxschneider@gmail.com>\n---\n cache.h    | 1 +\n color.c    | 3 +--\n editor.c   | 9 +++++++--\n sideband.c | 5 ++---\n 4 files changed, 11 insertions(+), 7 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 89f5d24579..3842fc097c 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1469,6 +1469,7 @@ extern const char *ident_default_name(void);\n extern const char *ident_default_email(void);\n extern const char *git_editor(void);\n extern const char *git_pager(int stdout_is_tty);\n+extern int is_terminal_dumb(void);\n extern int git_ident_config(const char *, const char *, void *);\n extern void reset_ident_date(void);\n \ndiff --git a/color.c b/color.c\nindex 9a9261ac16..d48dd947c9 100644\n--- a/color.c\n+++ b/color.c\n@@ -329,8 +329,7 @@ static int check_auto_color(void)\n \tif (color_stdout_is_tty < 0)\n \t\tcolor_stdout_is_tty = isatty(1);\n \tif (color_stdout_is_tty || (pager_in_use() && pager_use_color)) {\n-\t\tchar *term = getenv(\"TERM\");\n-\t\tif (term && strcmp(term, \"dumb\"))\n+\t\tif (!is_terminal_dumb())\n \t\t\treturn 1;\n \t}\n \treturn 0;\ndiff --git a/editor.c b/editor.c\nindex 7519edecdc..c65ea698eb 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -7,11 +7,16 @@\n #define DEFAULT_EDITOR \"vi\"\n #endif\n \n+int is_terminal_dumb(void)\n+{\n+\tconst char *terminal = getenv(\"TERM\");\n+\treturn !terminal || !strcmp(terminal, \"dumb\");\n+}\n+\n const char *git_editor(void)\n {\n \tconst char *editor = getenv(\"GIT_EDITOR\");\n-\tconst char *terminal = getenv(\"TERM\");\n-\tint terminal_is_dumb = !terminal || !strcmp(terminal, \"dumb\");\n+\tint terminal_is_dumb = is_terminal_dumb();\n \n \tif (!editor && editor_program)\n \t\teditor = editor_program;\ndiff --git a/sideband.c b/sideband.c\nindex 1e4d684d6c..6d7f943e43 100644\n--- a/sideband.c\n+++ b/sideband.c\n@@ -20,13 +20,12 @@\n \n int recv_sideband(const char *me, int in_stream, int out)\n {\n-\tconst char *term, *suffix;\n+\tconst char *suffix;\n \tchar buf[LARGE_PACKET_MAX + 1];\n \tstruct strbuf outbuf = STRBUF_INIT;\n \tint retval = 0;\n \n-\tterm = getenv(\"TERM\");\n-\tif (isatty(2) && term && strcmp(term, \"dumb\"))\n+\tif (isatty(2) && !is_terminal_dumb())\n \t\tsuffix = ANSI_SUFFIX;\n \telse\n \t\tsuffix = DUMB_SUFFIX;\n-- \n2.15.1\n\n"},{"id":"334321","messageId":"20171207151641.75065-3-lars.schneider@autodesk.com","threadId":"47395","inReplyTo":"20171207151641.75065-1-lars.schneider@autodesk.com","subject":"[PATCH v5 2/2] launch_editor(): indicate that Git waits for user input","fromName":"","fromEmail":"lars.schneider@autodesk.com","sentAt":"2017-12-07T15:16:41Z","receivedAt":"2017-12-07T15:17:56Z","isPatch":true,"sender":{"key":"lars.schneider@autodesk.com","avatar":"https://gravatar.com/avatar/524188df3a38b02692619777bb90d9cc735db1ad75f5304e0bf09f8efd299775?d=mp&s=160"},"body":"From: Lars Schneider <larsxschneider@gmail.com>\n\nWhen a graphical GIT_EDITOR is spawned by a Git command that opens\nand waits for user input (e.g. \"git rebase -i\"), then the editor window\nmight be obscured by other windows. The user might be left staring at\nthe original Git terminal window without even realizing that s/he needs\nto interact with another window before Git can proceed. To this user Git\nappears hanging.\n\nPrint a message that Git is waiting for editor input in the original\nterminal and get rid of it when the editor returns (if the terminal\nsupports erasing the last line).\n\nPower users might not want to see this message or their editor might\nalready print such a message (e.g. emacsclient). Allow these users to\nsuppress the message by disabling the \"advice.waitingForEditor\" config.\n\nThe standard advise() function is not used here as it would always add\na newline which would make deleting the message harder.\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Lars Schneider <larsxschneider@gmail.com>\n---\n Documentation/config.txt |  3 +++\n advice.c                 |  2 ++\n advice.h                 |  1 +\n editor.c                 | 20 ++++++++++++++++++++\n 4 files changed, 26 insertions(+)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 671fcbaa0f..de64201e82 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -354,6 +354,9 @@ advice.*::\n \tignoredHook::\n \t\tAdvice shown if an hook is ignored because the hook is not\n \t\tset as executable.\n+\twaitingForEditor::\n+\t\tPrint a message to the terminal whenever Git is waiting for\n+\t\teditor input from the user.\n --\n \n core.fileMode::\ndiff --git a/advice.c b/advice.c\nindex c6169bcb52..406efc183b 100644\n--- a/advice.c\n+++ b/advice.c\n@@ -18,6 +18,7 @@ int advice_object_name_warning = 1;\n int advice_rm_hints = 1;\n int advice_add_embedded_repo = 1;\n int advice_ignored_hook = 1;\n+int advice_waiting_for_editor = 1;\n \n static struct {\n \tconst char *name;\n@@ -40,6 +41,7 @@ static struct {\n \t{ \"rmhints\", &advice_rm_hints },\n \t{ \"addembeddedrepo\", &advice_add_embedded_repo },\n \t{ \"ignoredhook\", &advice_ignored_hook },\n+\t{ \"waitingforeditor\", &advice_waiting_for_editor },\n \n \t/* make this an alias for backward compatibility */\n \t{ \"pushnonfastforward\", &advice_push_update_rejected }\ndiff --git a/advice.h b/advice.h\nindex f525d6f89c..70568fa792 100644\n--- a/advice.h\n+++ b/advice.h\n@@ -20,6 +20,7 @@ extern int advice_object_name_warning;\n extern int advice_rm_hints;\n extern int advice_add_embedded_repo;\n extern int advice_ignored_hook;\n+extern int advice_waiting_for_editor;\n \n int git_default_advice_config(const char *var, const char *value);\n __attribute__((format (printf, 1, 2)))\ndiff --git a/editor.c b/editor.c\nindex c65ea698eb..d52017363c 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -45,6 +45,19 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\tconst char *args[] = { editor, real_path(path), NULL };\n \t\tstruct child_process p = CHILD_PROCESS_INIT;\n \t\tint ret, sig;\n+\t\tint print_waiting_for_editor = advice_waiting_for_editor && isatty(2);\n+\n+\t\tif (print_waiting_for_editor) {\n+\t\t\tfprintf(stderr,\n+\t\t\t\t_(\"hint: Waiting for your editor to close the file... \"));\n+\t\t\tif (is_terminal_dumb())\n+\t\t\t\t/*\n+\t\t\t\t * A dumb terminal cannot erase the line later on. Add a\n+\t\t\t\t * newline to separate the hint from subsequent output.\n+\t\t\t\t */\n+\t\t\t\tfprintf(stderr, \"\\n\");\n+\t\t\tfflush(stderr);\n+\t\t}\n \n \t\tp.argv = args;\n \t\tp.env = env;\n@@ -63,6 +76,13 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\tif (ret)\n \t\t\treturn error(\"There was a problem with the editor '%s'.\",\n \t\t\t\t\teditor);\n+\n+\t\tif (print_waiting_for_editor && !is_terminal_dumb())\n+\t\t\t/*\n+\t\t\t * Go back to the beginning and erase the entire line to\n+\t\t\t * avoid wasting the vertical space.\n+\t\t\t */\n+\t\t\tfputs(\"\\r\\033[K\", stderr);\n \t}\n \n \tif (!buffer)\n-- \n2.15.1\n\n"},{"id":"334327","messageId":"xmqqr2s6ee7e.fsf@gitster.mtv.corp.google.com","threadId":"47395","inReplyTo":"20171207151641.75065-3-lars.schneider@autodesk.com","subject":"Re: [PATCH v5 2/2] launch_editor(): indicate that Git waits for user input","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-12-07T15:43:17Z","receivedAt":"2017-12-07T15:43:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"lars.schneider@autodesk.com writes:\n\n> +\t\tif (print_waiting_for_editor) {\n> +\t\t\tfprintf(stderr,\n> +\t\t\t\t_(\"hint: Waiting for your editor to close the file... \"));\n> +\t\t\tif (is_terminal_dumb())\n> +\t\t\t\t/*\n> +\t\t\t\t * A dumb terminal cannot erase the line later on. Add a\n> +\t\t\t\t * newline to separate the hint from subsequent output.\n> +\t\t\t\t */\n> +\t\t\t\tfprintf(stderr, \"\\n\");\n> +\t\t\tfflush(stderr);\n> +\t\t}\n\nWas the trailing whitespace at the end of the hint message intended?\n\nIf we expect the editor to spit out additional garbage on the line,\nit would probably help to have that SP, but if that is why we have it\nthere, it probably should be done only when !is_terminal_dumb().\n\nIf the trailing SP is merely there by accident, then removal without\nchanging anything else is also OK.\n\nI cannot tell which is the case, hence this comment.\n\nThanks.\n"},{"id":"334329","messageId":"D17F94FA-702E-4E37-BDA5-94F0FFD5BD01@gmail.com","threadId":"47395","inReplyTo":"FCBDBD58-0593-4FFC-B574-61D67CAF13C6@gmail.com","subject":"Re: [PATCH v5 2/2] launch_editor(): indicate that Git waits for user input","fromName":"Lars Schneider","fromEmail":"larsxschneider@gmail.com","sentAt":"2017-12-07T16:16:13Z","receivedAt":"2017-12-07T16:16:30Z","isPatch":true,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"\n> On 07 Dec 2017, at 16:48, Lars Schneider <larsxschneider@gmail.com> wrote:\n> \n> \n>> On 07 Dec 2017, at 16:43, Junio C Hamano <gitster@pobox.com> wrote:\n>> \n>> lars.schneider@autodesk.com writes:\n>> ...\n> \n> How about this?\n> \n> \t\t\tfprintf(stderr,\n> \t\t\t\t_(\"hint: Waiting for your editor to close the file...\"));\n> \t\t\tif (is_terminal_dumb())\n> \t\t\t\t/*\n> \t\t\t\t * A dumb terminal cannot erase the line later on. Add a\n> \t\t\t\t * newline to separate the hint from subsequent output.\n> \t\t\t\t */\n> \t\t\t\tfprintf(stderr, \"\\n\")\n> \t\t\telse\n> \t\t\t\tfprintf(stderr, \" \")\n> \n\nI forgot the \";\" ... switching between programming languages ;-)\n\n\t\t\tif (is_terminal_dumb())\n\t\t\t\t/*\n\t\t\t\t * A dumb terminal cannot erase the line later on. Add a\n\t\t\t\t * newline to separate the hint from subsequent output.\n\t\t\t\t */\n\t\t\t\tfprintf(stderr, \"\\n\");\n\t\t\telse\n\t\t\t\tfprintf(stderr, \" \");\n\n\n\n> Can you squash that if you like it?\n> \n> Thanks,\n> Lars\n\n"},{"id":"334330","messageId":"xmqqmv2uec0p.fsf@gitster.mtv.corp.google.com","threadId":"47395","inReplyTo":"D17F94FA-702E-4E37-BDA5-94F0FFD5BD01@gmail.com","subject":"Re: [PATCH v5 2/2] launch_editor(): indicate that Git waits for user input","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-12-07T16:30:30Z","receivedAt":"2017-12-07T16:30:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Lars Schneider <larsxschneider@gmail.com> writes:\n\n>> Can you squash that if you like it?\n\nI thought you also had to update the log message that you forgot to?\n\nHere is the replacement I queued tentatively.\n\n-- >8 --\nFrom: Lars Schneider <larsxschneider@gmail.com>\nDate: Thu, 7 Dec 2017 16:16:41 +0100\nSubject: [PATCH] launch_editor(): indicate that Git waits for user input\n\nWhen a graphical GIT_EDITOR is spawned by a Git command that opens\nand waits for user input (e.g. \"git rebase -i\"), then the editor window\nmight be obscured by other windows. The user might be left staring at\nthe original Git terminal window without even realizing that s/he needs\nto interact with another window before Git can proceed. To this user Git\nappears hanging.\n\nPrint a message that Git is waiting for editor input in the original\nterminal and get rid of it when the editor returns, if the terminal\nsupports erasing the last line.  Also, make sure that our message is\nterminated with a whitespace so that any message the editor may show\nupon starting up will be kept separate from our message.\n\nPower users might not want to see this message or their editor might\nalready print such a message (e.g. emacsclient). Allow these users to\nsuppress the message by disabling the \"advice.waitingForEditor\" config.\n\nThe standard advise() function is not used here as it would always add\na newline which would make deleting the message harder.\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Lars Schneider <larsxschneider@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/config.txt |  3 +++\n advice.c                 |  2 ++\n advice.h                 |  1 +\n editor.c                 | 24 ++++++++++++++++++++++++\n 4 files changed, 30 insertions(+)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 9593bfabaa..6ebc50eea8 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -351,6 +351,9 @@ advice.*::\n \taddEmbeddedRepo::\n \t\tAdvice on what to do when you've accidentally added one\n \t\tgit repo inside of another.\n+\twaitingForEditor::\n+\t\tPrint a message to the terminal whenever Git is waiting for\n+\t\teditor input from the user.\n --\n \n core.fileMode::\ndiff --git a/advice.c b/advice.c\nindex d81e1cb742..af29d23e43 100644\n--- a/advice.c\n+++ b/advice.c\n@@ -17,6 +17,7 @@ int advice_set_upstream_failure = 1;\n int advice_object_name_warning = 1;\n int advice_rm_hints = 1;\n int advice_add_embedded_repo = 1;\n+int advice_waiting_for_editor = 1;\n \n static struct {\n \tconst char *name;\n@@ -38,6 +39,7 @@ static struct {\n \t{ \"objectnamewarning\", &advice_object_name_warning },\n \t{ \"rmhints\", &advice_rm_hints },\n \t{ \"addembeddedrepo\", &advice_add_embedded_repo },\n+\t{ \"waitingforeditor\", &advice_waiting_for_editor },\n \n \t/* make this an alias for backward compatibility */\n \t{ \"pushnonfastforward\", &advice_push_update_rejected }\ndiff --git a/advice.h b/advice.h\nindex c84a44531c..f7cbbd342f 100644\n--- a/advice.h\n+++ b/advice.h\n@@ -19,6 +19,7 @@ extern int advice_set_upstream_failure;\n extern int advice_object_name_warning;\n extern int advice_rm_hints;\n extern int advice_add_embedded_repo;\n+extern int advice_waiting_for_editor;\n \n int git_default_advice_config(const char *var, const char *value);\n __attribute__((format (printf, 1, 2)))\ndiff --git a/editor.c b/editor.c\nindex c65ea698eb..8acce0dcd4 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -45,6 +45,23 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\tconst char *args[] = { editor, real_path(path), NULL };\n \t\tstruct child_process p = CHILD_PROCESS_INIT;\n \t\tint ret, sig;\n+\t\tint print_waiting_for_editor = advice_waiting_for_editor && isatty(2);\n+\n+\t\tif (print_waiting_for_editor) {\n+\t\t\t/*\n+\t\t\t * A dumb terminal cannot erase the line later on. Add a\n+\t\t\t * newline to separate the hint from subsequent output.\n+\t\t\t *\n+\t\t\t * In case the editor emits further cruft after what\n+\t\t\t * we wrote above, separate it from our message with SP.\n+\t\t\t */\n+\t\t\tconst char term = is_terminal_dumb() ? '\\n' : ' ';\n+\n+\t\t\tfprintf(stderr,\n+\t\t\t\t_(\"hint: Waiting for your editor to close the file...%c\"),\n+\t\t\t\tterm);\n+\t\t\tfflush(stderr);\n+\t\t}\n \n \t\tp.argv = args;\n \t\tp.env = env;\n@@ -63,6 +80,13 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n \t\tif (ret)\n \t\t\treturn error(\"There was a problem with the editor '%s'.\",\n \t\t\t\t\teditor);\n+\n+\t\tif (print_waiting_for_editor && !is_terminal_dumb())\n+\t\t\t/*\n+\t\t\t * Go back to the beginning and erase the entire line to\n+\t\t\t * avoid wasting the vertical space.\n+\t\t\t */\n+\t\t\tfputs(\"\\r\\033[K\", stderr);\n \t}\n \n \tif (!buffer)\n-- \n2.15.1-480-gbc5668f98a\n\n"},{"id":"334331","messageId":"D5CBD713-5F68-4704-B110-66689A1678E0@gmail.com","threadId":"47395","inReplyTo":"xmqqmv2uec0p.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v5 2/2] launch_editor(): indicate that Git waits for user input","fromName":"Lars Schneider","fromEmail":"larsxschneider@gmail.com","sentAt":"2017-12-07T16:36:19Z","receivedAt":"2017-12-07T16:36:37Z","isPatch":true,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"\n> On 07 Dec 2017, at 17:30, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> Lars Schneider <larsxschneider@gmail.com> writes:\n> \n>>> Can you squash that if you like it?\n> \n> I thought you also had to update the log message that you forgot to?\n> \n> Here is the replacement I queued tentatively.\n\nPerfect. Thanks a lot for your additional fixes!\n\n- Lars\n\n> \n> -- >8 --\n> From: Lars Schneider <larsxschneider@gmail.com>\n> Date: Thu, 7 Dec 2017 16:16:41 +0100\n> Subject: [PATCH] launch_editor(): indicate that Git waits for user input\n> \n> When a graphical GIT_EDITOR is spawned by a Git command that opens\n> and waits for user input (e.g. \"git rebase -i\"), then the editor window\n> might be obscured by other windows. The user might be left staring at\n> the original Git terminal window without even realizing that s/he needs\n> to interact with another window before Git can proceed. To this user Git\n> appears hanging.\n> \n> Print a message that Git is waiting for editor input in the original\n> terminal and get rid of it when the editor returns, if the terminal\n> supports erasing the last line.  Also, make sure that our message is\n> terminated with a whitespace so that any message the editor may show\n> upon starting up will be kept separate from our message.\n> \n> Power users might not want to see this message or their editor might\n> already print such a message (e.g. emacsclient). Allow these users to\n> suppress the message by disabling the \"advice.waitingForEditor\" config.\n> \n> The standard advise() function is not used here as it would always add\n> a newline which would make deleting the message harder.\n> \n> Helped-by: Junio C Hamano <gitster@pobox.com>\n> Signed-off-by: Lars Schneider <larsxschneider@gmail.com>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> Documentation/config.txt |  3 +++\n> advice.c                 |  2 ++\n> advice.h                 |  1 +\n> editor.c                 | 24 ++++++++++++++++++++++++\n> 4 files changed, 30 insertions(+)\n> \n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index 9593bfabaa..6ebc50eea8 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -351,6 +351,9 @@ advice.*::\n> \taddEmbeddedRepo::\n> \t\tAdvice on what to do when you've accidentally added one\n> \t\tgit repo inside of another.\n> +\twaitingForEditor::\n> +\t\tPrint a message to the terminal whenever Git is waiting for\n> +\t\teditor input from the user.\n> --\n> \n> core.fileMode::\n> diff --git a/advice.c b/advice.c\n> index d81e1cb742..af29d23e43 100644\n> --- a/advice.c\n> +++ b/advice.c\n> @@ -17,6 +17,7 @@ int advice_set_upstream_failure = 1;\n> int advice_object_name_warning = 1;\n> int advice_rm_hints = 1;\n> int advice_add_embedded_repo = 1;\n> +int advice_waiting_for_editor = 1;\n> \n> static struct {\n> \tconst char *name;\n> @@ -38,6 +39,7 @@ static struct {\n> \t{ \"objectnamewarning\", &advice_object_name_warning },\n> \t{ \"rmhints\", &advice_rm_hints },\n> \t{ \"addembeddedrepo\", &advice_add_embedded_repo },\n> +\t{ \"waitingforeditor\", &advice_waiting_for_editor },\n> \n> \t/* make this an alias for backward compatibility */\n> \t{ \"pushnonfastforward\", &advice_push_update_rejected }\n> diff --git a/advice.h b/advice.h\n> index c84a44531c..f7cbbd342f 100644\n> --- a/advice.h\n> +++ b/advice.h\n> @@ -19,6 +19,7 @@ extern int advice_set_upstream_failure;\n> extern int advice_object_name_warning;\n> extern int advice_rm_hints;\n> extern int advice_add_embedded_repo;\n> +extern int advice_waiting_for_editor;\n> \n> int git_default_advice_config(const char *var, const char *value);\n> __attribute__((format (printf, 1, 2)))\n> diff --git a/editor.c b/editor.c\n> index c65ea698eb..8acce0dcd4 100644\n> --- a/editor.c\n> +++ b/editor.c\n> @@ -45,6 +45,23 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n> \t\tconst char *args[] = { editor, real_path(path), NULL };\n> \t\tstruct child_process p = CHILD_PROCESS_INIT;\n> \t\tint ret, sig;\n> +\t\tint print_waiting_for_editor = advice_waiting_for_editor && isatty(2);\n> +\n> +\t\tif (print_waiting_for_editor) {\n> +\t\t\t/*\n> +\t\t\t * A dumb terminal cannot erase the line later on. Add a\n> +\t\t\t * newline to separate the hint from subsequent output.\n> +\t\t\t *\n> +\t\t\t * In case the editor emits further cruft after what\n> +\t\t\t * we wrote above, separate it from our message with SP.\n> +\t\t\t */\n> +\t\t\tconst char term = is_terminal_dumb() ? '\\n' : ' ';\n> +\n> +\t\t\tfprintf(stderr,\n> +\t\t\t\t_(\"hint: Waiting for your editor to close the file...%c\"),\n> +\t\t\t\tterm);\n> +\t\t\tfflush(stderr);\n> +\t\t}\n> \n> \t\tp.argv = args;\n> \t\tp.env = env;\n> @@ -63,6 +80,13 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n> \t\tif (ret)\n> \t\t\treturn error(\"There was a problem with the editor '%s'.\",\n> \t\t\t\t\teditor);\n> +\n> +\t\tif (print_waiting_for_editor && !is_terminal_dumb())\n> +\t\t\t/*\n> +\t\t\t * Go back to the beginning and erase the entire line to\n> +\t\t\t * avoid wasting the vertical space.\n> +\t\t\t */\n> +\t\t\tfputs(\"\\r\\033[K\", stderr);\n> \t}\n> \n> \tif (!buffer)\n> -- \n> 2.15.1-480-gbc5668f98a\n> \n\n"},{"id":"334337","messageId":"dfb2cde5-a499-8da3-9695-8c8fd46a96ad@gmail.com","threadId":"47395","inReplyTo":"xmqqmv2uec0p.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v5 2/2] launch_editor(): indicate that Git waits for user input","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2017-12-07T17:37:46Z","receivedAt":"2017-12-07T17:40:52Z","isPatch":true,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"On Thursday 07 December 2017 10:00 PM, Junio C Hamano wrote:\n> +\n> +\t\tif (print_waiting_for_editor) {\n> +\t\t\t/*\n> +\t\t\t * A dumb terminal cannot erase the line later on. Add a\n> +\t\t\t * newline to separate the hint from subsequent output.\n> +\t\t\t *\n\n\n> +\t\t\t * In case the editor emits further cruft after what\n> +\t\t\t * we wrote above, separate it from our message with SP.\n\nI guess this part of the comment could be improved a little. I currently \ninterpret it as \"See if the editor emits further cruft, print a space in \nthat case\". Though, it's not what we are doing. Something like the \nfollowing, perhaps?\n\n      In a non-dumb terminal, separate our message from further cruft\n      that might be emitted by the editor with SP.\n\n\n\n> +\t\t\t */\n> +\t\t\tconst char term = is_terminal_dumb() ? '\\n' : ' ';\n> +\n> +\t\t\tfprintf(stderr,\n> +\t\t\t\t_(\"hint: Waiting for your editor to close the file...%c\"),\n> +\t\t\t\tterm);\n> +\t\t\tfflush(stderr);\n> +\t\t}\n>   \n>   \t\tp.argv = args;\n>   \t\tp.env = env;\n> @@ -63,6 +80,13 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n>   \t\tif (ret)\n>   \t\t\treturn error(\"There was a problem with the editor '%s'.\",\n>   \t\t\t\t\teditor);\n> +\n> +\t\tif (print_waiting_for_editor && !is_terminal_dumb())\n> +\t\t\t/*\n> +\t\t\t * Go back to the beginning and erase the entire line to\n> +\t\t\t * avoid wasting the vertical space.\n> +\t\t\t */\n> +\t\t\tfputs(\"\\r\\033[K\", stderr);\n>   \t}\n>   \n>   \tif (!buffer)\n> \n\n"},{"id":"334338","messageId":"FCBDBD58-0593-4FFC-B574-61D67CAF13C6@gmail.com","threadId":"47395","inReplyTo":"xmqqr2s6ee7e.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v5 2/2] launch_editor(): indicate that Git waits for user input","fromName":"Lars Schneider","fromEmail":"larsxschneider@gmail.com","sentAt":"2017-12-07T15:48:57Z","receivedAt":"2017-12-07T17:53:57Z","isPatch":true,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"\n> On 07 Dec 2017, at 16:43, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> lars.schneider@autodesk.com writes:\n> \n>> +\t\tif (print_waiting_for_editor) {\n>> +\t\t\tfprintf(stderr,\n>> +\t\t\t\t_(\"hint: Waiting for your editor to close the file... \"));\n>> +\t\t\tif (is_terminal_dumb())\n>> +\t\t\t\t/*\n>> +\t\t\t\t * A dumb terminal cannot erase the line later on. Add a\n>> +\t\t\t\t * newline to separate the hint from subsequent output.\n>> +\t\t\t\t */\n>> +\t\t\t\tfprintf(stderr, \"\\n\");\n>> +\t\t\tfflush(stderr);\n>> +\t\t}\n> \n> Was the trailing whitespace at the end of the hint message intended?\n> \n> If we expect the editor to spit out additional garbage on the line,\n> it would probably help to have that SP,\n\nArgh. I forgot to mention that in the cover letter. Yes, I added\nthe whitespace intentionally for exactly that reason.\n\n\n> but if that is why we have it\n> there, it probably should be done only when !is_terminal_dumb().\n\nThat, of course, is correct. My intention was to make the code simpler\nbut I can see that people would be confused about the whitespace.\n\nHow about this?\n\n\t\t\tfprintf(stderr,\n\t\t\t\t_(\"hint: Waiting for your editor to close the file...\"));\n\t\t\tif (is_terminal_dumb())\n\t\t\t\t/*\n\t\t\t\t * A dumb terminal cannot erase the line later on. Add a\n\t\t\t\t * newline to separate the hint from subsequent output.\n\t\t\t\t */\n\t\t\t\tfprintf(stderr, \"\\n\")\n\t\t\telse\n\t\t\t\tfprintf(stderr, \" \")\n\nCan you squash that if you like it?\n\nThanks,\nLars\n"},{"id":"334340","messageId":"84C88A13-FB21-425A-BEB2-C9041848CA67@gmail.com","threadId":"47395","inReplyTo":"dfb2cde5-a499-8da3-9695-8c8fd46a96ad@gmail.com","subject":"Re: [PATCH v5 2/2] launch_editor(): indicate that Git waits for user input","fromName":"Lars Schneider","fromEmail":"larsxschneider@gmail.com","sentAt":"2017-12-07T17:56:59Z","receivedAt":"2017-12-07T17:57:17Z","isPatch":true,"sender":{"key":"larsxschneider@gmail.com","avatar":"https://avatars.githubusercontent.com/u/477434?v=4"},"body":"\n> On 07 Dec 2017, at 18:37, Kaartic Sivaraam <kaartic.sivaraam@gmail.com> wrote:\n> \n> On Thursday 07 December 2017 10:00 PM, Junio C Hamano wrote:\n>> +\n>> +\t\tif (print_waiting_for_editor) {\n>> +\t\t\t/*\n>> +\t\t\t * A dumb terminal cannot erase the line later on. Add a\n>> +\t\t\t * newline to separate the hint from subsequent output.\n>> +\t\t\t *\n> \n> \n>> +\t\t\t * In case the editor emits further cruft after what\n>> +\t\t\t * we wrote above, separate it from our message with SP.\n> \n> I guess this part of the comment could be improved a little. I currently interpret it as \"See if the editor emits further cruft, print a space in that case\". Though, it's not what we are doing. Something like the following, perhaps?\n> \n>     In a non-dumb terminal, separate our message from further cruft\n>     that might be emitted by the editor with SP.\n\nI see what you mean. My (non-native) language feeling tells me that\nreordering the sentence might sound better:\n\n\t\t\t\t * In a non-dumb terminal, separate our message with SP\n\t\t\t\t * from further cruft that might be emitted by the editor.\n\n\n@Junio: If you agree with the change, can you squash either of the new versions? \n\nThanks,\nLars"}]}