On Thu, May 31 2018, Jeff King wrote: > On Wed, May 30, 2018 at 09:06:41PM +0000, Ævar Arnfjörð Bjarmason wrote: > >> A co-worker of mine who was using UNIX systems when dinosaurs roamed >> the earth was lamenting that kids these days were using tools like >> "git" that thought they knew better than isatty(3) when deciding >> whether or not something was a terminal, and the state of the >> documentation fixed earlier in this series certainly didn't help. >> >> So this setting is a small gift to all the UNIX graybeards out >> there. Now they can set color.ui=isatty and only emit fancy colors in >> situations when the gods of old intended, not whatever heuristic we've >> decided to set "auto" to. > > I'm having trouble thinking of a case where anybody would actually > care about the distinction between these two. > > If you're not using "-p", then colors will kick in if isatty() is true. > The whole "also check the pager" thing is only because we may check the > color isatty() after starting the pager. If we didn't, then nobody would > ever see color. If your pager doesn't understand color, then fine. Tell > Git not to send it color with color.pager=false. > > If you are using "-p", we might send color to your pager even though you > weren't originally going to a terminal. But either your pager can handle > colors, in which case this is fine, or it cannot, in which case you > would already have needed to set color.pager as above to un-break all of > the non-p cases. > > Is there some case where a pager can only handle color if _it's_ output > is going to a tty, and otherwise not? Maybe I'm missing something but how is that something we can deal with? We just: 1. use isatty() to see if we're attached to a terminal 2a. If yes and no pager is invoked (e.g. git status) and "auto" we use colors 2b. If yes and we're invoking a pager (e.g. git log) and "auto" we use colors 3b. At this point we're writing to the pager so isatty() is false, but we set our own GIT_PAGER_IN_USE and turn on colors if "auto" I suppose we can imagine a pager that sometimes emits to a terminal and sometimes e.g. opens a browser with the output, and we could ourselves somehow detect this... > And you'd want color predicated on > whether the original output was a tty or not, even if you said "-p"? > That's the only case I can think of where the existing config is not > sufficient, but I'm having a hard time envisioning a practical use. > >> As noted here this is *currently* the same as setting color.ui=auto & >> color.pager=false, but I think it's good to explicitly have this >> setting for any future changes. The reason, as now noted in the >> documentation is that the "auto" setting may become even smarter in >> the future and learn even deeper heuristics for when to turn itself on >> even if isatty(3) were returning true. > > Are we actually thinking about teaching it deeper heuristics? I think > the fact that it _is_ based on isatty() is meant to be understood by the > user, and we wouldn't want to change that. True, there is the pager > exception, but the point of that is to maintain the "are we going to a > tty" model, even in the face of sticking a pager in the middle. As noted in the cover letter I started writing this whole thing before understanding some of the subtleties, and now I think this "isatty" thing is probably pretty useless, and was wondering if others wanted it. Reasons to take it are: 1) To make user intent clearer. I.e. we could just also make it a synonym for color.ui=auto & color.pager=false and those used to isatty semantics skimming the docs would more easily find the right thing. 2) If there are any cases where isatty() is true, but we can detect via other means (e.g. inspecting other env variables) that non-pager output can't handle colors some of the time. Of course if we find such cases isatty() would suck more, but that's presumably what isatty() purists want :)