curses中的退格字符

时间:2013-10-12 22:05:22

标签: ruby curses

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 个答案:

答案 0 :(得分:1)

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

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