[PATCH] D67060: [Support] Support restoring colors in WithColor
Seiya Nuta via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 3 18:52:55 PDT 2019
seiya marked an inline comment as done.
seiya added inline comments.
================
Comment at: llvm/include/llvm/Support/WithColor.h:163
static raw_ostream &error(raw_ostream &OS, StringRef Prefix = "",
- bool DisableColors = false);
+ bool DisableColors = false,
+ WithColorContext *Context = nullptr);
----------------
In D67060#1655078, @MaskRay suggested to replace `bool DisableColors` with `WithColorContext *Context`. IIUC, the usage will look like:
```
lang=cpp
WithColorContext Ctx(/*DisableColors=*/ false);
{
WithColor Red(outs(), raw_ostream::RED, false, false, &Ctx);
Red << "AAA\n";
WithColor(outs(), raw_ostream::BLUE, false, false, &Ctx) << "BBB\n";
Red << "CCC\n";
}
```
However, with this approach we need to Bold and BG every time we use WithColorContext. How about adding a new constructor (b):
```
lang=cpp
// (a) Use DisableColors.
WithColor(raw_ostream &OS,
raw_ostream::Colors Color = raw_ostream::SAVEDCOLOR,
bool Bold = false, bool BG = false, bool DisableColors = false,
WithColorContext *Context = nullptr);
// (b) Use Context->DisableColors.
WithColor(raw_ostream &OS, WithColorContext *Context,
raw_ostream::Colors Color = raw_ostream::SAVEDCOLOR,
bool Bold = false, bool BG = false)
```
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67060/new/
https://reviews.llvm.org/D67060
More information about the llvm-commits
mailing list