From 187b189044b19482879eac3ed63772f3d8d2e000 Mon Sep 17 00:00:00 2001 From: a14m Date: Thu, 3 Dec 2020 12:53:50 +0100 Subject: Add the delay option to the bin and trap Kernel [SIG]nal-[INT]errupt --- CLI/ruby/bin/game-of-life | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'CLI/ruby/bin') 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 -- cgit v1.2.3