aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-cov/llvm-cov.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2019-08-02 04:48:30 +0000
committerRui Ueyama <ruiu@google.com>2019-08-02 04:48:30 +0000
commita52f982f1cd98ebf94abb5deb5244f460ddad2d1 (patch)
tree61799d68dd515bda1a6bd6d7b70812e96dbe9ded /llvm/tools/llvm-cov/llvm-cov.cpp
parent9131e925fd6b5010a9e797342a09141306183ed6 (diff)
downloadllvm-a52f982f1cd98ebf94abb5deb5244f460ddad2d1.zip
llvm-a52f982f1cd98ebf94abb5deb5244f460ddad2d1.tar.gz
llvm-a52f982f1cd98ebf94abb5deb5244f460ddad2d1.tar.bz2
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 llvm-svn: 367649
Diffstat (limited to 'llvm/tools/llvm-cov/llvm-cov.cpp')
-rw-r--r--llvm/tools/llvm-cov/llvm-cov.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/llvm/tools/llvm-cov/llvm-cov.cpp b/llvm/tools/llvm-cov/llvm-cov.cpp
index 172ec9f..dabb8afe 100644
--- a/llvm/tools/llvm-cov/llvm-cov.cpp
+++ b/llvm/tools/llvm-cov/llvm-cov.cpp
@@ -83,13 +83,10 @@ int main(int argc, const char **argv) {
}
}
- if (argc > 1) {
- if (sys::Process::StandardErrHasColors())
- errs().changeColor(raw_ostream::RED);
- errs() << "Unrecognized command: " << argv[1] << ".\n\n";
- if (sys::Process::StandardErrHasColors())
- errs().resetColor();
- }
+ if (argc > 1)
+ errs() << raw_ostream::RED << "Unrecognized command: " << argv[1] << ".\n\n"
+ << raw_ostream::RESET;
+
helpMain(argc, argv);
return 1;
}