module CLI::UI::Spinner

Constants

GLYPHS
PERIOD
RUNES
TASK_FAILED

Attributes

index[RW]

Public Class Methods

current_rune() click to toggle source

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.

# File lib/cli/ui/spinner.rb, line 32
def current_rune
  RUNES[index || 0]
end
spin(title, auto_debrief: true, &block) click to toggle source

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? Default to true

Block

  • *spinner+ - Instance of the spinner. Can call update_title to update the user of changes

Example Usage:

CLI::UI::Spinner.spin('Title') { sleep 1.0 }
# File lib/cli/ui/spinner.rb, line 59
def self.spin(title, auto_debrief: true, &block)
  sg = SpinGroup.new(auto_debrief: auto_debrief)
  sg.add(title, &block)
  sg.wait
end