[cfe-dev] clang-tidy: controlling color diagnostics

Riyaz Puthiyapurayil via cfe-dev cfe-dev at lists.llvm.org
Sun Aug 27 10:23:03 PDT 2017


Thanks for your quick response. I am able to get colors on a terminal. But I am unable to control it with a command line option.

I lose colors when I redirect the output to a file. With clang, I can force colors even when redirecting to a file using -fcolor-diagnostics option. However, -extra-arg=-fcolor-diagnostics doesn’t work with clang-tidy.

Alternatively, if I want to turn off color onto a terminal, I can use -fno-color-diagnostics with clang. With clang-tidy, that also doesn’t work.

I wonder if the following code in ClangTidy.cpp is the reason:

class ErrorReporter {
   . . .
   DiagOpts->ShowColors = llvm::sys::Process::StandardOutHasColors();
};

clang does it differently—see parseShowColorArgs in CompilerInvocation.cpp:

    if (O.matches(options::OPT_fcolor_diagnostics) ||
      O.matches(options::OPT_fdiagnostics_color)) {
    ShowColors = Colors_On;
  } . . .
  :
  :
  if (ShowColors == Colors_On ||
     (ShowColors == Colors_Auto && llvm::sys::Process::StandardErrHasColors()))
    return true;

-Riyaz

From: don hinton [mailto:hintonda at gmail.com]
Sent: Sunday, August 27, 2017 10:10 AM
To: Riyaz Puthiyapurayil <Riyaz.Puthiyapurayil at synopsys.com>
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] clang-tidy: controlling color diagnostics

Did you build it yourself?

There's a test in llvm/cmake/config-ix.cmake that sets HAVE_TERMINFO, which needs to be set in order to enable colors.  If it's not set or set to 0, then you won't get colors.  Try installing one of the libraries mentioned in the test:  tinfo terminfo curses ncurses ncursesw.

hth...
don

On Sun, Aug 27, 2017 at 9:45 AM, Riyaz Puthiyapurayil via cfe-dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> wrote:
Is there a way to turn on/off color diagnostics in clang-tidy? Passing -f[no]-color-diagnostics via -extra-arg does not seem to have any effect.

-Riyaz


_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Ddev&d=DwMFaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=mMZWMrEZcvPMLSsEQSah9FOTwza1UudSDkAneN47U9lD3qu6gt3kpnIb4MWV77cM&m=tX0BuxmCivYFNsAnVEokmG1tKqzkY0aq9NPsWF4FrDY&s=0VTnLNcleH853NCiLDoE2fdaQ-4vaRRGdpmgOqSQVEE&e=>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170827/2ccb1a0b/attachment.html>


More information about the cfe-dev mailing list