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.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 10 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
32 33 34 35 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 32 def activate @mutex.synchronize { @active = true } spin end |
#active? ⇒ Boolean
28 29 30 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 28 def active? @mutex.synchronize { @active } end |
#deactivate ⇒ Object
37 38 39 40 41 42 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 37 def deactivate return unless active? @mutex.synchronize do @active = false end end |
#start_spinner ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 44 def start_spinner @thread = Thread.new do loop do spin sleep @interval end end end |
#update(line) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/foreman_maintain/reporter/cli_reporter.rb', line 21 def update(line) @mutex.synchronize do @current_line = line print_current_line end end |