-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

4

1 回答 1

1

delch删除光标下的字符。您只需要重置光标位置:

6.times do |i|
  win2.setpos(1, 1)
  win2.addstr i.to_s
  win2.refresh
  sleep 0.6
end
于 2013-10-12T23:04:36.117 回答