summaryrefslogtreecommitdiffstats
path: root/CLI/ruby/lib/game_of_life.rb
diff options
context:
space:
mode:
Diffstat (limited to 'CLI/ruby/lib/game_of_life.rb')
-rw-r--r--CLI/ruby/lib/game_of_life.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/CLI/ruby/lib/game_of_life.rb b/CLI/ruby/lib/game_of_life.rb
index 2ff548c..b1a95f1 100644
--- a/CLI/ruby/lib/game_of_life.rb
+++ b/CLI/ruby/lib/game_of_life.rb
@@ -106,9 +106,13 @@ module GameOfLife
# and rendering of the current universe/banner info
# based on the delay/cell configured by the user
def render(universe)
- puts "\33c\e[3J" # Clears the screen and scrollback buffer.
- puts universe.to_s
- puts BANNER
+ # Use Alternate Screen (\e[?1049h) and move cursor to top left (\e[H)
+ # Ref: https://github.com/ruby/ruby/blob/ruby_2_7/lib/irb/easter-egg.rb#L112-L131
+ # Ref: https://stackoverflow.com/questions/11023929/using-the-alternate-screen-in-a-bash-script
+ # Ref: https://superuser.com/questions/122911/what-commands-can-i-use-to-reset-and-clear-my-terminal
+ print "\e[?1049h\e[H"
+ print universe.to_s
+ print BANNER
sleep(DELAY / 1000.0)
end
end