Sha256: 0c453251b9fa4e81219dabe00c65f20f01445641689556335b22c10125320b95

Contents?: true

Size: 1.27 KB

Versions: 28

Compression:

Stored size: 1.27 KB

Contents

class Colors
  class << self
    
    def default_terminal_colors
      @default_terminal_colors ||= "\e[0m\e[37m\e[40m"
    end
    
    def process(data)
      begin
        _process(data)
      ensure
        STDOUT.flush
        reset!
      end      
    end
    
    def reset!
      STDOUT.write("\e[0m")
      STDOUT.flush
    end
    
    def _process(data)	
      # Backrounds
      if m = data.match(%r{<(.*?) bg=(.*?)>(.*?)<\/(.*?)>}m)
        colors = {:red => 1, :green => 2, :yellow => 3, :blue => 4, :purple => 5, :sea => 6, :white => 7}
        colors.each do |k,v|
          t = data.match(%r{<(.*?) bg=#{k}>(.*?)<\/(.*?)>}m)
          data.gsub!(%r{<(.*?) bg=#{k}>(.*?)<\/(.*?)>}m, "\e[1m\e[4#{v}m<\\1>\\2</\\1>#{default_terminal_colors}")
        end
      end

      # Colored text
    	colors = {:red => 1, :green => 2, :yellow => 3, :blue => 4, :purple => 5, :sea => 6, :white => 7}
    	colors.each do |k,v|
        data.gsub!(%r{<#{k}>(.*?)</#{k}>}m, "\e[1m\e[3#{v}m\\1#{default_terminal_colors}")
    	end

    	data.gsub!(%r{<b>(.*?)</b>}m, "\e[1m\\1#{default_terminal_colors}")
    	data.gsub!(%r{<line>}m, "------------------------------")
    	data.gsub!(%r{<banner>(.*?)</banner>}m, "\e[33m\e[44m\e[1m\\1#{default_terminal_colors}")
    	return data
    end
    
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
auser-poolparty-1.3.0 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.1 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.10 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.11 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.12 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.13 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.14 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.15 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.16 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.17 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.2 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.3 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.4 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.5 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.6 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.7 vendor/gems/colors/lib/colors.rb
auser-poolparty-1.3.8 vendor/gems/colors/lib/colors.rb
fairchild-poolparty-1.3.17 vendor/gems/colors/lib/colors.rb
fairchild-poolparty-1.3.5 vendor/gems/colors/lib/colors.rb
poolparty-1.3.15 vendor/gems/colors/lib/colors.rb