rsb-gol 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rsb/gol/cli.rb +48 -1
- data/lib/rsb/gol/game.rb +1 -2
- data/lib/rsb/gol/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81f7f7960113b4fcd0b9c47ca9f11ff10a495018
|
4
|
+
data.tar.gz: 4fa41396f706339501fad2dc821d774d3e56bdee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
data/lib/rsb/gol/version.rb
CHANGED