muesli / termenv

Advanced ANSI style & color support for your terminal applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bold ansi codes not removed in unsupported terminals

fiws opened this issue · 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?

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

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.

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.

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.

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.

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.

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.