Answer the question
In order to leave comments, you need to log in
How to animate input line?
In general, I want to make a line animation so that during the input by a person (gets) in place of the letter "the wand is spinning"
The cycle for turning the wand is here:
def ss
while true
print "|\r"
sleep 0.2
print "/\r"
sleep 0.2
print "-\r"
sleep 0.2
print "\\\r"
sleep 0.2
end
end
a = Thread.new { ss }
Answer the question
In order to leave comments, you need to log in
Can it be like this
def spinner
chars = %w{ | / - \\ }
thread = Thread.new { yield }
while thread.alive?
$stdout.print chars[0]
sleep 0.5
$stdout.print "\b"
chars.push chars.shift
end
thread.join
end
spinner do
name=gets
puts name
end
If you want the wand to spin at the same time and you can enter text, then this is very unlikely.
If you just animate something:
https://github.com/prydonius/spinning_cursor
https://www.ruby-toolbox.com/categories/CLI_Progre...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question