onevcat / Rainbow

Delightful console output for Swift developers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clear string colors

kiliankoe opened this issue · comments

Hi, I ❤️ using Rainbow in my projects.

I am however stumbling across an issue where I need to use the length of a string as in .characters.count or just .count in Swift 4. Obviously this changes when introducing escape sequences, so I was looking for a way to remove these. Rainbow offers the handy .removingColor() method on strings, but unfortunately this seems to just replace the escape sequences with default values. Is there a way to access only the actual string content itself? That would be fantastic!

It is not directly supported now. However, it should be quite easy if you use the extractModes(for:) method and check its returning text (see this)

I will mark it as public for now and release an update so you could use it. However, a better approach could be expose something like "rawCount" to the string. I have a plan to improve the interface to avoid naming conflict, as well as Swift 4 module support. And I think it would better chance to also add that property in a later major release.

Thanks for the info and quick help! Works great as a quick fix 😊 Definitely looking forward to upcoming improvements!