7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/decking/helpers.rb', line 7
def run_with_progress(title, &block)
command = Thread.new(&block).tap{ |t| t.abort_on_exception = true}
progress = Thread.new do
opts = { title: title,
total: nil,
length: CONSOLE_LENGTH,
format: '%t%B',
progress_mark: ' ',
unknown_progress_animation_steps: ['.. .', '... ', ' ... ', ' ...', '. ..'] }
progressbar = ProgressBar.create opts
begin
loop do
progressbar.increment
sleep 0.5
end
rescue RuntimeError => e
if e.message == 'Shutdown'
progressbar.total = 100
progressbar.format '%t ' + "\u2713".green
progressbar.finish
else
raise RuntimeError e
end
end
end.tap {|t| t.abort_on_exception = true }
command.join
progress.raise 'Shutdown'
progress.join
finished = true
rescue Interrupt
clear_progressline
puts "I know you did't mean to do that... try again if you really do".yellow
rescue Exception => e
clear_progressline
puts e.class
puts e.message
puts e.backtrace.inspect
exit
ensure
begin
unless finished
command.join
progress.raise 'Shutdown'
progress.join
end
rescue Interrupt
puts "Caught second interrupt, exiting...".red
exit
rescue SystemExit
puts "Caught SystemExit. Exiting...".red
exit
end
end
|