emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#20837: closed (Code for --color=auto)


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#20837: closed (Code for --color=auto)
Date: Sun, 19 Jul 2015 00:14:02 +0000

Your message dated Sat, 18 Jul 2015 17:13:38 -0700
with message-id <address@hidden>
and subject line Re: Code for --color=auto
has caused the debbugs.gnu.org bug report #20837,
regarding Code for --color=auto
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
20837: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20837
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: Code for --color=auto Date: Wed, 17 Jun 2015 07:08:23 -0700
Hello -

I have my own C program where I also use SGR to produce color just like grep 
does.  I pulled the grep source (2.21) to see how —color=auto was implemented.  
In grep.c, lines 2440-2441, there is the code:

        if (color_option == 2)
          color_option = isatty (STDOUT_FILENO) && should_colorize ();

The thing about using isatty() is that it doesn’t work for the common case of 
piping the output of grep to less.  What about using fstat(STDOUT_FILENO) 
instead?  From testing (where “C” is an C program that outputs color using 
SGR), I’ve gotten:

        COMMAND  Should? isatty ISCHR ISFIFO ISREG
        ======== ======= ====== ===== ====== =====
        C          T      T      T     F      F
        C > file   F      F      F     F    >>T<<---- The interesting case.
        C | less   T      F      F     T      F

Hence, it would seem that we want to output color except when ISREG on the stat 
struct on stdout is T.  Wouldn’t this make better logic for —color=auto ?

- Paul




--- End Message ---
--- Begin Message --- Subject: Re: Code for --color=auto Date: Sat, 18 Jul 2015 17:13:38 -0700 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 This one's an easy call: the current behavior for --color=auto was designed to work the way it does, for the reasons Eric explained. Closing the bug report, as it's not a bug.


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]