Sha256: 8e099b7ea21c87133c473abd36605787846155ea9b2ad6f2d74bced8ffa22af0
Contents?: true
Size: 1.39 KB
Versions: 15
Compression:
Stored size: 1.39 KB
Contents
module Test module Unit 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 end
Version data entries
15 entries across 15 versions & 4 rubygems