cdiff should detect if there is a terminal

Bug #242115 reported by Olav Vitters
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
BzrTools
Fix Released
Undecided
Unassigned

Bug Description

I'd like to alias diff to cdiff. This so I do not have to remember if I should run cdiff or diff. However, cdiff doesn't automatically disable its colouring when the output goes to a terminal, preventing me from aliasing it.

Basically I want:
  bzr diff
to show me the diff in colour, and:
  bzr diff > file
not to put the colour escape codes in the file

Suggested solution:
$ cat test.py
#!/usr/bin/python

import sys

print sys.stdout.isatty()
print sys.stdin.isatty()

$ ./test.py
True
True

$ ./test.py > l

$ cat l
False
True

Revision history for this message
Aaron Bentley (abentley) wrote : Re: [Bug 242115] [NEW] cdiff should detect if there is a terminal

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Olav Vitters wrote:
> Public bug reported:
>
> I'd like to alias diff to cdiff. This so I do not have to remember if I
> should run cdiff or diff. However, cdiff doesn't automatically disable
> its colouring when the output goes to a terminal, preventing me from
> aliasing it.

However, I pipe cdiff through less on occasion, and less is not a
terminal, so that would cause color to be disabled.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIXoSF0F+nu1YWqI0RAvGmAJ9vCV5D8AMYGaRW8zyt9wxN9Y4dWwCfbbBv
ZN94YSVXl/EwUG8nYqAW6Os=
=waTN
-----END PGP SIGNATURE-----

Revision history for this message
Olav Vitters (ovitters) wrote :

Perhaps an --color option like grep? With 'never' (bit strange), 'always', 'auto'. Ideally I'd even like diff to automatically do cdiff --colour=auto :)

Revision history for this message
Daniel Clemente (n142857) wrote :

I like the way "git diff" works: it sends color codes if the output is a terminal, but has also the options --color and --no-color to force it.

Aaron Bentley (abentley)
Changed in bzrtools:
status: New → Fix Released
Revision history for this message
Daniel Clemente (n142857) wrote :

This doesn't seem fixed. With bzr.dev 4359 and bzrtools 705 (both from right now), „bzr cdiff >file; cat file“ shows the file in colours. Same with „|less“. GNU/Linux Debian and python 2.5.4

Revision history for this message
Daniel Clemente (n142857) wrote :

The problem is that --color=always is the default, instead of --color=auto, which is more a reasonable and extended behaviour.

Revision history for this message
Aaron Bentley (abentley) wrote : Re: [Bug 242115] Re: cdiff should detect if there is a terminal

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Daniel Clemente wrote:
> The problem is that --color=always is the default, instead of
> --color=auto, which is more a reasonable and extended behaviour.

color=auto will disable color when cdiff is piped to less -R, which is
broken. It is entirely appropriate for a program designed to emit
colorized diffs to default to emitting colorized diffs.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkoMMCUACgkQ0F+nu1YWqI0MPgCfS6/yvD8sJrlqO701oHMbKviP
TA8An1S5sDzDO5YjNQ18Humnl87beWit
=TPRf
-----END PGP SIGNATURE-----

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.