tty-spinner 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +120 -0
  3. data/README.md +28 -10
  4. data/Rakefile +8 -0
  5. data/examples/auto_spin.rb +8 -0
  6. data/examples/basic.rb +8 -0
  7. data/examples/clear.rb +9 -0
  8. data/examples/color.rb +12 -0
  9. data/examples/error.rb +9 -0
  10. data/examples/formats.rb +11 -0
  11. data/examples/hide_cursor.rb +12 -0
  12. data/examples/multi/basic.rb +13 -0
  13. data/examples/multi/basic_top_level.rb +13 -0
  14. data/examples/multi/custom_style.rb +26 -0
  15. data/examples/multi/files.rb +14 -0
  16. data/examples/multi/jobs.rb +10 -0
  17. data/examples/multi/multi.rb +17 -0
  18. data/examples/multi/multi_top_level.rb +18 -0
  19. data/examples/multi/pause.rb +26 -0
  20. data/examples/multi/threaded.rb +30 -0
  21. data/examples/pause.rb +19 -0
  22. data/examples/run.rb +18 -0
  23. data/examples/success.rb +9 -0
  24. data/examples/threaded.rb +11 -0
  25. data/examples/update.rb +11 -0
  26. data/lib/tty-spinner.rb +0 -2
  27. data/lib/tty/spinner.rb +40 -30
  28. data/lib/tty/spinner/formats.rb +3 -3
  29. data/lib/tty/spinner/multi.rb +31 -12
  30. data/lib/tty/spinner/version.rb +2 -2
  31. data/spec/spec_helper.rb +51 -0
  32. data/spec/unit/auto_spin_spec.rb +27 -0
  33. data/spec/unit/clear_spec.rb +18 -0
  34. data/spec/unit/error_spec.rb +46 -0
  35. data/spec/unit/events_spec.rb +37 -0
  36. data/spec/unit/formats_spec.rb +9 -0
  37. data/spec/unit/frames_spec.rb +33 -0
  38. data/spec/unit/hide_cursor_spec.rb +53 -0
  39. data/spec/unit/job_spec.rb +14 -0
  40. data/spec/unit/join_spec.rb +12 -0
  41. data/spec/unit/multi/auto_spin_spec.rb +34 -0
  42. data/spec/unit/multi/error_spec.rb +109 -0
  43. data/spec/unit/multi/line_inset_spec.rb +59 -0
  44. data/spec/unit/multi/on_spec.rb +13 -0
  45. data/spec/unit/multi/register_spec.rb +47 -0
  46. data/spec/unit/multi/spin_spec.rb +103 -0
  47. data/spec/unit/multi/stop_spec.rb +97 -0
  48. data/spec/unit/multi/success_spec.rb +110 -0
  49. data/spec/unit/new_spec.rb +26 -0
  50. data/spec/unit/pause_spec.rb +25 -0
  51. data/spec/unit/reset_spec.rb +21 -0
  52. data/spec/unit/run_spec.rb +32 -0
  53. data/spec/unit/spin_spec.rb +90 -0
  54. data/spec/unit/stop_spec.rb +64 -0
  55. data/spec/unit/success_spec.rb +46 -0
  56. data/spec/unit/update_spec.rb +87 -0
  57. data/tasks/console.rake +11 -0
  58. data/tasks/coverage.rake +11 -0
  59. data/tasks/spec.rake +29 -0
  60. data/tty-spinner.gemspec +27 -0
  61. metadata +62 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 78cca8f09f1905f3cc652e58d71e0e9aaa0b90af
4
- data.tar.gz: 8b4776c0f0e1e347edf5f03af42a548198ad24fe
2
+ SHA256:
3
+ metadata.gz: 6eab9dfc9f0d8787064da1d1e185288753ae915679a0852a28390355448209ed
4
+ data.tar.gz: a16e2d6cd158a62d6addb92d6bc591489350410e5d5b44774cceda2a94411c21
5
5
  SHA512:
6
- metadata.gz: c098cbcad5c133655d05693bcbbbd4bdbc59118ae5334cb6f81fe196aa66aab6b67490b54887d467e7615847250ccf77b2d5f773c5f2f8b4c47905c18d898ba3
7
- data.tar.gz: 690a4aa38f1b0955d9bb448e45896e3034eb4c6422aa57d177e6a6eb76148cf10d7d87c45bc6e37b79db27f68c090e3d64ab9aef02082ebf4158d941c63c32f0
6
+ metadata.gz: ae082cfc52d681f89aa1afc5454b3a16ae5987eeb6bb0ea7f1c0e7338bf0bd17def10978e3956b17216f4e1de48aa6c93e176441a4dbb5184119d71f2cc33398
7
+ data.tar.gz: ddada7e2bf3e2ea9430384d615e25307342106c1094780130b49ab483e1fdc1727a65faf5d3df5df06661f12ef618c5bce21ceba23881258ccc0cf34ec4f7358
@@ -0,0 +1,120 @@
1
+ # Change log
2
+
3
+ ## [v0.9.0] - 2018-12-01
4
+
5
+ ### Changed
6
+ * Change tty-cursor dependency
7
+ * Change to Ruby >= 2.0
8
+ * Change to freeze all string literals
9
+ * Change #execute_job to stop evaluating in spinner context and just execute the job
10
+ * Change #register to accept a spinner instance by Shane Cavanaugh(@shanecav84)
11
+
12
+ ### Fixed
13
+ * Fix to remove a stray single quote in spin_4 by Kristofer Rye(@rye)
14
+ * Fix Multi#line_inset to correctly assign styling in threaded environment
15
+ * Fix #stop & #auto_spin to always restore hidden cursor if enabled
16
+ * Fix deadlock when registering multi spinners
17
+
18
+ ## [v0.8.0] - 2018-01-11
19
+
20
+ ### Added
21
+ * Add new formats :bounce, :burger, :dance, :dot_2, ..., dot_11, :shark, :pong
22
+
23
+ ### Changed
24
+ * Change to only output to a console and stop output to a file, pipe etc...
25
+
26
+ ### Fixed
27
+ * Fix spinner #stop to clear line before printing final message
28
+
29
+ ## [v0.7.0] - 2017-09-11
30
+
31
+ ### Added
32
+ * Add :spin event type and emit from TTY::Spinner#spin
33
+
34
+ ### Changed
35
+ * Change to automatically spin top level multi spinner when registered spinners spin
36
+ * Remove unnecessary checks for top spinner in multi spinner #stop, #success, #error
37
+
38
+ ### Fixed
39
+ * Fix multi spinner #observe to only listen for events from registered spinners
40
+
41
+ ## [v0.6.0] - 2017-09-07
42
+
43
+ ### Changed
44
+ * Change TTY::Spinner::Multi to render registerd spinners at row
45
+ position at point of redering and not registration
46
+
47
+ ### Fixed
48
+ * Fix handling of multi spinner events
49
+ * Fix multi spinner display for unicode inset characters
50
+
51
+ ## [v0.5.0] - 2017-08-09
52
+
53
+ ### Added
54
+ * Add TTY::Spinner::Multi to allow for parallel spinners executation by Austin Blatt[@austb]
55
+ * Add formatting for multi spinner display by Austin Blatt[@austb]
56
+ * Add ability to add and execute jobs for single and multi spinners
57
+ * Add abilty to register multi spinners with async jobs
58
+ * Add #pause and #resume for single and multispinner
59
+
60
+ ### Changed
61
+ * Change to unify success category to mark spinner as succeded or errored
62
+ * Change Spinner to be thread safe
63
+
64
+ ### Fixed
65
+ * Stop firing events when a spinner is stopped
66
+
67
+ ## [v0.4.1] - 2016-08-07
68
+
69
+ ### Changed
70
+ * Change #update to clear output when in spinning state
71
+
72
+ ## [v0.4.0] - 2016-08-07
73
+
74
+ ### Added
75
+ * Add #auto_spin to automatically displaying spinning animation
76
+
77
+ ### Changed
78
+ * Change #start to setup timer and reset done state
79
+
80
+ ## [v0.3.0] - 2016-07-14
81
+
82
+ ### Added
83
+ * Add #run to automatically execute job with spinning animation by @Thermatix
84
+ * Add #update to allow for dynamic label name replacement
85
+
86
+ ### Fixed
87
+ * Fixed cursor hiding for success and error calls by @m-o-e
88
+ * Fix #join call to define actual error
89
+ * Fix #stop to print only once when finished
90
+
91
+ ## [v0.2.0] - 2016-03-13
92
+
93
+ ### Added
94
+ * Add new spinner formats by @rlqualls
95
+ * Add ability to specify custom frames through :frames option
96
+ * Add :clear option for removing spinner output when done
97
+ * Add #success and #error calls for stopping spinner
98
+ * Add :done, :success, :error completion events
99
+ * Add :success_mark & :error_mark to allow changing markers
100
+ * Add :interval for automatic spinning duration
101
+ * Add #start, #join and #kill for automatic spinner animation
102
+
103
+ ### Changed
104
+ * Change message formatting, use :spinner token to customize message
105
+ * Change format for definining spinner formats and intervals
106
+
107
+ ## [v0.1.0] - 2014-11-15
108
+
109
+ * Initial implementation and release
110
+
111
+ [v0.9.0]: https://github.com/piotrmurach/tty-spinner/compare/v0.8.0...v0.9.0
112
+ [v0.8.0]: https://github.com/piotrmurach/tty-spinner/compare/v0.7.0...v0.8.0
113
+ [v0.7.0]: https://github.com/piotrmurach/tty-spinner/compare/v0.6.0...v0.7.0
114
+ [v0.6.0]: https://github.com/piotrmurach/tty-spinner/compare/v0.5.0...v0.6.0
115
+ [v0.5.0]: https://github.com/piotrmurach/tty-spinner/compare/v0.4.1...v0.5.0
116
+ [v0.4.1]: https://github.com/piotrmurach/tty-spinner/compare/v0.4.0...v0.4.1
117
+ [v0.4.0]: https://github.com/piotrmurach/tty-spinner/compare/v0.3.0...v0.4.0
118
+ [v0.3.0]: https://github.com/piotrmurach/tty-spinner/compare/v0.2.0...v0.3.0
119
+ [v0.2.0]: https://github.com/piotrmurach/tty-spinner/compare/v0.1.0...v0.2.0
120
+ [v0.1.0]: https://github.com/piotrmurach/tty-spinner/compare/v0.1.0
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <div align="center">
2
+ <a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://cdn.rawgit.com/piotrmurach/tty/master/images/tty.png" alt="tty logo" /></a>
3
+ </div>
4
+
1
5
  # TTY::Spinner [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
2
6
 
3
7
  [![Gem Version](https://badge.fury.io/rb/tty-spinner.svg)][gem]
@@ -78,7 +82,7 @@ Or install it yourself as:
78
82
 
79
83
  ## 1. Usage
80
84
 
81
- **TTY::Spinner** by default uses `:classic` type of formatter and requires no paramters:
85
+ **TTY::Spinner** by default uses `:classic` type of formatter and requires no parameters:
82
86
 
83
87
  ```ruby
84
88
  spinner = TTY::Spinner.new
@@ -108,12 +112,13 @@ and when finished output:
108
112
  _ Loading ... Done!
109
113
  ```
110
114
 
111
- Use **TTY::Spinner::Multi** to synchornize multiple spinners:
115
+ Use **TTY::Spinner::Multi** to synchronize multiple spinners:
112
116
 
113
117
  ```ruby
114
118
  spinners = TTY::Spinner::Multi.new("[:spinner] top")
115
119
 
116
120
  sp1 = spinners.register "[:spinner] one"
121
+ # or sp1 = ::TTY::Spinner.new("[:spinner] one")
117
122
  sp2 = spinners.register "[:spinner] two"
118
123
 
119
124
  sp1.auto_spin
@@ -177,10 +182,20 @@ spinner.resume
177
182
 
178
183
  ### 2.3 run
179
184
 
180
- Use `run` with a code block that will automatically display spinning animation while the block executes and finish animation when the block terminates. Optionally you can provide a stop message to display when animation is finished.
185
+ Use `run` passing a block with a job that will automatically display spinning animation while the block executes and finish animation when the block terminates. The block yields a spinner instance.
181
186
 
182
187
  ```ruby
183
- spinner.run('Done!') { ... }
188
+ spinner.run do |spinner|
189
+ ...
190
+ end
191
+ ```
192
+
193
+ Optionally you can provide a stop message to display when animation is finished.
194
+
195
+ ```ruby
196
+ spinner.run('Done!') do |spinner|
197
+ ...
198
+ end
184
199
  ```
185
200
 
186
201
  ### 2.4 start
@@ -207,7 +222,7 @@ spinner.stop('Done!')
207
222
 
208
223
  #### 2.5.1 success
209
224
 
210
- Use `success` call to stop the spinning animation and replace the spinning symbol with checkmark character to indicate successful completion.
225
+ Use `success` call to stop the spinning animation and replace the spinning symbol with check mark character to indicate successful completion.
211
226
 
212
227
  ```ruby
213
228
  spinner = TTY::Spinner.new("[:spinner] Task name")
@@ -222,7 +237,7 @@ This will produce:
222
237
 
223
238
  #### 2.5.2 error
224
239
 
225
- Use `error` call to stop the spining animation and replace the spinning symbol with cross character to indicate error completion.
240
+ Use `error` call to stop the spinning animation and replace the spinning symbol with cross character to indicate error completion.
226
241
 
227
242
  ```ruby
228
243
  spinner = TTY::Spinner.new("[:spinner] Task name")
@@ -403,6 +418,9 @@ Create and register a `TTY::Spinner` under the multispinner
403
418
 
404
419
  ```ruby
405
420
  new_spinner = multi_spinner.register("[:spinner] Task 1 name", options)
421
+ # or
422
+ # spinner = ::TTY::Spinner.new("[:spinner] one")
423
+ # sp1 = multi_spinner.register(spinner)
406
424
  ```
407
425
 
408
426
  If no options are given it will use the options given to the multi_spinner when it was initialized to create the new spinner.
@@ -448,7 +466,7 @@ spinner_1.auto_spin
448
466
  spinner_2.auto_spin
449
467
  ```
450
468
 
451
- Finnally, you need to stop each spinner manually, in our case we mark the second spinner as failure which in turn will stop the top level multi spinner automatically and mark it as failure:
469
+ Finally, you need to stop each spinner manually, in our case we mark the second spinner as failure which in turn will stop the top level multi spinner automatically and mark it as failure:
452
470
 
453
471
  ```ruby
454
472
  spinner_1.success
@@ -498,7 +516,7 @@ multi_spinner.stop
498
516
 
499
517
  #### 5.3.1 success
500
518
 
501
- Use `success` call to stop the spinning animation and replace the spinning symbol with checkmark character to indicate successful completion.
519
+ Use `success` call to stop the spinning animation and replace the spinning symbol with a check mark character to indicate successful completion.
502
520
  This will also call `#success` on any sub-spinners that are still spinning.
503
521
 
504
522
  ```ruby
@@ -507,7 +525,7 @@ multi_spinner.success
507
525
 
508
526
  #### 5.3.2 error
509
527
 
510
- Use `error` call to stop the spining animation and replace the spinning symbol with cross character to indicate error completion.
528
+ Use `error` call to stop the spinning animation and replace the spinning symbol with cross character to indicate error completion.
511
529
  This will also call `#error` on any sub-spinners that are still spinning.
512
530
 
513
531
  ```ruby
@@ -536,4 +554,4 @@ multi_spinner = TTY::Spinner::Multi.new("[:spinner] parent", style: {
536
554
 
537
555
  ## Copyright
538
556
 
539
- Copyright (c) 2014-2018 Piotr Murach. See LICENSE for further details.
557
+ Copyright (c) 2014 Piotr Murach. See LICENSE for further details.
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ FileList['tasks/**/*.rake'].each(&method(:import))
6
+
7
+ desc 'Run all specs'
8
+ task ci: %w[ spec ]
@@ -0,0 +1,8 @@
1
+ require_relative '../lib/tty-spinner'
2
+
3
+ spinner = TTY::Spinner.new("Loading :spinner ...", format: :bouncing_ball)
4
+ spinner.auto_spin
5
+
6
+ sleep 1 # Some long task
7
+
8
+ spinner.stop('done')
@@ -0,0 +1,8 @@
1
+ require_relative '../lib/tty-spinner'
2
+
3
+ spinner = TTY::Spinner.new("Loading :spinner ... ", format: :spin_2)
4
+ 20.times do
5
+ spinner.spin
6
+ sleep(0.1)
7
+ end
8
+ spinner.stop('done')
@@ -0,0 +1,9 @@
1
+ require_relative '../lib/tty-spinner'
2
+
3
+ spinner = TTY::Spinner.new("[:spinner] Task name", format: :bouncing_ball)
4
+ 20.times do
5
+ spinner.spin
6
+ sleep(0.1)
7
+ end
8
+
9
+ spinner.success
@@ -0,0 +1,12 @@
1
+ require 'pastel'
2
+ require_relative '../lib/tty-spinner'
3
+
4
+ pastel = Pastel.new
5
+
6
+ format = "[#{pastel.yellow(':spinner')}] " + pastel.yellow("Task name")
7
+ spinner = TTY::Spinner.new(format, success_mark: pastel.green('+'))
8
+ 20.times do
9
+ spinner.spin
10
+ sleep(0.1)
11
+ end
12
+ spinner.success(pastel.green("(successful)"))
@@ -0,0 +1,9 @@
1
+ require_relative '../lib/tty-spinner'
2
+
3
+ spinner = TTY::Spinner.new("[:spinner] Task name")
4
+ 20.times do
5
+ spinner.spin
6
+ sleep(0.1)
7
+ end
8
+
9
+ spinner.error('(error)')
@@ -0,0 +1,11 @@
1
+ require_relative '../lib/tty-spinner'
2
+
3
+ TTY::Formats::FORMATS.keys.each do |token|
4
+ options = {format: token, hide_cursor: true}
5
+ spinner = TTY::Spinner.new("#{token}: :spinner", options)
6
+ 20.times do
7
+ spinner.spin
8
+ sleep(0.1)
9
+ end
10
+ spinner.stop
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'pastel'
2
+ require_relative '../lib/tty-spinner'
3
+
4
+ pastel = Pastel.new
5
+
6
+ format = "[#{pastel.yellow(':spinner')}] " + pastel.yellow("Task name")
7
+ spinner = TTY::Spinner.new(format, success_mark: pastel.green('+'), hide_cursor: true)
8
+ 10.times do
9
+ spinner.spin
10
+ sleep(0.1)
11
+ end
12
+ spinner.success(pastel.green("(successful)"))
@@ -0,0 +1,13 @@
1
+ require_relative '../../lib/tty-spinner'
2
+
3
+ spinners = TTY::Spinner::Multi.new
4
+
5
+ sp1 = spinners.register "[:spinner] one"
6
+ sp2 = spinners.register "[:spinner] two"
7
+ sp3 = spinners.register "[:spinner] three"
8
+
9
+ th1 = Thread.new { 20.times { sleep(0.2); sp1.spin }}
10
+ th2 = Thread.new { 30.times { sleep(0.1); sp2.spin }}
11
+ th3 = Thread.new { 10.times { sleep(0.3); sp3.spin }}
12
+
13
+ [th1, th2, th3].each(&:join)
@@ -0,0 +1,13 @@
1
+ require_relative '../../lib/tty-spinner'
2
+
3
+ spinners = TTY::Spinner::Multi.new "[:spinner] main", format: :pulse
4
+
5
+ sp1 = spinners.register "[:spinner] one", format: :classic
6
+ sp2 = spinners.register "[:spinner] two", format: :classic
7
+ sp3 = spinners.register "[:spinner] three", format: :classic
8
+
9
+ th1 = Thread.new { 20.times { sleep(0.2); sp1.spin }}
10
+ th2 = Thread.new { 30.times { sleep(0.1); sp2.spin }}
11
+ th3 = Thread.new { 10.times { sleep(0.3); sp3.spin }}
12
+
13
+ [th1, th2, th3].each(&:join)
@@ -0,0 +1,26 @@
1
+ require_relative '../../lib/tty-spinner'
2
+
3
+ opts = {
4
+ style: {
5
+ top: ". ",
6
+ middle: "|-> ",
7
+ bottom: "|__ ",
8
+ },
9
+ format: :bouncing_ball
10
+ }
11
+ spinners = TTY::Spinner::Multi.new("[:spinner] Top level spinner", opts)
12
+
13
+ sp1 = spinners.register "[:spinner] one"
14
+ sp2 = spinners.register "[:spinner] two"
15
+ sp3 = spinners.register "[:spinner] three"
16
+
17
+ sp1.auto_spin
18
+ sp2.auto_spin
19
+ sp3.auto_spin
20
+
21
+ sleep(2)
22
+ sp1.success
23
+ sleep 1
24
+ sp2.success
25
+ sleep 1
26
+ sp3.error
@@ -0,0 +1,14 @@
1
+ require 'pastel'
2
+ require_relative '../../lib/tty-spinner'
3
+
4
+ pastel = Pastel.new
5
+ spinners = TTY::Spinner::Multi.new("[:spinner] Downloading files...")
6
+
7
+ ['file1', 'file2', 'file3'].each do |file|
8
+ spinners.register("[:spinner] #{file}") do |sp|
9
+ sleep(rand * 5)
10
+ sp.success(pastel.green("success"))
11
+ end
12
+ end
13
+
14
+ spinners.auto_spin
@@ -0,0 +1,10 @@
1
+ require_relative '../../lib/tty-spinner'
2
+
3
+ spinners = TTY::Spinner::Multi.new("[:spinner] top")
4
+
5
+ spinners.register("[:spinner] one") { |sp| sleep(2); sp.success('yes 2') }
6
+ spinners.register("[:spinner] two") { |sp| sleep(3); sp.error('no 2') }
7
+ spinners.register("[:spinner] three") { |sp| sleep(1); sp.success('yes 3') }
8
+
9
+ spinners.auto_spin
10
+
@@ -0,0 +1,17 @@
1
+ require_relative '../../lib/tty-spinner'
2
+
3
+ spinners = TTY::Spinner::Multi.new
4
+
5
+ sp1 = spinners.register "[:spinner] one"
6
+ sp2 = spinners.register "[:spinner] two"
7
+ sp3 = spinners.register "[:spinner] three"
8
+
9
+ sp1.auto_spin
10
+ sp2.auto_spin
11
+ sp3.auto_spin
12
+
13
+ sleep(2)
14
+
15
+ sp1.stop
16
+ sp2.stop
17
+ sp3.stop
@@ -0,0 +1,18 @@
1
+ require_relative '../../lib/tty-spinner'
2
+
3
+ spinners = TTY::Spinner::Multi.new("[:spinner] Top level spinner")
4
+
5
+ sp1 = spinners.register "[:spinner] one"
6
+ sp2 = spinners.register "[:spinner] two"
7
+ sp3 = spinners.register "[:spinner] three"
8
+
9
+ sp1.auto_spin
10
+ sp2.auto_spin
11
+ sp3.auto_spin
12
+
13
+ sleep(2)
14
+ sp1.success
15
+ sleep 1
16
+ sp2.success
17
+ sleep 1
18
+ sp3.error