Hi everyone, I have a question. I try actually to make a spinner similar to the candy feature of emerge for who know Gentoo Linux. I almost done it, but I don’t get how to delete previous/next character without moving the cursor.
These are the functions use to do this animation actually in my project:
def resetCalculationAnimation
@calculationStartingTime = Time.monotonic
@frameIndex = 0
@reverseAnimation = false
end
def playCalculationAnimation(@text = ISM::Default::CommandLine::CalculationWaitingText)
currentTime = Time.monotonic
if (currentTime - @calculationStartingTime).milliseconds > 40
if @frameIndex == @text.size && !@reverseAnimation
@reverseAnimation = true
end
if @frameIndex < 1
@reverseAnimation = false
end
if @reverseAnimation
print "\033[1D"
print " "
print "\033[1D"
@frameIndex -= 1
end
if !@reverseAnimation
print "#{@text[@frameIndex].colorize(:green)}"
@frameIndex += 1
end
@calculationStartingTime = Time.monotonic
end
end
def cleanCalculationAnimation
loop do
if @frameIndex > 0
print "\033[1D"
print " "
print "\033[1D"
@frameIndex -= 1
else
break
end
end
end