2013-10-12 116 views
-1
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 

而且退格字符詛咒

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 

我想打印一個0,0消失,然後是1,則有1消失,然後是2,則有2消失,一直到6

回答

1

delch刪除光標下的字符。你只需要重置光標位置:

6.times do |i| 
    win2.setpos(1, 1) 
    win2.addstr i.to_s 
    win2.refresh 
    sleep 0.6 
end