Sha256: 940a0799b30ca073125533fd52bbcfb9e3643e353faae8f43b84039db81c5054

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

require_relative './color.rb'

class Console

  def self.announce_task_start task
	line = Color.bold + Color.cyan + "[:" + task + "]" + Color.clear
	#while(line.length < 80) do
	#  line = line + "="
	#end
	#puts " "
	puts line + Color.clear
  end

  def self.announce_task_end task, elapsed_str
    line =  task + " completed in " + Color.green + elapsed_str + Color.clear
	puts line + Color.clear
	puts " "
  end

  def self.print_hash(indent,hash)
    max_length=0
    hash.each { |name,value| max_length=name.to_s.length if name.to_s.length > max_length }
	max_length=max_length+1
    index=0
    hash.each do |name,value|
	  prefix = Color.bold + "#{indent}#{name.to_s}".rjust(max_length) + Color.clear
      if value.kind_of?(Hash)
        print_hash(prefix+" ",value)
      elsif value.kind_of?(Array)
	    Console.print_array prefix,name,value
      else
	    puts Color.white + prefix + " " + Color.green + value.to_s + Color.clear
      end
      index+=1
      indent=" ".rjust(indent.length)
    end
  end

  def self.print_array(prefix,key,array)
    array.each do |v|
      if v.kind_of?(Hash)
	    puts Color.bright_yellow + prefix + Color.clear
        print_hash( prefix + " ".rjust(max_length),v)
      else
        puts Color.white + prefix + " " + Color.green + v.to_s + Color.clear if v.kind_of?(String)
		#prefix = indent + " ".rjust(max_length-1)
		#prefix = " ".rjust(indent.length+max_length-1)
		words = prefix.split(' ')
		prefix = " ".rjust(prefix.length)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dev_tasks-0.0.43 lib/console.rb
dev_tasks-0.0.42 lib/console.rb
dev_tasks-0.0.40 lib/console.rb
dev_tasks-0.0.39 lib/console.rb
dev_tasks-0.0.38 lib/console.rb
dev_tasks-0.0.37 lib/console.rb
dev_tasks-0.0.36 lib/console.rb