Sha256: 25bbbf994e9f6a90e511815cbde9639f7d9c77ff3883f8dd87bfc1c74d2784bd
Contents?: true
Size: 1.27 KB
Versions: 6
Compression:
Stored size: 1.27 KB
Contents
module Test class Color NAMES = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"] def initialize(name, options={}) @name = name @foreground = options[:foreground] @foreground = true if @foreground.nil? @intensity = options[:intensity] @bold = options[:bold] @italic = options[:italic] @underline = options[:underline] end def sequence sequence = [] if @name == "none" elsif @name == "reset" sequence << "0" else foreground_parameter = @foreground ? 3 : 4 foreground_parameter += 6 if @intensity sequence << "#{foreground_parameter}#{NAMES.index(@name)}" end sequence << "1" if @bold sequence << "3" if @italic sequence << "4" if @underline sequence end def escape_sequence "\e[#{sequence.join(';')}m" end def +(other) MixColor.new([self, other]) end end class MixColor def initialize(colors) @colors = colors end def sequence @colors.inject([]) do |result, color| result + color.sequence end end def escape_sequence "\e[#{sequence.join(';')}m" end def +(other) self.class.new([self, other]) end end end
Version data entries
6 entries across 6 versions & 2 rubygems