]> granicus.if.org Git - clang/commit
Improve raw_ostream so that you can "write" colors using operator<<
authorRui Ueyama <ruiu@google.com>
Fri, 2 Aug 2019 04:48:30 +0000 (04:48 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 2 Aug 2019 04:48:30 +0000 (04:48 +0000)
commit9ead55fa15c1b85098f0948a737db177556433fe
tree24a66eaef264420562f13a207348a0f83c9675a6
parentd0e06d7ab5de059dbfb456d13d21de56811b071b
Improve raw_ostream so that you can "write" colors using operator<<

1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.

So, if you print out "error: " in red, for example, you had to do
something like this:

  OS.changeColor(raw_ostream::RED);
  OS << "error: ";
  OS.resetColor();

With this patch, you can write the same code as follows:

  OS << raw_ostream::RED << "error: " << raw_ostream::RESET;

2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.

Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.

Differential Revision: https://reviews.llvm.org/D65564

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@367649 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/AST/ASTDumperUtils.h
lib/Analysis/CFG.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Frontend/TextDiagnostic.cpp
tools/diagtool/TreeView.cpp