termcolor icon indicating copy to clipboard operation
termcolor copied to clipboard

Expose is_colorized

Open patlefort opened this issue 4 years ago • 2 comments

Hi, it would be useful if the is_colorized function would be exposed outside the implementation detail namespace. That way I can know if it's safe to colorize into a transitory string (via stringstream for example) before outputing that string to a maybe colorized stream.

Small aside: while technically according to the standard your "_internal" namespace is valid, I would avoid anything that starts with an underscore.

patlefort avatar Jun 08 '20 20:06 patlefort

Hey @patlefort,

Sorry for taking me so long to respond to you. Would you mind to elaborate a little bit on your use case? I don't quite understand why someone would like to check whether a stream is color capable or not?

ikalnytskyi avatar Feb 07 '21 15:02 ikalnytskyi

In the case of buffered output, if you want to buffer an output before sending it to a stream but I would like to know if it's safe to colorize it. Example: create an std::stringstream, output to it, then send the stringstream buffer to std::cout. I'd check if std::cout is colorized so I can set the stringstream colorized state with colorize. One use case is a logger in a multi-thread context. I think it make sense to expose it when you also have colorize and nocolorize.

patlefort avatar Feb 07 '21 15:02 patlefort