class Dev::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

Initializes a new Task This is managed entirely internally by SpinGroup

Attributes

  • title - Title of the task

  • block - Block for the task, will be provided with an instance of the spinner

# File lib/dev/ui/spinner/spin_group.rb, line 41
def initialize(title, &block)
  @title = title
  @thread = Thread.new do
    cap = Dev::UI::StdoutRouter::Capture.new(self, with_frame_inset: false, &block)
    begin
      cap.run
    ensure
      @stdout = cap.stdout
      @stderr = cap.stderr
    end
  end

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

Public Instance Methods

check() click to toggle source

Checks if a task is finished

# File lib/dev/ui/spinner/spin_group.rb, line 61
def check
  return true if @done
  return false if @thread.alive?

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

  @done
end
render(index, force = true) click to toggle source

Re-renders the task if required

Attributes

  • index - index of the task

  • force - force rerender of the task

# File lib/dev/ui/spinner/spin_group.rb, line 85
def render(index, force = true)
  return full_render(index) if force || @force_full_render
  partial_render(index)
ensure
  @force_full_render = false
end
update_title(new_title) click to toggle source

Update the spinner title

Attributes

  • title - title to change the spinner to

# File lib/dev/ui/spinner/spin_group.rb, line 98
def update_title(new_title)
  @title = new_title
  @force_full_render = true
end

Private Instance Methods

full_render(index) click to toggle source
# File lib/dev/ui/spinner/spin_group.rb, line 105
def full_render(index)
  inset + glyph(index) + Dev::UI::Color::RESET.code + ' ' + Dev::UI.resolve_text(title) + "\e[K"
end
glyph(index) click to toggle source
# File lib/dev/ui/spinner/spin_group.rb, line 113
def glyph(index)
  if @done
    @success ? Dev::UI::Glyph::CHECK.to_s : Dev::UI::Glyph::X.to_s
  else
    GLYPHS[index]
  end
end
inset() click to toggle source
# File lib/dev/ui/spinner/spin_group.rb, line 121
def inset
  @inset ||= Dev::UI::Frame.prefix
end
inset_width() click to toggle source
# File lib/dev/ui/spinner/spin_group.rb, line 125
def inset_width
  @inset_width ||= Dev::UI::ANSI.printing_width(inset)
end
partial_render(index) click to toggle source
# File lib/dev/ui/spinner/spin_group.rb, line 109
def partial_render(index)
  Dev::UI::ANSI.cursor_forward(inset_width) + glyph(index) + Dev::UI::Color::RESET.code
end