Class: ForemanMaintain::Reporter::CLIReporter::Spinner
- Inherits:
-
Object
- Object
- ForemanMaintain::Reporter::CLIReporter::Spinner
- Defined in:
- lib/foreman_maintain/reporter/cli_reporter.rb
Overview
Simple spinner able to keep updating current line
Instance Method Summary collapse
- #activate ⇒ Object
- #active? ⇒ Boolean
- #deactivate ⇒ Object
-
#initialize(reporter, interval = 0.1) ⇒ Spinner
constructor
A new instance of Spinner.
- #start_spinner ⇒ Object
- #update(line) ⇒ Object
Constructor Details
#initialize(reporter, interval = 0.1) ⇒ Spinner
Returns a new instance of Spinner.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 9 def initialize(reporter, interval = 0.1) @reporter = reporter @mutex = Mutex.new @active = false @interval = interval @spinner_index = 0 @spinner_chars = %w[| / - \\] @current_line = '' @puts_needed = false end |
Instance Method Details
#activate ⇒ Object
31 32 33 34 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 31 def activate @mutex.synchronize { @active = true } unless @reporter.plaintext? spin end |
#active? ⇒ Boolean
27 28 29 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 27 def active? @mutex.synchronize { @active } end |
#deactivate ⇒ Object
36 37 38 39 40 41 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 36 def deactivate return unless active? @mutex.synchronize do @active = false end end |
#start_spinner ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 43 def start_spinner @thread = Thread.new do loop do spin sleep @interval end end end |
#update(line) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 20 def update(line) @mutex.synchronize do @current_line = line print_current_line end end |