whirly 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/data/whirly-static-spinners.json +50 -0
- data/lib/whirly.rb +10 -8
- data/lib/whirly/version.rb +1 -2
- data/spec/whirly_spec.rb +118 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 676e277e0721c5b27b89f72b91d218c6132ecea9
|
4
|
+
data.tar.gz: c84ff19c62bc2dd2f178d266c06446465bbc2571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cda16355b8fc8f217c05796bd6b9f524da98b4d9574e8b9a2827fefc05c336e706f3a2de5f5641965b9e95e88bbdfa7b89b3473b1a675c6d65d064ad6f5e205
|
7
|
+
data.tar.gz: ff67f700686adcdad1dd2b2d6c661aab1ec7a0a85f0ebdf6d0a03fbef97fe157daec8970b890020aa559356577ba33344cf50643c823c74fc6456b8b3e83549c
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Whirly 😀 [![[version]](https://badge.fury.io/rb/whirly.svg)](http://badge.fury.io/rb/whirly) [![[travis]](https://travis-ci.org/janlelis/whirly.png)](https://travis-ci.org/janlelis/whirly)
|
2
2
|
|
3
|
-
A simple, colorful and customizable terminal spinner library for Ruby. It comes with
|
3
|
+
A simple, colorful and customizable terminal spinner library for Ruby. It comes with 23 custom spinners and also includes those from the [cli-spinners](https://github.com/sindresorhus/cli-spinners) project.
|
4
4
|
|
5
5
|
## Demonstration
|
6
6
|
|
@@ -171,5 +171,55 @@
|
|
171
171
|
"😿",
|
172
172
|
"🙀"
|
173
173
|
]
|
174
|
+
},
|
175
|
+
"card": {
|
176
|
+
"interval": 90,
|
177
|
+
"stop": "🂠",
|
178
|
+
"frames": [
|
179
|
+
"🃁", "🃂", "🃃", "🃄", "🃅", "🃆", "🃇", "🃈", "🃉", "🃊", "🃋", "🃌", "🃍", "🃎",
|
180
|
+
"🂱", "🂲", "🂳", "🂴", "🂵", "🂶", "🂷", "🂸", "🂹", "🂺", "🂻", "🂼", "🂽", "🂾",
|
181
|
+
"🂡", "🂢", "🂣", "🂤", "🂥", "🂦", "🂧", "🂨", "🂩", "🂪", "🂫", "🂬", "🂭", "🂮",
|
182
|
+
"🃑", "🃒", "🃓", "🃔", "🃕", "🃖", "🃗", "🃘", "🃙", "🃚", "🃛", "🃜", "🃝", "🃞"
|
183
|
+
]
|
184
|
+
},
|
185
|
+
"cloud": {
|
186
|
+
"interval": 140,
|
187
|
+
"frames": [
|
188
|
+
"🌥",
|
189
|
+
"🌦",
|
190
|
+
"🌧",
|
191
|
+
"🌨",
|
192
|
+
"🌩",
|
193
|
+
"🌪"
|
194
|
+
]
|
195
|
+
},
|
196
|
+
"photo": {
|
197
|
+
"interval": 200,
|
198
|
+
"frames": [
|
199
|
+
"📷",
|
200
|
+
"📸"
|
201
|
+
]
|
202
|
+
},
|
203
|
+
"banknote": {
|
204
|
+
"interval": 100,
|
205
|
+
"frames": [
|
206
|
+
"💴",
|
207
|
+
"💵",
|
208
|
+
"💶",
|
209
|
+
"💷"
|
210
|
+
]
|
211
|
+
},
|
212
|
+
"white_square": {
|
213
|
+
"interval": 100,
|
214
|
+
"mode": "swing",
|
215
|
+
"frames": [
|
216
|
+
"🞓",
|
217
|
+
"🞒",
|
218
|
+
"🞑",
|
219
|
+
"🞐",
|
220
|
+
"🞏",
|
221
|
+
"🞎",
|
222
|
+
"🞔"
|
223
|
+
]
|
174
224
|
}
|
175
225
|
}
|
data/lib/whirly.rb
CHANGED
@@ -133,13 +133,6 @@ module Whirly
|
|
133
133
|
# optionally overwrite configuration on start
|
134
134
|
configure(**options)
|
135
135
|
|
136
|
-
# ensure cursor is visible after exit the program (only register for the very first time)
|
137
|
-
if (!defined?(@at_exit_handler_registered) || !@at_exit_handler_registered) && @options[:hide_cursor]
|
138
|
-
@at_exit_handler_registered = true
|
139
|
-
stream = @options[:stream]
|
140
|
-
at_exit{ stream.print CLI_COMMANDS[:show_cursor] }
|
141
|
-
end
|
142
|
-
|
143
136
|
# only enable once
|
144
137
|
return false if defined?(@enabled) && @enabled
|
145
138
|
|
@@ -149,6 +142,13 @@ module Whirly
|
|
149
142
|
# only do something if we are on a real terminal (or forced)
|
150
143
|
return false unless @options[:stream].tty? || @options[:non_tty]
|
151
144
|
|
145
|
+
# ensure cursor is visible after exit the program (only register for the very first time)
|
146
|
+
if (!defined?(@at_exit_handler_registered) || !@at_exit_handler_registered) && @options[:hide_cursor]
|
147
|
+
@at_exit_handler_registered = true
|
148
|
+
stream = @options[:stream]
|
149
|
+
at_exit{ stream.print CLI_COMMANDS[:show_cursor] }
|
150
|
+
end
|
151
|
+
|
152
152
|
# init color
|
153
153
|
initialize_color if @options[:color]
|
154
154
|
|
@@ -176,12 +176,14 @@ module Whirly
|
|
176
176
|
|
177
177
|
def self.stop(stop_frame = nil)
|
178
178
|
return false unless @enabled
|
179
|
+
@enabled = false
|
180
|
+
return false unless @options[:stream].tty? || @options[:non_tty]
|
181
|
+
|
179
182
|
@thread.terminate if @thread
|
180
183
|
render(stop_frame || @stop) if stop_frame || @stop
|
181
184
|
unrender if @options[:remove_after_stop]
|
182
185
|
@options[:stream].puts if @options[:append_newline]
|
183
186
|
@options[:stream].print CLI_COMMANDS[:show_cursor] if @options[:hide_cursor]
|
184
|
-
@enabled = false
|
185
187
|
|
186
188
|
true
|
187
189
|
end
|
data/lib/whirly/version.rb
CHANGED
data/spec/whirly_spec.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require_relative "../lib/whirly"
|
2
2
|
require "minitest/autorun"
|
3
|
+
require "paint"
|
3
4
|
# require "irbtools/binding"
|
4
5
|
require "stringio"
|
5
6
|
|
6
7
|
def short_sleep
|
7
|
-
sleep 0.
|
8
|
+
sleep 0.2
|
8
9
|
end
|
9
10
|
|
10
11
|
def medium_sleep
|
11
|
-
sleep 0.
|
12
|
+
sleep 0.6
|
12
13
|
end
|
13
14
|
|
14
15
|
def long_sleep
|
@@ -169,10 +170,10 @@ describe Whirly do
|
|
169
170
|
spinner = { "frames" => "A".."H", "mode" => "random", "interval" => 10 }
|
170
171
|
|
171
172
|
Whirly.start(spinner: spinner)
|
172
|
-
|
173
|
+
short_sleep
|
173
174
|
Whirly.stop
|
174
175
|
|
175
|
-
refute
|
176
|
+
refute /\A.*?A.*?B.*?C.*?D.*?E.*?F.*?G.*?H/m =~ @capture.string
|
176
177
|
end
|
177
178
|
|
178
179
|
it "can be set to reverse" do
|
@@ -195,6 +196,91 @@ describe Whirly do
|
|
195
196
|
assert_match /A.*B.*C.*D.*E.*F.*G.*H.*G.*F.*E.*D.*C.*B.*A/m, @capture.string
|
196
197
|
end
|
197
198
|
end
|
199
|
+
|
200
|
+
describe "Interval" do
|
201
|
+
it "spins more often when interval is lower" do
|
202
|
+
capture1 = StringIO.new
|
203
|
+
Whirly.start(stream: capture1, interval: 100)
|
204
|
+
medium_sleep
|
205
|
+
Whirly.stop
|
206
|
+
|
207
|
+
capture2 = StringIO.new
|
208
|
+
Whirly.start(stream: capture2, interval: 50)
|
209
|
+
medium_sleep
|
210
|
+
Whirly.stop
|
211
|
+
|
212
|
+
assert capture1.string.size < capture2.string.size
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "Colors" do
|
218
|
+
it "will use no color when :color option is falsey" do
|
219
|
+
Whirly.start(color: false)
|
220
|
+
short_sleep
|
221
|
+
Whirly.stop
|
222
|
+
|
223
|
+
refute /\[38;5;/ =~ @capture.string
|
224
|
+
end
|
225
|
+
|
226
|
+
it "will use color when :color option is truthy" do
|
227
|
+
Whirly.start(color: true)
|
228
|
+
short_sleep
|
229
|
+
Whirly.stop
|
230
|
+
|
231
|
+
assert /\[38;5;/ =~ @capture.string
|
232
|
+
end
|
233
|
+
|
234
|
+
it "defaults :color to true when the paint gem is available" do
|
235
|
+
Whirly.reset
|
236
|
+
Whirly.configure
|
237
|
+
assert Whirly.options[:color]
|
238
|
+
end
|
239
|
+
|
240
|
+
# it "defaults :color to true when the paint gem is not available" do
|
241
|
+
# remember_paint = Paint
|
242
|
+
# Object.send(:remove_const, :Paint)
|
243
|
+
# Whirly.reset
|
244
|
+
# Whirly.configure
|
245
|
+
# Object.send(:const_set, :Paint, remember_paint)
|
246
|
+
# refute Whirly.options[:color]
|
247
|
+
# end
|
248
|
+
|
249
|
+
it "changes the the color" do
|
250
|
+
Whirly.start
|
251
|
+
long_sleep
|
252
|
+
Whirly.stop
|
253
|
+
|
254
|
+
colors = @capture.string.scan(/\[38;5;(\d+)m/).flatten
|
255
|
+
assert colors.uniq.size > 1
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
describe "Cursor" do
|
260
|
+
it "hides (and later shows) cursor when :hide_cursor => true option is given (default)" do
|
261
|
+
Whirly.start(hide_cursor: true)
|
262
|
+
short_sleep
|
263
|
+
Whirly.stop
|
264
|
+
|
265
|
+
assert_match /\[?25l.*\[?25h/m, @capture.string
|
266
|
+
end
|
267
|
+
|
268
|
+
it "does not hide cursor when :hide_cursor => false option is given" do
|
269
|
+
Whirly.start(hide_cursor: false)
|
270
|
+
short_sleep
|
271
|
+
Whirly.stop
|
272
|
+
|
273
|
+
refute /\[?25l.*\[?25h/m =~ @capture.string
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
describe "Spinner Packs" do
|
278
|
+
it "can be passed an alternative set of :spinner_packs" do
|
279
|
+
assert_raises ArgumentError do
|
280
|
+
Whirly.start(spinner_packs: [:cli], spinner: "cat") # whirly is part of :whirly, but not of :cli
|
281
|
+
Whirly.stop
|
282
|
+
end
|
283
|
+
end
|
198
284
|
end
|
199
285
|
|
200
286
|
describe "Ansi Escape Mode" do
|
@@ -213,6 +299,34 @@ describe Whirly do
|
|
213
299
|
end
|
214
300
|
end
|
215
301
|
|
302
|
+
describe "Streams and TTYs" do
|
303
|
+
it "will not output anything on non-ttys" do
|
304
|
+
Whirly.reset
|
305
|
+
@capture = StringIO.new
|
306
|
+
Whirly.start(stream: @capture)
|
307
|
+
short_sleep
|
308
|
+
Whirly.stop
|
309
|
+
assert_equal "", @capture.string
|
310
|
+
end
|
311
|
+
|
312
|
+
it "will output something on non-ttys when :non_tty => true option is given" do
|
313
|
+
Whirly.reset
|
314
|
+
@capture = StringIO.new
|
315
|
+
Whirly.start(stream: @capture, non_tty: true)
|
316
|
+
short_sleep
|
317
|
+
Whirly.stop
|
318
|
+
refute_equal "", @capture.string
|
319
|
+
end
|
320
|
+
|
321
|
+
it "can be configured to which stream whirly's output goes" do
|
322
|
+
iolike = StringIO.new
|
323
|
+
Whirly.start(stream: iolike, non_tty: true)
|
324
|
+
short_sleep
|
325
|
+
Whirly.stop
|
326
|
+
refute_equal "", iolike.string
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
216
330
|
describe "Positioning" do
|
217
331
|
it "will render spinner 1 line further below (useful for spinning while git cloning)" do
|
218
332
|
Whirly.start(position: "below")
|
@@ -263,4 +377,3 @@ describe Whirly do
|
|
263
377
|
end
|
264
378
|
end
|
265
379
|
end
|
266
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whirly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Lelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode-display_width
|