Here is a program that shows a simple animation to show the user that the program is waiting for input, or is doing something, and it hasn't crashed:
require "curses"
include Curses
chars = [" ","* ","** ","***","***","** ","* "," "]
four = Window.new(3,20,10,30)
four.box('|', '-')
four.setpos 1, 1
four.addstr "Hello"
while ( true )
four.setpos 1, 6
four.addstr chars[0]
four.refresh
sleep 0.1
chars.push chars.shift
end
Inside the while loop, the cursor is repositioned to line 1, column 6 every turn of the loop. This is so that stars are overwritten with blank spaces and it all works perfectly.
However, try changing the "Hello" string to "Hello Everyone"
As you can see, the star animation now occurs in the middle of this string. The animation hasn't been 'shunted along'. Is there a way to automatically append the animation to the end of a string?
Or would I need to programatically position it? Find the length of the hello string and add 1 to it, and use this to position the col coordinate?