Question

require 'curses'
    include Curses

    init_screen

    win2 = Window.new(3,160,12,10)
    win2.setpos(1,1)


    6.times do |i|
        win2.addstr i.to_s
        win2.delch
        sleep 0.6
        win2.refresh
    end #=> 0,1,2,3,4,5,6

And

    6.times do |i|
        win2.addstr i.to_s
        win2.addstr '\b'
        sleep 0.6
        win2.refresh
    end #=> 0\n,1\n,2\n,3\n,4\n,5\n,6\n

I want to print a 0, the 0 to disappear, then a 1, then have the 1 disappear, then a 2, then have the 2 disappear, all the way up to 6

Was it helpful?

Solution

delch deletes the character under the cursor. You just have to reset the cursor position:

6.times do |i|
  win2.setpos(1, 1)
  win2.addstr i.to_s
  win2.refresh
  sleep 0.6
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top