ku1ik / rainbow

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

Add uncolor method #54

Closed ypresto closed 7 years ago

ypresto commented 7 years ago

Similar method exists in Perl's Term:ANSIColor as uncolor(). It is useful when:

ypresto commented 7 years ago

rebased!

ku1ik commented 7 years ago

Good observation @olleolleolle.

SGR stands for Set Graphics Rendition, and in addition to dealing with colors it also allows setting/unsetting other text attributes like bold, blinking, italic, underline and few others. This new method strips all ANSI escape sequences, not only SGR, so the name is appropriate in my opinion.

I hesitated to merge this because so far Rainbow only dealt with SGR seqs (escape seqs ending in m) and strip_ansi_escape clears the text of all ansi escape seqs (potentially cursor movement, erasing, scrolling, saving/restoring cursor position etc). But I think in most cases it would be used on colored text, so it's probably ok to have it in Rainbow.

ku1ik commented 7 years ago

We can either merge it as it is now, or modify regex to only strip ones ending in m, and renaming the method to uncolor or strip_colors.

ypresto commented 7 years ago

Changed to uncolor method..!

ku1ik commented 7 years ago

Sorry, I've been busy recently. This looks good, let's merge it 👍