[PATCH] D65564: Improve raw_ostream so that you can "write" colors using operator<<

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 02:21:18 PDT 2019


ruiu created this revision.
ruiu added reviewers: MaskRay, grimar.
Herald added subscribers: cfe-commits, thopre, gbedwell, aheejin, hiraditya, arichardson, sbc100, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: andreadb.
Herald added projects: clang, LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65564

Files:
  clang/include/clang/AST/ASTDumperUtils.h
  clang/lib/Analysis/CFG.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/tools/diagtool/TreeView.cpp
  lld/COFF/Driver.cpp
  lld/COFF/DriverUtils.cpp
  lld/Common/ErrorHandler.cpp
  lld/ELF/Driver.cpp
  lld/ELF/DriverUtils.cpp
  lld/include/lld/Common/ErrorHandler.h
  lld/lib/Driver/DarwinLdDriver.cpp
  lld/test/COFF/color-diagnostics.test
  lld/test/ELF/color-diagnostics.test
  lld/wasm/Driver.cpp
  llvm/include/llvm/Support/FormattedStream.h
  llvm/include/llvm/Support/WithColor.h
  llvm/include/llvm/Support/raw_ostream.h
  llvm/lib/Support/WithColor.cpp
  llvm/lib/Support/raw_ostream.cpp
  llvm/tools/llvm-cov/CoverageReport.cpp
  llvm/tools/llvm-cov/CoverageViewOptions.h
  llvm/tools/llvm-cov/RenderingSupport.h
  llvm/tools/llvm-cov/SourceCoverageViewText.cpp
  llvm/tools/llvm-cov/llvm-cov.cpp
  llvm/tools/llvm-mca/Views/TimelineView.cpp
  llvm/utils/FileCheck/FileCheck.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65564.212758.patch
Type: text/x-patch
Size: 28907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190801/b47ed0e4/attachment.bin>


More information about the llvm-commits mailing list