module Chandler::Refinements::Color

Monkey patch String to provide basic ANSI color support.

“hello”.color? # => false “hello”.blue # => “e[0;34;49mhelloe[0m” “hello”.blue.color? # => true “hello”.blue.strip_color # “hello”

Constants

ANSI_CODES

Public Instance Methods

color?() click to toggle source

Returns `true` if this String contains ANSI color sequences.

# File lib/chandler/refinements/color.rb, line 21
def color?
  self != strip_color
end
strip_color() click to toggle source

Returns a new String with ANSI color sequences removed.

# File lib/chandler/refinements/color.rb, line 26
def strip_color
  gsub(/\e\[[0-9;]*m/, "")
end