summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2016-08-08 18:50:15 -0700
committerJim Meyering <meyering@fb.com>2016-08-08 18:53:32 -0700
commit697c1f4fa93ac971c487725e9e53fc211cd3c670 (patch)
tree7f52c2f612ee28425a9442e629b3f7abf855a3be
parent09369932527342a4fb0ccc6677184c3d3ce7fc49 (diff)
downloaddiffutils-697c1f4fa93ac971c487725e9e53fc211cd3c670.tar.gz
diff: disable colorization for TERM=dumb
* src/diff.c (main): With --color or --color=auto, when TERM is "dumb", disable colorization. Suggested by Daniel Colascione. * NEWS (Bug fixes): Mention it. * tests/colors: Add a test that would fail without this change, yet passes with it.
-rw-r--r--NEWS4
-rw-r--r--src/diff.c7
-rwxr-xr-xtests/colors5
3 files changed, 16 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index add082b..9a8d2e1 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU diffutils NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ diff --color no longer colorizes when TERM=dumb
+
* Noteworthy changes in release 3.4 (2016-08-08) [stable]
diff --git a/src/diff.c b/src/diff.c
index 9bc1d96..686945e 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -656,6 +656,13 @@ main (int argc, char **argv)
prev = c;
}
+ if (colors_style == AUTO)
+ {
+ char const *t = getenv ("TERM");
+ if (t && STREQ (t, "dumb"))
+ colors_style = NEVER;
+ }
+
if (output_style == OUTPUT_UNSPECIFIED)
{
if (show_c_function)
diff --git a/tests/colors b/tests/colors
index 3ad2206..8651a5b 100755
--- a/tests/colors
+++ b/tests/colors
@@ -86,6 +86,11 @@ test $? = 1 || fail=1
gen_exp_default > exp || framework_failure_
compare exp out || fail=1
+TERM=dumb diff ---presume-output-tty --color=auto a b > out
+test $? = 1 || fail=1
+gen_exp_default > exp || framework_failure_
+compare exp out || fail=1
+
diff --color=never a b > out
test $? = 1 || fail=1
gen_exp_default > exp || framework_failure_