From 80776ace98f5d532366e4432beaf20cd96e10a3b Mon Sep 17 00:00:00 2001 From: a14m Date: Wed, 10 Feb 2021 22:35:11 +0100 Subject: Better and more performant ruby rendering in alternative terminal 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 --- CLI/ruby/lib/game_of_life.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'CLI/ruby/lib') 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 -- cgit v1.2.3