def update_display(transfer)
@ticks ||= 0
@last_updated_at ||= 0
@last_logs ||= []
@last_progress ||= ["", 0]
@ticks += 1
step_map = {
"dump" => "Capturing",
"upload" => "Storing",
"download" => "Retreiving",
"restore" => "Restoring",
"gunzip" => "Uncompressing",
"load" => "Restoring",
}
if !transfer["log"]
@last_progress = ['pending', nil]
redisplay "Pending... #{spinner(@ticks)}"
else
logs = transfer["log"].split("\n")
new_logs = logs - @last_logs
@last_logs = logs
new_logs.each do |line|
matches = line.scan /^([a-z_]+)_progress:\s+([^ ]+)/
next if matches.empty?
step, amount = matches[0]
if ['done', 'error'].include? amount
redisplay "#{@last_progress[0].capitalize}... #{amount}\n"
end
step = step_map[step] || step
@last_progress = [step, amount]
end
step, amount = @last_progress
unless ['done', 'error'].include? amount
redisplay "#{step.capitalize}... #{amount} #{spinner(@ticks)}"
end
end
end