termenv icon indicating copy to clipboard operation
termenv copied to clipboard

Bold ansi codes not removed in unsupported terminals

Open fiws opened this issue 3 years ago • 6 comments

https://play.golang.org/p/vV2-0Q2g-9t

↑ Output of this playground link:

[1mTest[0m
[1;mTest with color and bold[0m
Test with only color

But they should be removed, right?

fiws avatar Apr 23 '21 18:04 fiws

So basically, if input is not a TTY you're saying that bold (and other ANSI) should not be rendered, correct?

meowgorithm avatar Jun 11 '21 15:06 meowgorithm

I don't know what the criterium should be. It should probably just be the same logic as with the colors. The colors are removed in the example i posted, but the bold ANSI codes are not.

fiws avatar Jun 11 '21 15:06 fiws

I actually agree and it was an oversight in the original design. The ColorProfile should really just be a Profile and apply to the other markups as well. That however is a bit of an API change.

muesli avatar Jun 11 '21 16:06 muesli

Well, in the meantime one could argue that the absence of color is technically a ColorProfile. I personally wouldn’t mind the API change, however.

meowgorithm avatar Jun 11 '21 18:06 meowgorithm

I ran into the same issue. I also have many use cases where I would want colors and style applied without a TTY, logging for example. If it is not possible to detect whether bold printing is supported, a profile that removes all styles should be offered. Users can then add a CLI flag to their application to disable style support. If it is set, they can use the aforementioned profile, if not, they can query the terminal with termenv.ColorProfile() as usual.

erikgeiser avatar Jul 31 '21 12:07 erikgeiser

I'll try to support this without breaking the existing API. This means that everyone who wants styles to be automatically stripped away will have to use a newer termenv API.

muesli avatar Jan 31 '22 19:01 muesli

This has been merged in master now. Please start using termenv.Output which should strip the styles correctly. The old API has been deprecated but remains backwards compatible with the previous behavior for the time being.

muesli avatar Sep 20 '22 15:09 muesli