consoleparty 0.4.1 → 0.5.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/party.rb +53 -27
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8676ab579c7845c6b90bb6fe02ce6a92ecae5fe
4
- data.tar.gz: ab5268f4de4f5c0789ffaa209d264ad6867ce1d0
3
+ metadata.gz: aebcc82678ca2ecee6e7bb2131292687f7bfdc29
4
+ data.tar.gz: 73991d52fa4de070fb672473a7b63eabdfe293b9
5
5
  SHA512:
6
- metadata.gz: 06f5aa33804dece1c7b440910b498db7e2bef96a259242cf300998f8306bc43a74bc898ce8732d3470b81af53d6afb1b0031ada645cec40057aa79e2b3362335
7
- data.tar.gz: 4e0e33a66802a9611bdac082a6156facd3d019ce99390dcb0a1d86a7b95c9630862fd6e85c52a08019ffb84abe8e3484dc6dcb88edfc922f89ed08370c0c143c
6
+ metadata.gz: d664dc3019b8b887433c47ae347532af8ecd1380e3b2cc7aafbce9f6c05e91be90d17d97a91ac8e66c33543ba0011bab5a7e99403cd627871724198bde30b550
7
+ data.tar.gz: f4060f1a8a6833a3659536a3f1545a9976a532a46b12a1d84332a737d7b12529b60aea150e5669c19edd486f88f25e9693030d48b3117e7cbfdeb2c1da8a81e1
@@ -1,31 +1,36 @@
1
1
  require 'curses'
2
2
  require 'getoptlong'
3
+ def help_and_exit
4
+ puts <<~EOF
5
+ party [--silent] [-f "farewell"] [-w "words" -w "in" -w "rectangle"...] ["Things", "To", "Say"]
6
+
7
+ -h, --help:
8
+ show help
9
+
10
+ -f [greeting], --farewell [greeting]:
11
+ says greeting at the end, or "I had a great time" by default
12
+
13
+ -s, --silent:
14
+ start a silent party (without MC)
15
+ EOF
16
+ exit()
17
+ end
3
18
 
4
19
  opts = GetoptLong.new(
5
20
  [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
6
21
  [ '--farewell', '-f', GetoptLong::OPTIONAL_ARGUMENT ],
7
- [ '--silent', '-s', GetoptLong::OPTIONAL_ARGUMENT ]
22
+ [ '--silent', '-s', GetoptLong::OPTIONAL_ARGUMENT ],
23
+ [ '--written', '-w', GetoptLong::OPTIONAL_ARGUMENT ]
8
24
  )
9
25
 
10
26
  silent = false
11
27
  farewell = false
12
28
  stuff_to_say = ["Party", "Wo-hoo", "Party", "Yeah"]
29
+ written_words = []
13
30
  opts.each do |opt, arg|
14
31
  case opt
15
32
  when '--help'
16
- puts <<~EOF
17
- party [--silent] ... ["Things", "To", "Say"]
18
-
19
- -h, --help:
20
- show help
21
-
22
- -f [greeting], --farewell [greeting]:
23
- says greeting at the end, or "I had a great time" by default
24
-
25
- -s, --silent:
26
- start a silent party (without MC)
27
- EOF
28
- exit()
33
+ help_and_exit()
29
34
  when '--farewell'
30
35
  if arg == ''
31
36
  farewell = "Ei häd äh Grad Tim"
@@ -34,9 +39,20 @@ opts.each do |opt, arg|
34
39
  end
35
40
  when '--silent'
36
41
  silent = true
42
+ when '--written'
43
+ if arg == ''
44
+ puts "-w must be followed by an argument"
45
+ help_and_exit()
46
+ exit();
47
+ end
48
+ written_words.push(arg)
37
49
  end
38
50
  end
39
51
 
52
+ unless written_words.length > 0
53
+ written_words = ["Party", "Wohoo"]
54
+ end
55
+
40
56
  if ARGV.length != 0
41
57
  stuff_to_say = ARGV
42
58
  end
@@ -45,7 +61,7 @@ end
45
61
  include Curses
46
62
  class Party
47
63
 
48
- def self.start(silent, farewell, stuff_to_say)
64
+ def self.start(written_words, silent, farewell, stuff_to_say)
49
65
  interrupted = false
50
66
  cols = (%x( tput cols )).to_i
51
67
  lines = (%x( tput lines )).to_i
@@ -68,14 +84,17 @@ class Party
68
84
  delta = 1
69
85
  while !interrupted
70
86
  sleep_time = (1.0/i.to_f)*1.3
71
- sem.synchronize {
72
- draw_rect(rec_left_x,rec_left_y,rec_width,rec_height, color_pair((i+3)%5), color_pair((i+3)%5), "PARTY")
73
- }
74
- sleep(sleep_time)
75
- sem.synchronize {
76
- draw_rect(rec_left_x,rec_left_y,rec_width,rec_height, color_pair(1), color_pair(1), "WOHOO")
77
- }
78
- sleep(sleep_time)
87
+ written_words.each.with_index do |word, w_i|
88
+ sem.synchronize {
89
+ if w_i % 2 == 0
90
+ draw_rect(rec_left_x,rec_left_y,rec_width,rec_height, color_pair((i+3)%5), color_pair((i+3)%5), word)
91
+ else
92
+ draw_rect(rec_left_x,rec_left_y,rec_width,rec_height, color_pair(1), color_pair(1), word)
93
+ end
94
+ }
95
+ sleep(sleep_time)
96
+ end
97
+
79
98
  i+=delta
80
99
  if i == 10
81
100
  delta = -1
@@ -166,13 +185,19 @@ class Party
166
185
 
167
186
  for j in 0..h-2
168
187
  setpos(leftY+1+j, leftX+2)
169
- for o in 1..(l-4)/string.length
170
- addstr(string)
171
- end
188
+ addstr(word_snake(string, l-4))
172
189
  end
173
190
  refresh
174
191
  end
175
192
 
193
+ def self.word_snake(string, length)
194
+ s = ""
195
+ for _ in 0..(length/string.length)
196
+ s += string
197
+ end
198
+ s[0..(length-1)]
199
+ end
200
+
176
201
 
177
202
  def self.draw_line(lineNr, should_not_draw)
178
203
  setpos(lineNr, 0)
@@ -206,4 +231,5 @@ class Party
206
231
  end
207
232
  end
208
233
 
209
- Party.start(silent, farewell, stuff_to_say)
234
+ Party.start(written_words, silent, farewell, stuff_to_say)
235
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consoleparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calvin Claus