Class: ZTK::Spinner
- Inherits:
-
Object
- Object
- ZTK::Spinner
- Defined in:
- lib/ztk/spinner.rb
Overview
Spinner Class
This class can be used to display an "activity indicator" to a user while a task is executed in the supplied block. This indicator takes the form of a spinner.
Constant Summary
- CHARSET =
Spinner Character Set
%w( | / - \\ )
Class Method Summary (collapse)
-
+ (Object) spin(options = {}) { ... }
UI Spinner.
Class Method Details
+ (Object) spin(options = {}) { ... }
UI Spinner
Displays a "spinner" while executing the supplied block. It is advisable that no output is sent to the console during this time.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ztk/spinner.rb', line 40 def spin(={}, &block) = Base.build_config({ :step => 0.1 }, ) !block_given? and Base.log_and_raise(.ui.logger, SpinnerError, "You must supply a block!") count = 0 spinner = Thread.new do while (count >= 0) do .ui.stdout.print(CHARSET[(count += 1) % CHARSET.length]) .ui.stdout.print("\b") .ui.stdout.respond_to?(:flush) and .ui.stdout.flush sleep(.step) end end yield.tap do count = -100 spinner.join end end |