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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4f963c78fba302d24ef508e16cc7cf582f879ef
4
- data.tar.gz: 747799f998285ac6ce9217f0c91000839e361459
3
+ metadata.gz: d0cf6f3e0b9eec7b7be21f0acaa82870327fd456
4
+ data.tar.gz: 2022ddaea631e2297a6eb8118251afbcf1564d05
5
5
  SHA512:
6
- metadata.gz: e2c6d763a21adaec119190811f80a86090f5f0927e897a65893a2999889ae7affecf73e4b5a67710be08a04baf95240583fc392dded0c3f0aed087b9242eef69
7
- data.tar.gz: a5e1792a63bbbaaf994ae314ee725d0fc2edfc8d81c3c15dde24ce7283a60d202caf30266a4a69e725173558b6f711bbe28f118c7cc3982696f232e621321283
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
- @marks = build_marks(mark)
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 run
35
- clear_screen
36
- loop do
37
- trap(:INT) do
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)
@@ -1,3 +1,3 @@
1
1
  module LetItFall
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: let_it_fall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyoendo