Class: CLI::UI::Spinner::SpinGroup::Task
- Inherits:
-
Object
- Object
- CLI::UI::Spinner::SpinGroup::Task
- Extended by:
- T::Sig
- 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
-
#initialize(title, final_glyph:, merged_output:, duplicate_output_to:, &block) ⇒ Task
constructor
A new instance of Task.
- #interrupt ⇒ Object
- #render(index, force = true, width: CLI::UI::Terminal.width) ⇒ Object
- #update_title(new_title) ⇒ Object
Methods included from T::Sig
Constructor Details
#initialize(title, final_glyph:, merged_output:, duplicate_output_to:, &block) ⇒ Task
Returns a new instance of Task.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 103 def initialize(title, final_glyph:, merged_output:, duplicate_output_to:, &block) @title = title @final_glyph = final_glyph @always_full_render = title =~ Formatter::SCAN_WIDGET @thread = Thread.new do cap = CLI::UI::StdoutRouter::Capture.new( merged_output: merged_output, duplicate_output_to: duplicate_output_to, ) { block.call(self) } begin cap.run ensure @stdout = cap.stdout @stderr = cap.stderr end end @m = Mutex.new @force_full_render = false @done = false @exception = nil @success = false end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
84 85 86 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 84 def exception @exception end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
78 79 80 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 78 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
78 79 80 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 78 def stdout @stdout end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
81 82 83 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 81 def success @success end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
78 79 80 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 78 def title @title end |
Instance Method Details
#check ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 129 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 |
#interrupt ⇒ Object
193 194 195 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 193 def interrupt @thread.raise(Interrupt) end |
#render(index, force = true, width: CLI::UI::Terminal.width) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 165 def render(index, force = true, width: CLI::UI::Terminal.width) @m.synchronize do if !CLI::UI.enable_cursor? || force || @always_full_render || @force_full_render full_render(index, width) else partial_render(index) end ensure @force_full_render = false end end |
#update_title(new_title) ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 184 def update_title(new_title) @m.synchronize do @always_full_render = new_title =~ Formatter::SCAN_WIDGET @title = new_title @force_full_render = true end end |