simple-spinner/src/spinner.cr
Aşkın Gedik a7b2e9a6f3 init
2015-12-30 13:56:47 +02:00

39 lines
597 B
Crystal

require "./spinner/*"
class Spin
property delay, chars
CL = STDOUT.tty? ? "\u001b[0G" : "\u000d \u000d"
CLEAR = STDOUT.tty? ? "\u001b[2K" : "\u000d"
def initialize(@delay = 0.1, @chars = CHARSET[:pipe])
@state = true
end
def stop
@state = false
print CLEAR
end
private def clear(count)
print CL * count
end
def start
spawn do
i = 0
while @state
chars = @chars[i % @chars.size]
print "#{chars}"
# to_s for colorize
clear(chars.to_s.size)
sleep @delay
i += 1
end
end
end
end