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

Seiya Nuta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 23:57:45 PDT 2019


seiya added a comment.

In D67060#1656821 <https://reviews.llvm.org/D67060#1656821>, @ruiu wrote:

> 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


That sounds good idea to me too but how can we obtain the current color from the terminal? I skimmed xterm control sequences but couldn't find out the feature (note: I'm not familiar with Windows).

Also, getting colors from the terminal may degrades the performance since we need to invoke a system call every time we use WithColor. We should discuss about the performance after measuring it, btw.


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

https://reviews.llvm.org/D67060





More information about the llvm-commits mailing list