let_it_fall 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/let_it_fall.rb +34 -12
- data/lib/let_it_fall/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: d0cf6f3e0b9eec7b7be21f0acaa82870327fd456
|
4
|
+
data.tar.gz: 2022ddaea631e2297a6eb8118251afbcf1564d05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c25ec23290c61830447469fb7b102c25059763dcf600a824785337ee790249dfe14807f796edba52d84b0762e20276f0d2af0d96ca2020cf52b20e067b18ddf4
|
7
|
+
data.tar.gz: 8f4030cd6a334dd70d52e35ab7305cba399e6bbaeb4035399d5c31408e3e59dfcee8d5ce396c1ccef226970f85c25e4151b1e19968effbd38fa42f4b3db042a5
|
data/lib/let_it_fall.rb
CHANGED
@@ -15,13 +15,36 @@ module LetItFall
|
|
15
15
|
else
|
16
16
|
raise ArgumentError, "color should be 31-37 or nil"
|
17
17
|
end
|
18
|
-
@
|
18
|
+
@mark = mark
|
19
19
|
@interval = interval
|
20
20
|
@screen = {}
|
21
21
|
@matrix = matrix
|
22
22
|
$stdout.sync = true
|
23
23
|
end
|
24
24
|
|
25
|
+
def run
|
26
|
+
clear_screen
|
27
|
+
marks = build_marks(@mark)
|
28
|
+
Thread.new do
|
29
|
+
while STDIN.getc # hit return
|
30
|
+
marks = select_next_marks(@mark)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
loop do
|
35
|
+
trap(:INT) do
|
36
|
+
reset_screen
|
37
|
+
exit(0)
|
38
|
+
end
|
39
|
+
print_marks(rand(@x), 0, marks)
|
40
|
+
sleep @interval
|
41
|
+
end
|
42
|
+
ensure
|
43
|
+
reset_screen
|
44
|
+
exit(0)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
25
48
|
def build_marks(mark)
|
26
49
|
marks =
|
27
50
|
case mark
|
@@ -31,21 +54,20 @@ module LetItFall
|
|
31
54
|
Array(marks).map { |code| code.chr("UTF-8") }.cycle
|
32
55
|
end
|
33
56
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
print "\e[?25h\e[0;0H" # show cursor and set 0,0 pos
|
39
|
-
exit(0)
|
40
|
-
end
|
41
|
-
print_marks(rand(@x), 0, @marks)
|
42
|
-
sleep @interval
|
57
|
+
def select_next_marks(mark)
|
58
|
+
unless @_markset
|
59
|
+
keys = CODESET.keys
|
60
|
+
@_markset = keys.rotate(keys.index(@mark)+1).cycle
|
43
61
|
end
|
62
|
+
build_marks(@_markset.next)
|
44
63
|
end
|
45
64
|
|
46
|
-
private
|
47
65
|
def clear_screen
|
48
|
-
print "\e[?25l\e[2J"
|
66
|
+
print "\e[?25l\e[2J" # hide cursor and clear screen
|
67
|
+
end
|
68
|
+
|
69
|
+
def reset_screen
|
70
|
+
print "\e[?25h\e[0;0H" # show cursor and set 0,0 pos
|
49
71
|
end
|
50
72
|
|
51
73
|
def print_marks(pos_x, pos_y, marks)
|
data/lib/let_it_fall/version.rb
CHANGED