Class: CliLogger::Spinner
- Inherits:
-
Object
- Object
- CliLogger::Spinner
- Defined in:
- lib/cli_logger/spinner.rb
Overview
Spinner class
Instance Method Summary collapse
- #clear_line ⇒ Object
-
#initialize ⇒ Spinner
constructor
A new instance of Spinner.
- #spin ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Spinner
Returns a new instance of Spinner.
5 6 7 8 |
# File 'lib/cli_logger/spinner.rb', line 5 def initialize @chars = %w( + - - - ) @step = 0.095 end |
Instance Method Details
#clear_line ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/cli_logger/spinner.rb', line 37 def clear_line width = @chars.count print "\r" print ' ' * width print "\r" end |
#spin ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cli_logger/spinner.rb', line 26 def spin $stdout.sync = true Thread.current[:done] = false until Thread.current[:done] clear_line print @chars.join.green @chars.unshift @chars.pop sleep @step end end |
#start ⇒ Object
10 11 12 13 14 15 |
# File 'lib/cli_logger/spinner.rb', line 10 def start stop sleep @step @thread = Thread.new { spin } end |
#stop ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/cli_logger/spinner.rb', line 17 def stop return unless @thread return if @thread[:done] @thread[:done] = true sleep @step / (@chars.count - 1) clear_line end |