diff options
| author | a14m <[email protected]> | 2020-12-10 21:31:16 +0000 |
|---|---|---|
| committer | a14m <[email protected]> | 2020-12-10 21:31:16 +0000 |
| commit | fe3c74d73728de8c732af6982aad2d19e3f61373 (patch) | |
| tree | 35f07cdcf823d03316e803d79bd25d8a7272a378 /CLI/ruby/bin | |
| parent | b4e9a712549dba1326aa680157574e946e1faa85 (diff) | |
| parent | 88ec97f698f5ba68ad2a4be0f45cefa24a3f8934 (diff) | |
Merge branch 'feature/ruby/seed' into 'master'
Feature/ruby/seed
See merge request a14m/game-of-life!6
Diffstat (limited to 'CLI/ruby/bin')
| -rwxr-xr-x | CLI/ruby/bin/game-of-life | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/CLI/ruby/bin/game-of-life b/CLI/ruby/bin/game-of-life index 0230271..f49682e 100755 --- a/CLI/ruby/bin/game-of-life +++ b/CLI/ruby/bin/game-of-life @@ -20,10 +20,10 @@ class CLI < Thor class_option "input", aliases: "-i", type: :string, banner: :VALUE, desc: "Specify the path/URL for the file to use as an initial state. (used instead of seed)" - class_option "width", aliases: "-w", type: :numeric, banner: :WIDTH, + class_option "width", type: :numeric, banner: :WIDTH, desc: "Specify the width of generated universe. (default to terminal width)" - class_option "height", aliases: "-h", type: :numeric, banner: :HEIGHT, + class_option "height", type: :numeric, banner: :HEIGHT, desc: "Specify the hight of generated universe. (default to terminal height)" class_option "dead-cell", type: :string, banner: :CHAR, default: "\s", @@ -34,18 +34,31 @@ class CLI < Thor class_option "delay", aliases: "-d", type: :numeric, banner: "Milli-Seconds", default: 50, desc: "Specify the introduced delay between each generation" + # rubocop:disable Metrics/AbcSize + # rubocop:disable Metrics/MethodLength def start + max_height = IO.console.winsize[0] - 2 + max_width = IO.console.winsize[1] + if options["width"]&.> max_width + fail GameOfLife::Error, "Invalid --width value, must not exceed current terminal width: #{max_width}" + end + if options["height"]&.> max_height + fail GameOfLife::Error, "Invalid --height value, must not exceed current terminal height: #{max_height}" + end + 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], + "height" => max_height, + "width" => max_width, "seed" => rand(100_000), }.merge(options) universe = GameOfLife.generate(options_with_console_defaults) GameOfLife.run(universe) end + # rubocop:enable Metrics/AbcSize + # rubocop:enable Metrics/MethodLength class << self # Allow exit with status 1 on failure |
