class SpinningCursor::Cursor
This class contains the cursor types (and their helper methods)
Public Class Methods
new(parsed)
click to toggle source
As of v0.1.0: only initializes the cursor class, use the spin method to start the printing. Takes only the banner argument as a result of this.
# File lib/spinning_cursor/cursor.rb, line 13 def initialize(parsed) @parsed = parsed end
Public Instance Methods
spin()
click to toggle source
Takes a cursor type symbol and delay, and starts the printing
# File lib/spinning_cursor/cursor.rb, line 20 def spin $stdout.sync = true if @parsed.delay send @parsed.type, @parsed.delay else send @parsed.type end end
Private Instance Methods
cycle_through(chars, delay)
click to toggle source
# File lib/spinning_cursor/cursor.rb, line 45 def cycle_through(chars, delay) chars.cycle do |char| unless @parsed.output==:at_stop or captured_console_empty? $console.print "#{ESC_R_AND_CLR}" $console.print $stdout.string $console.print "\n" unless $stdout.string[-1,1] == "\n" $stdout.string = "" # TODO: Check for race condition. end reset_line @parsed.banner.empty? ? char : "#{@parsed.banner} #{char}" sleep delay end end
dots(delay = 1)
click to toggle source
Prints three dots and clears the line
# File lib/spinning_cursor/cursor.rb, line 34 def dots(delay = 1) cycle_through ['.', '..', '...', ''], delay end
spinner(delay = 0.5)
click to toggle source
Cycles through '|', '/', '-', '', resembling a spinning cursor
# File lib/spinning_cursor/cursor.rb, line 41 def spinner(delay = 0.5) cycle_through ['|', '/', '-', '\\'], delay end