Class: CLI::UI::Spinner::SpinGroup::Task
- Inherits:
-
Object
- Object
- CLI::UI::Spinner::SpinGroup::Task
- Defined in:
- lib/cli/ui/spinner/spin_group.rb
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#check ⇒ Object
Checks if a task is finished.
-
#initialize(title, &block) ⇒ Task
constructor
Initializes a new Task This is managed entirely internally by
SpinGroup
. -
#render(index, force = true, width: CLI::UI::Terminal.width) ⇒ Object
Re-renders the task if required.
-
#update_title(new_title) ⇒ Object
Update the spinner title.
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
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
31 32 33 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 31 def exception @exception end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
31 32 33 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 31 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
31 32 33 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 31 def stdout @stdout end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
31 32 33 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 31 def success @success end |
#title ⇒ Object (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
#check ⇒ Object
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 |