ku1ik / rainbow

Ruby gem for colorizing printed text on ANSI terminals
MIT License
813 stars 68 forks source link

Enhancement: Rainbow.clear? #56

Closed ddoherty03 closed 7 years ago

ddoherty03 commented 7 years ago

I am using rainbow to build up tables with possibly colored components, and I need to compute the width of a string that may or may not be rainbowized. I would like to have a method on Rainbow that would return just the wrapped string without any escape codes if the string is already wrapped or just the string otherwise.

Then I could calculate the width of an element that may or may not be wrapped with something like

xx = Rainbow("hello").color(:auqamarine).blink
yy = 'hello'
Rainbow.clear(xx) # => 'hello'
Rainbow.clear(yy) # => 'hello'
Rainbow.clear(xx).length # => 6
Rainbow.clear(yy).length # => 6

In the meantime, any easy way to do this with current gem? Also, thanks for a great gem.

ku1ik commented 7 years ago

There's no method in the current version of rainbow for this. But we have PR for exactly this: #54 :)

ddoherty03 commented 7 years ago

Thanks, @sickill. I would vote for a less ponderous name, though, than 'strip_ascii_escape', something like 'clear' or 'wipe', etc.

olleolleolle commented 7 years ago

@ddoherty03 @sickill The #54 is now merged.

Is this issue "fixed" with that?

ku1ik commented 7 years ago

It's called uncolor now and I'd say that fixes this issue indeed :)

ddoherty03 commented 7 years ago

@sickill, yes indeed. Thanks for getting to this.

olleolleolle commented 7 years ago

Thanks, all; closing this issue.