Class: Daedalus::FancyLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/daedalus.rb

Constant Summary collapse

HEADER =
"Daedalus building:"

Instance Method Summary collapse

Methods inherited from Logger

#inc!, #info, #thread_id, #verbose

Constructor Details

#initialize(level = 0) ⇒ FancyLogger

Returns a new instance of FancyLogger.



88
89
90
# File 'lib/daedalus.rb', line 88

def initialize(level=0)
  super 0
end

Instance Method Details

#command(cmd) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/daedalus.rb', line 114

def command(cmd)
  output = IO.popen "sh -c '#{cmd} 2>&1'", "r"

  begin
    str = output.read
  rescue Exception
    Process.kill 'SIGINT', output.pid
    STDOUT.puts "\nInterrupt compiling."
    raise "Stopped compiling"
  end

  Process.wait output.pid

  if $?.exitstatus != 0
    STDOUT.puts "Error compiling: #{cmd}"
    STDOUT.puts "Output:\n#{str}"
    raise "Error compiling"
  end
end

#show(kind, cmd) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/daedalus.rb', line 98

def show(kind, cmd)
  @count += 1
  perc = (100 * (@count.to_f / @total)).to_i
  bar_size = (30 * (@count.to_f / @total)).to_i

  bar = "#{'=' * bar_size}#{' ' * (30 - bar_size)}"

  if cmd.size > 38
    cmd = "..#{cmd[-38,38]}"
  else
    cmd = cmd.ljust(40)
  end

  STDOUT.print "\r[%3d%% #{bar}] #{kind} #{cmd}" % perc.to_i
end

#start(count) ⇒ Object



92
93
94
95
96
# File 'lib/daedalus.rb', line 92

def start(count)
  super
  STDOUT.sync = true
  STDOUT.puts HEADER
end

#stopObject



134
135
136
137
# File 'lib/daedalus.rb', line 134

def stop
  super
  STDOUT.puts
end