Module: CLI::UI::Spinner
- Defined in:
- lib/cli/ui/spinner.rb,
lib/cli/ui/spinner/async.rb,
lib/cli/ui/spinner/spin_group.rb
Defined Under Namespace
Constant Summary collapse
- PERIOD =
seconds
0.1- TASK_FAILED =
:task_failed- RUNES =
if CLI::UI::OS.current.use_emoji? ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'].freeze else ['\\', '|', '/', '-', '\\', '|', '/', '-'].freeze end
- GLYPHS =
colors.zip(RUNES).map { |c, r| c + r + CLI::UI::Color::RESET.code }.freeze
Class Attribute Summary collapse
-
.index ⇒ Object
: Integer?.
Class Method Summary collapse
-
.current_rune ⇒ Object
We use this from CLI::UI::Widgets::Status to render an additional spinner next to the “working” element.
-
.spin(title, auto_debrief: true, to: $stdout, &block) ⇒ Object
Adds a single spinner Uses an interactive session to allow the user to pick an answer Can use arrows, y/n, numbers (1/2), and vim bindings to control.
Class Attribute Details
.index ⇒ Object
: Integer?
25 26 27 |
# File 'lib/cli/ui/spinner.rb', line 25 def index @index end |
Class Method Details
.current_rune ⇒ Object
We use this from CLI::UI::Widgets::Status to render an additional spinner next to the “working” element. While this global state looks a bit repulsive at first, it’s worth realizing that:
-
It’s managed by the SpinGroup#wait method, not individual tasks; and
-
It would be complete insanity to run two separate but concurrent SpinGroups.
While it would be possible to stitch through some connection between the SpinGroup and the Widgets included in its title, this is simpler in practice and seems unlikely to cause issues in practice. : -> String
38 39 40 |
# File 'lib/cli/ui/spinner.rb', line 38 def current_rune RUNES[index || 0] end |
.spin(title, auto_debrief: true, to: $stdout, &block) ⇒ Object
Adds a single spinner Uses an interactive session to allow the user to pick an answer Can use arrows, y/n, numbers (1/2), and vim bindings to control

Attributes
-
title- Title of the spinner to use
Options
-
:auto_debrief- Automatically debrief exceptions or through success_debrief? Default to true -
:to- Target stream, like $stdout or $stderr. Can be anything with print and puts methods, or under Sorbet, IO or StringIO. Defaults to $stdout.
Block
-
*spinner+ - Instance of the spinner. Can call
update_titleto update the user of changes
Example Usage:
CLI::UI::Spinner.spin('Title') { sleep 1.0 }
: (String title, ?auto_debrief: bool, ?to: io_like) { (SpinGroup::Task task) -> void } -> bool
69 70 71 72 73 |
# File 'lib/cli/ui/spinner.rb', line 69 def spin(title, auto_debrief: true, to: $stdout, &block) sg = SpinGroup.new(auto_debrief: auto_debrief) sg.add(title, &block) sg.wait(to: to) end |