[PATCH] D67060: [Support] Support restoring colors in WithColor

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 22:50:18 PDT 2019


ruiu added a comment.

This looks better, but I don't think we need the concept of context. If a function takes a context object, it is usually expected that you can interlace function calls with different context objects freely. Say, you have context object A and B, then you literally have two contexts, and they don't interfere with each other. However, that's not the case for the terminal color. The current color of text output on console is naturally and fundamentally a global state associated to each terminal, and therefore there is only one context. So, I don't think that allowing multiple contexts captures the real concept correctly.

I believe the following scheme models captures the reality better:

1. Add a new method, getColor, to raw_fd_stream, which returns the current color set by changeColor before
2. Make a change to WithColor so that it remembers the current color (obtained by calling getColor) before changing color
3. In the destructor, WithColor restores the previous color


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67060/new/

https://reviews.llvm.org/D67060





More information about the llvm-commits mailing list