Browse files

Re-rendering CLI output on top of itself

  • Loading branch information...
1 parent 4617b42 commit e94d876a3dcf4ced73efcb77d82cbbe56221b369 Jason Kotchoff committed Aug 28, 2011
Showing with 8 additions and 3 deletions.
  1. +8 −3 world.rb
View
11 world.rb
@@ -146,14 +146,19 @@ def world_state_to_s(world_state = current_state)
end
class WorldSimulator
+ require 'curses'
+
def self.run(world_origin_state_file_path, sleep_time = 0.4)
- puts "\nRunning Game of Life simulation - press <ctrl> + c to stop\n\n"
-
original_state = File.read(world_origin_state_file_path)
world = TwoDimensionalRectangularWorld.new(original_state)
loop do
- puts world.to_s
+ Curses.clear
+ Curses.setpos(1, 0)
+ Curses.addstr("Running Game of Life simulation on #{world_origin_state_file_path} - press <ctrl> + c to stop")
+ Curses.setpos(2, 0)
+ Curses.addstr(world.to_s)
+ Curses.refresh
world.evolve!
sleep sleep_time.to_f
end

0 comments on commit e94d876

Please sign in to comment.