0

任务是使用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'时,没有任何打印出来。

在这种情况下如何处理诅咒,我会很乐意提供建议或线索。提前致谢。

4

1 回答 1

1

您必须调用刷新,以更新屏幕内容:

init_screen()
  5.times do |val|
  str << "This is the #{val} time we've done something.\n"
  addstr(str)
  refresh
  sleep 1
  clear
end
于 2013-11-11T19:27:46.497 回答