Class: Console
- Inherits:
-
Object
- Object
- Console
- Defined in:
- lib/console.rb
Class Method Summary collapse
- .announce_task_end(task, elapsed_str) ⇒ Object
- .announce_task_start(task) ⇒ Object
- .debug(message) ⇒ Object
- .end_command(command) ⇒ Object
- .print(message) ⇒ Object
- .print_array(prefix, key, array) ⇒ Object
- .print_hash(indent, hash) ⇒ Object
- .start_command(command) ⇒ Object
Class Method Details
.announce_task_end(task, elapsed_str) ⇒ Object
26 27 28 29 30 |
# File 'lib/console.rb', line 26 def self.announce_task_end task, elapsed_str line = task + " completed in " + Color.green + elapsed_str + Color.clear puts line + Color.clear puts " " end |
.announce_task_start(task) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/console.rb', line 17 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 |
.debug(message) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/console.rb', line 5 def self.debug if(defined?(DEV_TASKS)) if(DEV_TASKS.has_key?(:debug)) puts end end end |
.end_command(command) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/console.rb', line 36 def self.end_command command if command[:exit_code] != 0 print " " + Color.green + command[:input] + Color.clear puts command[:output] raise Color.yellow + "`" + Color.green + command[:input] + Color.yellow + "`" + Color.clear + " has exit code " + command[:exit_code].to_s + " " + command[:output] else puts command[:input] + " " + command[:elapsed] end end |
.print(message) ⇒ Object
13 14 15 |
# File 'lib/console.rb', line 13 def self.print puts end |
.print_array(prefix, key, array) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/console.rb', line 67 def self.print_array(prefix,key,array) array.each do |v| if v.kind_of?(Hash) puts Color.bold + prefix + Color.clear print_hash( prefix + " ".rjust(max_length),v) else puts Color.bold + prefix + " " + Color.clear + 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 |
.print_hash(indent, hash) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/console.rb', line 48 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 = "#{indent}#{name.to_s}".rjust(max_length) if value.kind_of?(Hash) print_hash(prefix+" ",value) elsif value.kind_of?(Array) Console.print_array prefix,name,value else puts Color.bold + prefix + " " + Color.clear + Color.green + value.to_s + Color.clear end index+=1 indent=" ".rjust(indent.length) end end |
.start_command(command) ⇒ Object
32 33 34 |
# File 'lib/console.rb', line 32 def self.start_command command end |