Class: Fronde::CLI::Throbber

Inherits:
Object
  • Object
show all
Defined in:
lib/fronde/cli/throbber.rb

Overview

Decorations for the command line

Constant Summary collapse

THROBBER_FRAMES =

Returns the possible throbber themes.

Returns:

  • (Hash)

    the possible throbber themes

{
  'basic' => '-\|/',
  'basicdots' => 'โ‹ฏโ‹ฑโ‹ฎโ‹ฐ',
  'moon' => '๐ŸŒ‘๐ŸŒ’๐ŸŒ“๐ŸŒ”๐ŸŒ•๐ŸŒ–๐ŸŒ—๐ŸŒ˜',
  'clock' => '๐Ÿ•›๐Ÿ•๐Ÿ•‘๐Ÿ•’๐Ÿ•“๐Ÿ•”๐Ÿ••๐Ÿ•–๐Ÿ•—๐Ÿ•˜๐Ÿ•™๐Ÿ•š',
  'bricks' => 'โฃทโฃฏโฃŸโกฟโขฟโฃปโฃฝโฃพ',
  'points' => 'ยทโ˜โ›โ˜',
  'quadrant' => 'โ–™โ–›โ–œโ–Ÿ',
  'default' => ['โ  โ ‚ โ „ โก€ โ „ โ ‚ โ ', 'โ ‚ โ  โ ‚ โ „ โก€ โ „ โ ‚', 'โ „ โ ‚ โ  โ ‚ โ „ โก€ โ „',
                'โก€ โ „ โ ‚ โ  โ ‚ โ „ โก€', 'โ „ โก€ โ „ โ ‚ โ  โ ‚ โ „', 'โ ‚ โ „ โก€ โ „ โ ‚ โ  โ ‚']
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread, message) ⇒ Throbber

Returns a new instance of Throbber.



22
23
24
25
26
27
28
29
# File 'lib/fronde/cli/throbber.rb', line 22

def initialize(thread, message)
  @frames = select_frames
  @term_width = terminal_width
  @thread = thread
  @thread.abort_on_exception = false
  @thread.report_on_exception = false
  @message = message
end

Class Method Details

.run(thread, message, verbose) ⇒ void

This method returns an undefined value.

Animates strings in the user console to alert him that something

is running in the background.

The animation is chosen among a bunch of themes, with the configuration option ~throbber~ (retrieved via Fronde::Config::Store#get).

Examples:

long_stuff = Thread.new { very_long_operation }
Fronde::CLI::Throbber.run(long_stuff, 'Computing hard stuff:')

Parameters:

  • thread (Thread)

    the long-running operation to decorate

  • message (String)

    the message to display before the throbber

  • verbose (Boolean)

    whether the decoration should be shown or skipped



62
63
64
65
66
67
68
69
# File 'lib/fronde/cli/throbber.rb', line 62

def run(thread, message, verbose)
  if verbose
    thread.join
  else
    throbber = new(thread, message)
    throbber.run
  end
end

Instance Method Details

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fronde/cli/throbber.rb', line 31

def run
  thread_loop
rescue RuntimeError => e
  show_error
  raise e
  # :nocov: not sure how to emulate a Ctrl+c in rspec
rescue Interrupt => e
  show_message Rainbow(I18n.t('fronde.bin.interrupted')).red, "\n"
  raise e
  # :nocov:
else
  show_message Rainbow(I18n.t('fronde.bin.done')).green, "\n"
end