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:, work_queue:, &block) ⇒ Task
constructor
A new instance of Task.
- #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:, work_queue:, &block) ⇒ Task
Returns a new instance of Task.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 120 def initialize(title, final_glyph:, merged_output:, duplicate_output_to:, work_queue:, &block) @title = title @final_glyph = final_glyph @always_full_render = title =~ Formatter::SCAN_WIDGET @future = work_queue.enqueue 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.
100 101 102 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 100 def exception @exception end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
94 95 96 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 94 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
94 95 96 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 94 def stdout @stdout end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
97 98 99 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 97 def success @success end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
94 95 96 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 94 def title @title end |
Instance Method Details
#check ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 146 def check return true if @done return false unless @future.completed? @done = true begin result = @future.value @success = true @success = false if result == TASK_FAILED rescue => exc @exception = exc @success = false end @done end |
#render(index, force = true, width: CLI::UI::Terminal.width) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 182 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
201 202 203 204 205 206 207 |
# File 'lib/cli/ui/spinner/spin_group.rb', line 201 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 |