任务是使用curses lib在一段时间内在没有用户输入的情况下将一些不断变化的信息打印到屏幕上。
以下代码说明了想法。
require 'curses'
include Curses
str = String.new
init_screen()
5.times do |val|
str << "This is the #{val} time we've done something.\n"
addstr(str)
getstr
sleep 1
clear
end
close_screen
按 Enter 第四次后输出是:
This is the 0 time we've done something.
This is the 1 time we've done something.
This is the 2 time we've done something.
This is the 3 time we've done something.
This is the 4 time we've done something.
但是当我删除我不需要的'getstr'时,没有任何打印出来。
在这种情况下如何处理诅咒,我会很乐意提供建议或线索。提前致谢。