threads / patch / 36771

patchsideband.c: Get rid of ANSI sequences for non-terminal shell

Subject: [PATCH] sideband.c: Get rid of ANSI sequences for non-terminal shell

## tl;dr

2 messages between May 28, 2014 and May 29, 2014. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Naumov, Michael (North Sydney)· May 28, 2014, 03:12 UTC · lore

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(-)
Show changes to sideband.c +1 −1
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
Jeff King· May 29, 2014, 17:45 UTC · re: Naumov, Michael (North Sydney) · lore

Re: [PATCH] sideband.c: Get rid of ANSI sequences for non-terminal shell

On Wed, May 28, 2014 at 03:12:15AM +0000, Naumov, Michael (North Sydney) wrote:
Show 9 quoted lines
> 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

Please wrap your commit messages (and emails) at something reasonable to fit on an 80-char terminal with indentation (I usually use 60, but anything <= 72 is probably fine).

Other than that, I think the patch looks fine.
> 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!
This version looks OK to me (and applies via git-am).
-Peff

← back to recent threads