class Dex::UI::Spinner::SpinGroup::Task

Attributes

exception[R]
stderr[R]
stdout[R]
success[R]
title[R]

Public Class Methods

new(title, &block) click to toggle source
# File lib/dex/ui/spinner.rb, line 31
def initialize(title, &block)
  @title = title
  @thread = Thread.new do
    cap = Dex::UI::StdoutRouter::Capture.new(with_frame_inset: false, &block)
    begin
      cap.run
    ensure
      @stdout = cap.stdout
      @stderr = cap.stderr
    end
  end

  @done      = false
  @exception = nil
  @success   = false
end

Public Instance Methods

check() click to toggle source
# File lib/dex/ui/spinner.rb, line 48
def check
  return true if @done
  return false if @thread.alive?

  @done = true
  begin
    status = @thread.join.status
    @success = (status == false)
  rescue => exc
    @exception = exc
    @success = false
  end

  @done
end
render(index, force = true) click to toggle source
# File lib/dex/ui/spinner.rb, line 64
def render(index, force = true)
  return full_render(index) if force
  partial_render(index)
end

Private Instance Methods

full_render(index) click to toggle source
# File lib/dex/ui/spinner.rb, line 71
def full_render(index)
  inset + glyph(index) + Dex::UI::Color::RESET.code + ' ' + Dex::UI.resolve_text(title)
end
glyph(index) click to toggle source
# File lib/dex/ui/spinner.rb, line 79
def glyph(index)
  if @done
    @success ? Dex::UI::Glyph::CHECK.to_s : Dex::UI::Glyph::X.to_s
  else
    GLYPHS[index]
  end
end
inset() click to toggle source
# File lib/dex/ui/spinner.rb, line 87
def inset
  @inset ||= Dex::UI::Frame.prefix
end
inset_width() click to toggle source
# File lib/dex/ui/spinner.rb, line 91
def inset_width
  @inset_width ||= Dex::UI::ANSI.printing_width(inset)
end
partial_render(index) click to toggle source
# File lib/dex/ui/spinner.rb, line 75
def partial_render(index)
  Dex::UI::ANSI.cursor_forward(inset_width) + glyph(index) + Dex::UI::Color::RESET.code
end