summaryrefslogtreecommitdiffstats
path: root/CLI/ruby
diff options
context:
space:
mode:
authora14m <[email protected]>2020-12-03 12:53:50 +0100
committera14m <[email protected]>2020-12-03 12:53:50 +0100
commit187b189044b19482879eac3ed63772f3d8d2e000 (patch)
treefa30a7182a231468570687357c04b0349593b65c /CLI/ruby
parentb20ea269b244b448231d548fca4f068cbfce31e2 (diff)
Add the delay option to the bin and trap Kernel [SIG]nal-[INT]errupt
Diffstat (limited to 'CLI/ruby')
-rwxr-xr-xCLI/ruby/bin/game-of-life21
1 files changed, 14 insertions, 7 deletions
diff --git a/CLI/ruby/bin/game-of-life b/CLI/ruby/bin/game-of-life
index 4de4fd4..28864ad 100755
--- a/CLI/ruby/bin/game-of-life
+++ b/CLI/ruby/bin/game-of-life
@@ -31,17 +31,20 @@ class CLI < Thor
class_option "live-cell", type: :string, banner: :CHAR, default: "\u2588",
desc: "Specify the dead-cell representation"
+
+ class_option "delay", aliases: "-d", type: :numeric, banner: "Milli-Seconds", default: 50,
+ desc: "Specify the introduced delay between each generation"
def start
- options_with_defaults = {
- "height" => IO.console.winsize[0],
+ options_with_console_defaults = {
+ # Defaults the hight to less then the height of the terminal to allow banner info
+ # and an extra emtpy line to avoid triggering terminal scroll while flushing
+ "height" => IO.console.winsize[0] - 3,
"width" => IO.console.winsize[1],
"seed" => rand(100_000),
}.merge(options)
- GameOfLife::Cell.const_set(:LIVE_CELL, options["live-cell"])
- GameOfLife::Cell.const_set(:DEAD_CELL, options["dead-cell"])
- universe = GameOfLife::Generators::Input.new(options_with_defaults)
- puts universe
+ universe = GameOfLife.generate(options_with_console_defaults)
+ GameOfLife.run(universe)
end
class << self
@@ -53,4 +56,8 @@ class CLI < Thor
end
end
-CLI.start(ARGV)
+begin
+ CLI.start(ARGV)
+rescue SystemExit, Interrupt
+ "Do nothing when user exits with Interrupt (CMD/Ctrl + C)"
+end