class Dex::UI::Spinner::SpinGroup
Public Class Methods
new()
click to toggle source
# File lib/dex/ui/spinner.rb, line 22 def initialize @m = Mutex.new @consumed_lines = 0 @tasks = [] end
Public Instance Methods
add(title, &block)
click to toggle source
# File lib/dex/ui/spinner.rb, line 96 def add(title, &block) @m.synchronize do @tasks << Task.new(title, &block) end end
debrief()
click to toggle source
# File lib/dex/ui/spinner.rb, line 138 def debrief @m.synchronize do @tasks.each do |task| next if task.success e = task.exception out = task.stdout err = task.stderr Dex::UI::Frame.open('Task Failed: ' + task.title, color: :red) do if e puts"#{e.class}: #{e.message}" puts "\tfrom #{e.backtrace.join("\n\tfrom ")}" end Dex::UI::Frame.divider('STDOUT') out = "(empty)" if out.strip.empty? puts out Dex::UI::Frame.divider('STDERR') err = "(empty)" if err.strip.empty? puts err end end @tasks.all?(&:success) end end
wait()
click to toggle source
# File lib/dex/ui/spinner.rb, line 102 def wait idx = 0 loop do all_done = true @m.synchronize do Dex::UI.raw do @tasks.each.with_index do |task, int_index| nat_index = int_index + 1 task_done = task.check all_done = false unless task_done if nat_index > @consumed_lines print(task.render(idx, true) + "\n") @consumed_lines += 1 else offset = @consumed_lines - int_index move_to = Dex::UI::ANSI.cursor_up(offset) + "\r" move_from = "\r" + Dex::UI::ANSI.cursor_down(offset) print(move_to + task.render(idx, idx.zero?) + move_from) end end end end break if all_done idx = (idx + 1) % GLYPHS.size sleep(PERIOD) end debrief end