rsb-gol 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3da5ccda1bc86c201ea34f365e97e54f96e3852
4
- data.tar.gz: 227feae90ef9c9cab4c6cd437d2022892947229f
3
+ metadata.gz: 81f7f7960113b4fcd0b9c47ca9f11ff10a495018
4
+ data.tar.gz: 4fa41396f706339501fad2dc821d774d3e56bdee
5
5
  SHA512:
6
- metadata.gz: 426fda512a0efc72141d96d9039467891068522db30ac8b0ef840a143529cf7a0c581c91ddef9c10251516958db6f0f3d3aca79276cbda7d345e81a4b93f18e4
7
- data.tar.gz: 0d2b80588b01f2ff3d77f851454557bf6e664ece729d998caff8cdeed2d5c409b972efe303ea2806a15c6ff3ad43919dee064b9ae1fa5eb7a0b064fd708c121f
6
+ metadata.gz: 17b76dd2fe214fb4c975d628f89c8493691c7e19fbde7b153dba089abb6311c5eff3d5086e832fb93e2a446236ff4e044f0434c143dd34d396c58333b7976231
7
+ data.tar.gz: 42c99346c6d1101b7b0077b416560cf74705698691fe710fcea08d48133bb5b6c1c9adfe84d6beda383347f6f6aa463fd2ee38bd5053f602a12b8932ac7c2e7f
data/lib/rsb/gol/cli.rb CHANGED
@@ -3,10 +3,57 @@ require 'thor'
3
3
  module Rsb
4
4
  module Gol
5
5
  class Cli < Thor
6
+ class_option :iterations, type: :numeric, default: 1_000_000
7
+ class_option :alive_char, type: :string, default: '●'
8
+ class_option :death_char, type: :string, default: ' '
9
+ class_option :columns, type: :numeric
10
+ class_option :rows, type: :numeric
11
+
6
12
  desc 'start', 'start the game of life'
7
13
  def start
14
+ rows, columns = screen_size
15
+ iterations = options.iterations
16
+ alive = options.alive_char
17
+ dead = options.death_char
18
+
19
+ columns = options.columns if options.columns?
20
+ rows = options.rows if options.rows?
21
+
8
22
  # ✺ ☻ ⬣ ● ⨀
9
- Rsb::Gol::Game.new.start(1000,'●',' ')
23
+ game = Rsb::Gol::Game.new(cols: columns, rows: rows)
24
+ game.start(iterations, alive, dead)
25
+ end
26
+
27
+ no_commands do
28
+ # credit to: https://gist.github.com/nixpulvis/6025433
29
+ # From the tty_ioctl man page in Linux.
30
+ #
31
+ # TIOCGWINSZ struct winsize *argp
32
+ # Get window size.
33
+ #
34
+ # TIOCSWINSZ const struct winsize *argp
35
+ # Set window size.
36
+ #
37
+ # The struct used by these ioctls is defined as
38
+ #
39
+ # struct winsize {
40
+ # unsigned short ws_row;
41
+ # unsigned short ws_col;
42
+ # unsigned short ws_xpixel; /* unused */
43
+ # unsigned short ws_ypixel; /* unused */
44
+ # };
45
+ # rows cols width height
46
+ def screen_size
47
+ window = [0, 0, 0, 0].pack('SSSS')
48
+ fd = IO.sysopen('/dev/tty', 'w')
49
+ terminal = IO.new(fd, "w")
50
+
51
+ # The in in this call is === TIOCGWINSZ. No idea where it is defined.
52
+ # I found it using ruby-termios with `Termios::TIOCGWINSZ`
53
+ terminal.ioctl(1074295912, window)
54
+ rows, cols, _, _ = window.unpack('SSSS')
55
+ [rows - 10, cols - 10]
56
+ end
10
57
  end
11
58
  end
12
59
  end
data/lib/rsb/gol/game.rb CHANGED
@@ -39,8 +39,7 @@ module Rsb
39
39
  output = universe.visualize(alive, dead)
40
40
 
41
41
  clear_screen
42
-
43
- puts "#{output}\n\n #{status}\n"
42
+ puts "\n\n#{output}\n\n #{status}\n"
44
43
  sleep(1.0/ step)
45
44
  end
46
45
  end
@@ -1,5 +1,5 @@
1
1
  module Rsb
2
2
  module Gol
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsb-gol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Scott-Buccleuch