b0VIM 7.41W/.danok~dan/dev/gems/whirly/lib/whirly.rbutf-8 3210#"! Utpad3kj\I+  eE! Y 5 4 u t R = '  ] > y ` 7 v n m [    f\TS6"B'"skedPWQP>(wG  zUD5 end end }.join "end end end }.join "%.2x" % nc end @color_directions[i] = rand(3) - 1 nc = 255 elsif nc >= 255 @color_directions[i] = rand(3) - 1 nc = 0 if nc <= 0 nc = c.to_i(16) + color_change color_change = rand(@color_change_rate) * @color_directions[i] @color = @color.scan(/../).map.with_index{ |c, i| def self.next_color end @stream.print "\n\e[s#{@current_frame}\e[u\e[1A" # @stream.print "\e[s#{@current_frame}\e[u" @current_frame += " #{@status}" if @status @current_frame = Paint[@current_frame, @color] if @color @current_frame = @proc ? @proc.call : @frames.next unrender return if @paused def self.render end @stream.print "\n\e[s#{' ' * current_frame_size}\e[u\e[1A" current_frame_size = @current_frame.size return unless @current_frame def self.unrender end @paused = false @stream.print CLI_COMMANDS[:hide_cursor] if @hide_cursor def self.continue end end continue yield if block_given? @stream.print CLI_COMMANDS[:show_cursor] if @hide_cursor @paused = true # unrender def self.pause end true print "TODO" if delete @stream.print CLI_COMMANDS[:show_cursor] if @hide_cursor @enabled = false @thread.terminate return false unless @enabled def self.stop(delete = false) end true end Whirly.stop yield if block_given? # idiomatic block syntax end end sleep(@interval) render next_color if @color while true # it's just a spinner, no exact timing here @thread = Thread.new do # start spinner loop @stream.print CLI_COMMANDS[:hide_cursor] if @hide_cursor # hide cursor end end warn "Whirly warning: Using colors requires the paint gem" else @color_change_rate = color_change_rate @color_directions = (0..2).map{ |e| rand(3) - 1 } @color = "%.6x" % rand(16777216) if defined?(Paint) if use_color # init color @proc = @spinner["proc"] @frames = @spinner["frames"] && @spinner["frames"].cycle @interval = (interval || @spinner["interval"] || 100) * 0.001 @hide_cursor = hide_cursor raise(ArgumentError, "Whirly: Invalid spinner given") if !@spinner || (!@spinner["frames"] && !@spinner["proc"]) @spinner = SPINNERS[spinner.to_s] @status = status @stream = stream @paused = false @enabled = true # save options and preprocess return false if @enabled # only activate once at_exit{ @stream.print CLI_COMMANDS[:show_cursor] } if !defined?(@enabled) && hide_cursor # ensure cursor is visible after exit return false unless stream.tty? # only actviate if we are on a real terminal hide_cursor: true) status: nil, color_change_rate: 30, use_color: defined?(Paint), spinner: "whirly", interval: nil, def self.start(stream: $stdout, end @paused def self.paused? end @enabled def self.enabled? end attr_accessor :status class << self } show_cursor: "\x1b[?25h", hide_cursor: "\x1b[?25l", CLI_COMMANDS = {module Whirly# TODO clear previous frame# TODO configure extra-line belowrequire "paint"require_relative "whirly/spinners"require_relative "whirly/version"