class Colored2::AsciiDecorator
Attributes
__background_next[RW]
__colors_disabled[RW]
my_class[RW]
string[RW]
Public Class Methods
background_next!()
click to toggle source
# File lib/colored2/ascii_decorator.rb, line 35 def background_next! self.__background_next = true end
background_next?()
click to toggle source
# File lib/colored2/ascii_decorator.rb, line 41 def background_next? self.__background_next end
disable!()
click to toggle source
# File lib/colored2/ascii_decorator.rb, line 32 def disable! self.__colors_disabled = true end
enable!()
click to toggle source
# File lib/colored2/ascii_decorator.rb, line 26 def enable! self.__colors_disabled = false end
enabled?()
click to toggle source
# File lib/colored2/ascii_decorator.rb, line 29 def enabled? !self.__colors_disabled end
foreground_next!()
click to toggle source
# File lib/colored2/ascii_decorator.rb, line 38 def foreground_next! self.__background_next = false end
new(a_string)
click to toggle source
# File lib/colored2/ascii_decorator.rb, line 51 def initialize(a_string) self.string = a_string.instance_of?(Object) ? '' : a_string.to_s self.my_class = self.class end
Public Instance Methods
decorate(options = {})
click to toggle source
options = :color options = :color | :no_color
# File lib/colored2/ascii_decorator.rb, line 58 def decorate(options = {}) return string if !self.class.enabled? || string.length == 0 escape_sequence = [ Colored2::TextColor.new(options[:foreground]), Colored2::BackgroundColor.new(options[:background]), Colored2::Effect.new(options[:effect]) ].compact.join colored = '' colored << escape_sequence if options[:beginning] == :on colored << string if options[:end] colored << no_color if options[:end] == :off && !colored.end_with?(no_color) colored << escape_sequence if options[:end] == :on end colored end
un_decorate()
click to toggle source
# File lib/colored2/ascii_decorator.rb, line 76 def un_decorate string.gsub(%r{\e\[\d+(;\d+)*m}, '') end
Private Instance Methods
no_color()
click to toggle source
# File lib/colored2/ascii_decorator.rb, line 82 def no_color @no_color ||= Colored2::Effect.new(:no_color).to_s end