git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sideband.c: Get rid of ANSI sequences for non-terminal shell
@ 2014-05-28  3:12 Naumov, Michael (North Sydney)
  2014-05-29 17:45 ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Naumov, Michael (North Sydney) @ 2014-05-28  3:12 UTC (permalink / raw)
  To: Junio C Hamano, git
  Cc: peff@peff.net, spearce@spearce.org, j6t@kdbg.org, nico@cam.org,
	junkio@cox.net, kusmabite@gmail.com, mnaoumov@gmail.com

Some git tools such as GitExtensions for Windows use environment variable TERM=msys which causes the weird ANSI sequence shown for the messages returned from server-side hooks
We add those ANSI sequences to help format sideband data on the user's terminal. However, GitExtensions is not using a terminal, and the ANSI sequences just confuses it. We can recognize this use by checking isatty().
See https://github.com/gitextensions/gitextensions/issues/1313 for more details

NOTE: I considered to cover the case that a pager has already been started. But decided that is probably not worth worrying about here, though, as we shouldn't be using a pager for commands that do network communications (and if we do, omitting the magic line-clearing signal is probably a sane thing to do).

Signed-off-by: Michael Naumov <mnaoumov@gmail.com>
Thanks-to: Erik Faye-Lund <kusmabite@gmail.com>
Thanks-to: Jeff King <peff@peff.net>
---
 sideband.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sideband.c b/sideband.c
index d1125f5..7f9dc22 100644
--- a/sideband.c
+++ b/sideband.c
@@ -30,7 +30,7 @@ int recv_sideband(const char *me, int in_stream, int out)
 
 	memcpy(buf, PREFIX, pf);
 	term = getenv("TERM");
-	if (term && strcmp(term, "dumb"))
+	if (isatty(2) && term && strcmp(term, "dumb"))
 		suffix = ANSI_SUFFIX;
 	else
 		suffix = DUMB_SUFFIX;
-- 
1.8.3.msysgit.0

P.S. I gave up trying to send this letter from gmail, it eats my tab character
P.S 2. Sorry, my tab character has been eaten again!

Regards,
Michael

^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] sideband.c: Get rid of ANSI sequences for non-terminal shell
@ 2014-05-30 23:10 Naumov, Michael (North Sydney)
  2014-06-02  6:30 ` Jeff King
  2014-06-02 17:59 ` Junio C Hamano
  0 siblings, 2 replies; 6+ messages in thread
From: Naumov, Michael (North Sydney) @ 2014-05-30 23:10 UTC (permalink / raw)
  To: Junio C Hamano, git
  Cc: peff@peff.net, spearce@spearce.org, j6t@kdbg.org, nico@cam.org,
	junkio@cox.net, kusmabite@gmail.com, mnaoumov@gmail.com

Some git tools such as GitExtensions for Windows use environment
variable TERM=msys which causes the weird ANSI sequence shown for the
messages returned from server-side hooks
We add those ANSI sequences to help format sideband data on the user's
terminal. However, GitExtensions is not using a terminal, and the ANSI
sequences just confuses it. We can recognize this use by checking
isatty().
See https://github.com/gitextensions/gitextensions/issues/1313 for
more details

NOTE: I considered to cover the case that a pager has already been
started. But decided that is probably not worth worrying about here,
though, as we shouldn't be using a pager for commands that do network
communications (and if we do, omitting the magic line-clearing signal
is probably a sane thing to do).

Signed-off-by: Michael Naumov <mnaoumov@gmail.com>
Thanks-to: Erik Faye-Lund <kusmabite@gmail.com>
Thanks-to: Jeff King <peff@peff.net>
---
 sideband.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sideband.c b/sideband.c
index d1125f5..7f9dc22 100644
--- a/sideband.c
+++ b/sideband.c
@@ -30,7 +30,7 @@ int recv_sideband(const char *me, int in_stream, int out)
 
 	memcpy(buf, PREFIX, pf);
 	term = getenv("TERM");
-	if (term && strcmp(term, "dumb"))
+	if (isatty(2) && term && strcmp(term, "dumb"))
 		suffix = ANSI_SUFFIX;
 	else
 		suffix = DUMB_SUFFIX;
-- 
1.8.3.msysgit.0

P.S. I gave up trying to send this letter from gmail, it eats my tab
character
P.S 2. Sorry, my tab character has been eaten again!
P.S 3. Wrapped the letter lines to fit on the terminal

Regards,
Michael

^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] sideband.c: Get rid of ANSI sequences for non-terminal shell
@ 2014-06-02 23:40 Naumov, Michael (North Sydney)
  0 siblings, 0 replies; 6+ messages in thread
From: Naumov, Michael (North Sydney) @ 2014-06-02 23:40 UTC (permalink / raw)
  To: Junio C Hamano, git
  Cc: peff@peff.net, spearce@spearce.org, j6t@kdbg.org, nico@cam.org,
	junkio@cox.net, kusmabite@gmail.com, mnaoumov@gmail.com

From: Michael Naumov <mnaoumov@gmail.com>

Diagnostic messages received on the sideband #2 from the server side
are sent to the standard error with ANSI terminal control sequence
"\033[K" that erases to the end of line appended at the end of each
line.

However, some programs (e.g. GitExtensions for Windows) read and
interpret and/or show the message without understanding the terminal
control sequences, resulting them to be shown to their end users.
To help these programs, squelch the control sequence when the
standard error stream is not being sent to a tty.

NOTE: I considered to cover the case that a pager has already been 
started. But decided that is probably not worth worrying about here, 
though, as we shouldn't be using a pager for commands that do network 
communications (and if we do, omitting the magic line-clearing signal 
is probably a sane thing to do).

Signed-off-by: Michael Naumov <mnaoumov@gmail.com>
Thanks-to: Erik Faye-Lund <kusmabite@gmail.com>
Thanks-to: Jeff King <peff@peff.net>
---
 sideband.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sideband.c b/sideband.c
index d1125f5..7f9dc22 100644
--- a/sideband.c
+++ b/sideband.c
@@ -30,7 +30,7 @@ int recv_sideband(const char *me, int in_stream, int out)
 
 	memcpy(buf, PREFIX, pf);
 	term = getenv("TERM");
-	if (term && strcmp(term, "dumb"))
+	if (isatty(2) && term && strcmp(term, "dumb"))
 		suffix = ANSI_SUFFIX;
 	else
 		suffix = DUMB_SUFFIX;
-- 
1.8.3.msysgit.0

P.S. I gave up trying to send this letter from gmail, it eats my tab
character
P.S 2. Sorry, my tab character has been eaten again!
P.S 3. Wrapped the letter lines to fit on the terminal
P.S 4. GitExtensions tried to use TERM=dumb but this caused process leakage for diff tools. See https://github.com/gitextensions/gitextensions/issues/1092

Regards,
Michael

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

end of thread, other threads:[~2014-06-02 23:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-28  3:12 [PATCH] sideband.c: Get rid of ANSI sequences for non-terminal shell Naumov, Michael (North Sydney)
2014-05-29 17:45 ` Jeff King
  -- strict thread matches above, loose matches on Subject: below --
2014-05-30 23:10 Naumov, Michael (North Sydney)
2014-06-02  6:30 ` Jeff King
2014-06-02 17:59 ` Junio C Hamano
2014-06-02 23:40 Naumov, Michael (North Sydney)

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 NNTP newsgroup(s).