Class: Rubyagents::UI::Spinner
- Inherits:
-
Object
- Object
- Rubyagents::UI::Spinner
- Defined in:
- lib/rubyagents/ui.rb
Instance Method Summary collapse
-
#initialize(message) ⇒ Spinner
constructor
A new instance of Spinner.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(message) ⇒ Spinner
Returns a new instance of Spinner.
72 73 74 75 76 |
# File 'lib/rubyagents/ui.rb', line 72 def initialize() @message = @running = false @frame = 0 end |
Instance Method Details
#start ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rubyagents/ui.rb', line 78 def start @running = true @thread = Thread.new do while @running char = SPINNER_FRAMES[@frame % SPINNER_FRAMES.size] frame = Styles.spinner_style.render(char) $stderr.print "\r\e[K#{frame} #{@message}" @frame += 1 sleep 0.08 end $stderr.print "\r\e[K" end end |
#stop ⇒ Object
92 93 94 95 |
# File 'lib/rubyagents/ui.rb', line 92 def stop @running = false @thread&.join end |