Class: CLI::UI::Spinner::SpinGroup::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/ui/spinner/spin_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, &block) ⇒ Task

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cli/ui/spinner/spin_group.rb', line 41

def initialize(title, &block)
  @title = title
  @thread = Thread.new do
    cap = CLI::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

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



31
32
33
# File 'lib/cli/ui/spinner/spin_group.rb', line 31

def exception
  @exception
end

#stderrObject (readonly)

Returns the value of attribute stderr.



31
32
33
# File 'lib/cli/ui/spinner/spin_group.rb', line 31

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



31
32
33
# File 'lib/cli/ui/spinner/spin_group.rb', line 31

def stdout
  @stdout
end

#successObject (readonly)

Returns the value of attribute success.



31
32
33
# File 'lib/cli/ui/spinner/spin_group.rb', line 31

def success
  @success
end

#titleObject (readonly)

Returns the value of attribute title.



31
32
33
# File 'lib/cli/ui/spinner/spin_group.rb', line 31

def title
  @title
end

Instance Method Details

#checkObject

Checks if a task is finished



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cli/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, width: CLI::UI::Terminal.width) ⇒ Object

Re-renders the task if required

Attributes

  • index - index of the task

  • force - force rerender of the task

  • width - current terminal width to format for



86
87
88
89
90
91
# File 'lib/cli/ui/spinner/spin_group.rb', line 86

def render(index, force = true, width: CLI::UI::Terminal.width)
  return full_render(index, width) if force || @force_full_render
  partial_render(index)
ensure
  @force_full_render = false
end

#update_title(new_title) ⇒ Object

Update the spinner title

Attributes

  • title - title to change the spinner to



99
100
101
102
# File 'lib/cli/ui/spinner/spin_group.rb', line 99

def update_title(new_title)
  @title = new_title
  @force_full_render = true
end