{"thread":{"id":"11534","subject":"[PATCH 2/2] recv_sideband: Do not use ANSI escape sequence on dumb terminals.","startedAt":"2008-01-08T16:24:53Z","lastAt":"2008-01-08T16:24:53Z","messageCount":1,"participants":["Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"64749","messageId":"4783A3D5.70309@viscovery.net","threadId":"11534","inReplyTo":null,"subject":"[PATCH 2/2] recv_sideband: Do not use ANSI escape sequence on dumb terminals.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-01-08T16:24:53Z","receivedAt":"2008-01-08T16:24:53Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"From: Johannes Sixt <johannes.sixt@telecom.at>\n\nThe \"clear to end of line\" sequence is used to nicely output the progress\nindicator without leaving garbage on the terminal. However, this works\nonly on ANSI capable terminals. We use the same check as in color.c to\nfind out whether the terminal supports this feature and use a workaround\n(a few spaces in a row) if it does not.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n sideband.c |   13 ++++++++++---\n 1 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/sideband.c b/sideband.c\nindex 513d7b3..0873e69 100644\n--- a/sideband.c\n+++ b/sideband.c\n@@ -13,15 +13,22 @@\n  */\n\n #define PREFIX \"remote:\"\n-#define SUFFIX \"\\033[K\"  /* change to \"        \" if ANSI sequences don't work */\n\n int recv_sideband(const char *me, int in_stream, int out, int err)\n {\n \tunsigned pf = strlen(PREFIX);\n-\tunsigned sf = strlen(SUFFIX);\n+\tunsigned sf;\n \tchar *buf, *save;\n+\tchar *suffix, *term;\n\n+\tterm = getenv(\"TERM\");\n+\tif (term && strcmp(term, \"dumb\"))\n+\t\tsuffix = \"\\033[K\";\n+\telse\n+\t\tsuffix = \"        \";\n+\tsf = strlen(suffix);\n \tsave = xmalloc(sf);\n+\n \tbuf = xmalloc(pf + LARGE_PACKET_MAX + sf + 1);\n \tmemcpy(buf, PREFIX, pf);\n \twhile (1) {\n@@ -68,7 +75,7 @@ int recv_sideband(const char *me, int in_stream, int out, int err)\n \t\t\t\tif (brk > pf+1 + 1) {\n \t\t\t\t\tmemcpy(save, buf + brk, sf);\n \t\t\t\t\tbuf[brk + sf - 1] = buf[brk - 1];\n-\t\t\t\t\tmemcpy(buf + brk - 1, SUFFIX, sf);\n+\t\t\t\t\tmemcpy(buf + brk - 1, suffix, sf);\n \t\t\t\t\tsafe_write(err, buf, brk + sf);\n \t\t\t\t\tmemcpy(buf + brk, save, sf);\n \t\t\t\t} else\n-- \n1.5.4.rc2.815.g2f849-dirty\n"}]}