显示更新信息,无需用户与curses交互

时间:2013-11-11 19:17:54

标签: ruby curses

任务是使用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键第4次输出后:

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'时,我不需要打印出来。

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

1 个答案:

答案 0 :(得分:1)

您必须调用refresh,才能更新屏幕内容:

init_screen()
  5.times do |val|
  str << "This is the #{val} time we've done something.\n"
  addstr(str)
  refresh
  sleep 1
  clear
end