Last active
May 13, 2022 17:11
-
-
Save tithonium/403dcb7fa7cb0d046cc56c5d0c480450 to your computer and use it in GitHub Desktop.
Spinner - I had a long-running process that I didn't want to make spammy, but wanted to know it was /going/. So...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SPINNER = ("\u2800".."\u28ff").to_a.shuffle | |
def spinner | |
if @spinstep.nil? | |
@spinstep = 0 | |
else | |
return if (Time.now - @spintime) < 0.1 | |
STDOUT.print "\b \b" | |
end | |
@spintime = Time.now | |
STDOUT.print SPINNER[(@spinstep += 1) % SPINNER.length] | |
end | |
def unspinner | |
if @spinstep | |
STDOUT.puts "\b \b" | |
@spinstep = nil | |
@spintime = nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment