Module: GreenHat::Spinner
- Included in:
- Thing
- Defined in:
- lib/greenhat/thing/spinner.rb
Overview
Info Formatter
Instance Method Summary collapse
-
#humanize(time) ⇒ Object
Replace TimeDifference with stackoverflow.com/a/4136485/1678507.
- #spin_done ⇒ Object
- #spin_start(title) ⇒ Object
- #time ⇒ Object
Instance Method Details
#humanize(time) ⇒ Object
Replace TimeDifference with stackoverflow.com/a/4136485/1678507
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/greenhat/thing/spinner.rb', line 40 def humanize(time) miliseconds = (Time.now - time) * 1000 [[1000, :ms], [60, :s], [60, :m], [24, :h]].map do |count, name| next unless miliseconds.positive? miliseconds, n = miliseconds.divmod(count) "#{n.to_i}#{name}" unless n.to_i.zero? end.compact.reverse.join(' ') end |
#spin_done ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/greenhat/thing/spinner.rb', line 18 def spin_done # Ignore when Quiet is Set return true if Cli.quiet title = @spinner.tokens[:title] spin_end = humanize(@spin_time) title_update = if spin_end.blank? title else "#{title} (#{spin_end.pastel(:blue)})" end @spinner.update(title: title_update) @spinner.success end |
#spin_start(title) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/greenhat/thing/spinner.rb', line 4 def spin_start(title) # Ignore when Quiet is Set return true if Cli.quiet @spin_time = Time.now @spinner = TTY::Spinner.new( "#{time.pastel(:bright_black)} - [:spinner] :title", hide_cursor: true, success_mark: '✔'.pastel(:green) ) @spinner.update(title: title) # Don't Auto spin when debug output is happening @spinner.auto_spin unless ENV['DEBUG'] end |
#time ⇒ Object
35 36 37 |
# File 'lib/greenhat/thing/spinner.rb', line 35 def time Time.now.strftime('%I:%M:%S').pastel(:bright_black) end |