tty-spinner 0.9.2 → 0.9.3

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -3
  3. data/lib/tty/spinner/version.rb +1 -1
  4. metadata +16 -102
  5. data/Rakefile +0 -8
  6. data/examples/auto_spin.rb +0 -8
  7. data/examples/basic.rb +0 -8
  8. data/examples/clear.rb +0 -9
  9. data/examples/color.rb +0 -12
  10. data/examples/error.rb +0 -9
  11. data/examples/formats.rb +0 -11
  12. data/examples/hide_cursor.rb +0 -12
  13. data/examples/multi/basic.rb +0 -13
  14. data/examples/multi/basic_top_level.rb +0 -13
  15. data/examples/multi/custom_style.rb +0 -26
  16. data/examples/multi/files.rb +0 -14
  17. data/examples/multi/jobs.rb +0 -10
  18. data/examples/multi/multi.rb +0 -17
  19. data/examples/multi/multi_top_level.rb +0 -18
  20. data/examples/multi/pause.rb +0 -26
  21. data/examples/multi/threaded.rb +0 -30
  22. data/examples/pause.rb +0 -19
  23. data/examples/run.rb +0 -18
  24. data/examples/success.rb +0 -9
  25. data/examples/threaded.rb +0 -11
  26. data/examples/update.rb +0 -11
  27. data/spec/spec_helper.rb +0 -51
  28. data/spec/unit/auto_spin_spec.rb +0 -27
  29. data/spec/unit/clear_spec.rb +0 -18
  30. data/spec/unit/error_spec.rb +0 -46
  31. data/spec/unit/events_spec.rb +0 -37
  32. data/spec/unit/formats_spec.rb +0 -9
  33. data/spec/unit/frames_spec.rb +0 -33
  34. data/spec/unit/hide_cursor_spec.rb +0 -53
  35. data/spec/unit/job_spec.rb +0 -14
  36. data/spec/unit/join_spec.rb +0 -12
  37. data/spec/unit/multi/auto_spin_spec.rb +0 -34
  38. data/spec/unit/multi/error_spec.rb +0 -109
  39. data/spec/unit/multi/line_inset_spec.rb +0 -59
  40. data/spec/unit/multi/on_spec.rb +0 -13
  41. data/spec/unit/multi/register_spec.rb +0 -47
  42. data/spec/unit/multi/spin_spec.rb +0 -103
  43. data/spec/unit/multi/stop_spec.rb +0 -97
  44. data/spec/unit/multi/success_spec.rb +0 -110
  45. data/spec/unit/new_spec.rb +0 -26
  46. data/spec/unit/pause_spec.rb +0 -25
  47. data/spec/unit/reset_spec.rb +0 -21
  48. data/spec/unit/run_spec.rb +0 -32
  49. data/spec/unit/spin_spec.rb +0 -119
  50. data/spec/unit/stop_spec.rb +0 -64
  51. data/spec/unit/success_spec.rb +0 -46
  52. data/spec/unit/update_spec.rb +0 -87
  53. data/tasks/console.rake +0 -11
  54. data/tasks/coverage.rake +0 -11
  55. data/tasks/spec.rake +0 -29
  56. data/tty-spinner.gemspec +0 -27
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
-
3
- RSpec.describe TTY::Spinner, '#new' do
4
-
5
- it "creates spinner with default format" do
6
- spinner = TTY::Spinner.new
7
- expect(spinner.format).to eq(:classic)
8
- end
9
-
10
- it "doesn't accept unknown formatting tokens" do
11
- expect {
12
- TTY::Spinner.new(format: :unknown)
13
- }.to raise_error(ArgumentError, /Unknown format token `:unknown`/)
14
- end
15
-
16
- it "creates spinner with custom format" do
17
- spinner = TTY::Spinner.new("Initializing... :spinner ")
18
- expect(spinner.message).to eq("Initializing... :spinner ")
19
- end
20
-
21
- it "allows to set default output" do
22
- output = $stdout
23
- spinner = TTY::Spinner.new(output: output)
24
- expect(spinner.output).to eq(output)
25
- end
26
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Spinner, '#pause' do
4
- let(:output) { StringIO.new('', 'w+') }
5
-
6
- it "allows to pause auto spinning" do
7
- spinner = TTY::Spinner.new(output: output, interval: 100)
8
- allow(spinner).to receive(:spin)
9
-
10
- spinner.auto_spin
11
- expect(spinner.paused?).to eq(false)
12
-
13
- sleep(0.02)
14
-
15
- spinner.pause
16
- expect(spinner.paused?).to eq(true)
17
-
18
- spinner.resume
19
- expect(spinner.paused?).to eq(true)
20
-
21
- spinner.stop
22
-
23
- expect(spinner).to have_received(:spin).at_least(1)
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- # coding: utf-8
2
-
3
- RSpec.describe TTY::Spinner, '#reset' do
4
- let(:output) { StringIO.new('', 'w+') }
5
-
6
- it "spins default frames" do
7
- spinner = TTY::Spinner.new(output: output)
8
- 5.times do |n|
9
- spinner.spin
10
- spinner.reset if n == 2
11
- end
12
- output.rewind
13
- expect(output.read).to eq([
14
- "\e[1G|",
15
- "\e[1G/",
16
- "\e[1G-",
17
- "\e[1G|",
18
- "\e[1G/"
19
- ].join)
20
- end
21
- end
@@ -1,32 +0,0 @@
1
- # coding: utf-8
2
-
3
- RSpec.describe TTY::Spinner, '#run' do
4
- let(:output) { StringIO.new('', 'w+') }
5
-
6
- it "runs animation while executing block" do
7
- spinner = TTY::Spinner.new(output: output, interval: 100)
8
- allow(spinner).to receive(:spin)
9
- spinner.run("done") { sleep(0.1) }
10
- expect(spinner).to have_received(:spin).at_least(5).times
11
- end
12
-
13
- it "runs animation and executes block within context" do
14
- context = spy('context')
15
- spinner = TTY::Spinner.new(":title", output: output)
16
-
17
- spinner.run("done") do
18
- context.call
19
- spinner.update(title: 'executing')
20
- end
21
-
22
- expect(context).to have_received(:call).once
23
- end
24
-
25
- it "yields spinner instance when block argument is provided" do
26
- spinner = TTY::Spinner.new(":title", output: output)
27
-
28
- expect { |job|
29
- spinner.run("done", &job)
30
- }.to yield_with_args(spinner)
31
- end
32
- end
@@ -1,119 +0,0 @@
1
- # coding: utf-8
2
-
3
- RSpec.describe TTY::Spinner, '#spin' do
4
- let(:output) { StringIO.new('', 'w+') }
5
- let(:save) { TTY::Cursor.save }
6
- let(:restore) { TTY::Cursor.restore }
7
-
8
- it "spins default frames" do
9
- spinner = TTY::Spinner.new(output: output)
10
-
11
- expect(spinner.done?).to eq(false)
12
-
13
- 5.times { spinner.spin }
14
- output.rewind
15
- expect(output.read).to eq([
16
- "\e[1G|",
17
- "\e[1G/",
18
- "\e[1G-",
19
- "\e[1G\\",
20
- "\e[1G|"
21
- ].join)
22
- end
23
-
24
- it "spins chosen frame" do
25
- spinner = TTY::Spinner.new(output: output, format: :spin)
26
- 5.times { spinner.spin }
27
- output.rewind
28
- expect(output.read).to eq([
29
- "\e[1G◴",
30
- "\e[1G◷",
31
- "\e[1G◶",
32
- "\e[1G◵",
33
- "\e[1G◴"
34
- ].join)
35
- end
36
-
37
- it "spins with message" do
38
- spinner = TTY::Spinner.new("Loading ... :spinner", output: output)
39
- 4.times { spinner.spin }
40
- output.rewind
41
- expect(output.read).to eq([
42
- "\e[1GLoading ... |",
43
- "\e[1GLoading ... /",
44
- "\e[1GLoading ... -",
45
- "\e[1GLoading ... \\"
46
- ].join)
47
- end
48
-
49
- context "with the cursor" do
50
- before do
51
- multi_spinner = double("MultiSpinner")
52
- allow(multi_spinner).to receive(:synchronize).and_yield
53
- allow(multi_spinner).to receive(:next_row).and_return(1)
54
- allow(multi_spinner).to receive(:rows).and_return(1)
55
- allow(multi_spinner).to receive(:line_inset).and_return("--- ")
56
-
57
- spinner = TTY::Spinner.new(output: output, hide_cursor: hide_cursor)
58
- spinner.attach_to(multi_spinner)
59
- spinner.spin
60
- spinner.redraw_indent
61
-
62
- output.rewind
63
- end
64
-
65
- context "on" do
66
- let(:hide_cursor) { false }
67
-
68
- it "can spin and redraw indent" do
69
- expect(output.read).to eq([
70
- "\e[1G--- |\n",
71
- save,
72
- "\e[1A",
73
- "--- ",
74
- restore
75
- ].join)
76
- end
77
- end
78
-
79
- context "off" do
80
- let(:hide_cursor) { true }
81
-
82
- it "can spin and redraw indent" do
83
- expect(output.read).to eq([
84
- "--- ",
85
- "\e[?25l\n",
86
- save,
87
- "\e[1A",
88
- "\e[1G",
89
- "--- |",
90
- restore,
91
- save,
92
- "\e[1A",
93
- "--- ",
94
- restore
95
- ].join)
96
- end
97
- end
98
- end
99
-
100
- it "spins with many threads" do
101
- spinner = TTY::Spinner.new(output: output)
102
-
103
- th1 = Thread.new { 3.times { spinner.spin; sleep(0.05) } }
104
- th2 = Thread.new { 4.times { spinner.spin; sleep(0.05) } }
105
-
106
- [th1, th2].each(&:join)
107
-
108
- output.rewind
109
- expect(output.read).to eq([
110
- "\e[1G|",
111
- "\e[1G/",
112
- "\e[1G-",
113
- "\e[1G\\",
114
- "\e[1G|",
115
- "\e[1G/",
116
- "\e[1G-"
117
- ].join)
118
- end
119
- end
@@ -1,64 +0,0 @@
1
- # coding: utf-8
2
-
3
- RSpec.describe TTY::Spinner, '#stop' do
4
- let(:output) { StringIO.new('', 'w+') }
5
-
6
- it "doesn't reprint stop message" do
7
- spinner = TTY::Spinner.new(output: output)
8
- spinner.spin
9
- 3.times { spinner.stop }
10
- output.rewind
11
- expect(output.read).to eq([
12
- "\e[1G|",
13
- "\e[0m\e[2K",
14
- "\e[1G|\n",
15
- ].join)
16
- end
17
-
18
- it "stops after 2 spins" do
19
- spinner = TTY::Spinner.new(output: output)
20
- 5.times do |n|
21
- spinner.spin
22
- spinner.stop if n == 1
23
- end
24
- output.rewind
25
- expect(output.read).to eq([
26
- "\e[1G|",
27
- "\e[1G/",
28
- "\e[0m\e[2K",
29
- "\e[1G/\n"
30
- ].join)
31
- end
32
-
33
- it "stops after 2 spins and prints stop message" do
34
- spinner = TTY::Spinner.new(output: output)
35
- 5.times do |n|
36
- spinner.spin
37
- spinner.stop('Done!') if n == 1
38
- end
39
- output.rewind
40
- expect(output.read).to eq([
41
- "\e[1G|",
42
- "\e[1G/",
43
- "\e[0m\e[2K",
44
- "\e[1G/ Done!\n"
45
- ].join)
46
-
47
- expect(spinner.done?).to eq(true)
48
- end
49
-
50
- it "stops after 2 spins with message and prints stop message" do
51
- spinner = TTY::Spinner.new("Loading ... :spinner", output: output)
52
- 5.times do |n|
53
- spinner.spin
54
- spinner.stop('Done!') if n == 1
55
- end
56
- output.rewind
57
- expect(output.read).to eq([
58
- "\e[1GLoading ... |",
59
- "\e[1GLoading ... /",
60
- "\e[0m\e[2K",
61
- "\e[1GLoading ... / Done!\n"
62
- ].join)
63
- end
64
- end
@@ -1,46 +0,0 @@
1
- # coding: utf-8
2
-
3
- RSpec.describe TTY::Spinner, '#success' do
4
- let(:output) { StringIO.new('', 'w+') }
5
-
6
- it "marks spinner as success" do
7
- spinner = TTY::Spinner.new(output: output)
8
- 3.times { spinner.spin }
9
- spinner.success
10
- output.rewind
11
- expect(output.read).to eq([
12
- "\e[1G|",
13
- "\e[1G/",
14
- "\e[1G-",
15
- "\e[0m\e[2K",
16
- "\e[1G#{TTY::Spinner::TICK}\n"
17
- ].join)
18
-
19
- expect(spinner.success?).to eq(true)
20
- end
21
-
22
- it "marks spinner as success with message" do
23
- spinner = TTY::Spinner.new(output: output)
24
- 3.times { spinner.spin }
25
- spinner.success('Successful')
26
- output.rewind
27
- expect(output.read).to eq([
28
- "\e[1G|",
29
- "\e[1G/",
30
- "\e[1G-",
31
- "\e[0m\e[2K",
32
- "\e[1G#{TTY::Spinner::TICK} Successful\n"
33
- ].join)
34
-
35
- expect(spinner.success?).to be(true)
36
- end
37
-
38
- it "changes success spinner marker" do
39
- spinner = TTY::Spinner.new(success_mark: '*', output: output)
40
- spinner.success('(successful)')
41
- output.rewind
42
- expect(output.read).to eq("\e[0m\e[2K\e[1G* (successful)\n")
43
-
44
- expect(spinner.success?).to be(true)
45
- end
46
- end
@@ -1,87 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Spinner, '#update' do
4
- let(:output) { StringIO.new('', 'w+') }
5
-
6
- it "updates message content with custom token" do
7
- spinner = TTY::Spinner.new(":title :spinner", output: output, interval: 100)
8
- spinner.update(title: 'task')
9
- 5.times { spinner.spin }
10
- spinner.stop('done')
11
- output.rewind
12
- expect(output.read).to eq([
13
- "\e[1Gtask |",
14
- "\e[1Gtask /",
15
- "\e[1Gtask -",
16
- "\e[1Gtask \\",
17
- "\e[1Gtask |",
18
- "\e[0m\e[2K",
19
- "\e[1Gtask | done\n"
20
- ].join)
21
- end
22
-
23
- it "updates message many times before stopping" do
24
- spinner = TTY::Spinner.new(":title :spinner", output: output)
25
-
26
- spinner.update(title: 'task_a')
27
- 2.times { spinner.spin }
28
- spinner.update(title: 'task_b')
29
- 2.times { spinner.spin }
30
- spinner.stop('done')
31
- output.rewind
32
-
33
- expect(output.read).to eq([
34
- "\e[1Gtask_a |",
35
- "\e[1Gtask_a /",
36
- "\e[0m\e[2K\e[1G",
37
- "\e[1Gtask_b -",
38
- "\e[1Gtask_b \\",
39
- "\e[0m\e[2K",
40
- "\e[1Gtask_b \\ done\n"
41
- ].join)
42
- end
43
-
44
- it "updates message after stopping" do
45
- spinner = TTY::Spinner.new(":title :spinner", output: output)
46
-
47
- spinner.update(title: 'task_a')
48
- 2.times { spinner.spin }
49
- spinner.stop('done')
50
-
51
- spinner.start
52
- spinner.update(title: 'task_b')
53
- 2.times { spinner.spin }
54
- spinner.stop('done')
55
-
56
- output.rewind
57
- expect(output.read).to eq([
58
- "\e[1Gtask_a |",
59
- "\e[1Gtask_a /",
60
- "\e[0m\e[2K",
61
- "\e[1Gtask_a / done\n",
62
- "\e[1Gtask_b |",
63
- "\e[1Gtask_b /",
64
- "\e[0m\e[2K",
65
- "\e[1Gtask_b / done\n"
66
- ].join)
67
- end
68
-
69
- it "maintains current tokens" do
70
- spinner = TTY::Spinner.new(":foo :bar", output: output)
71
- expect(spinner.tokens).to eq({})
72
-
73
- spinner.update(foo: 'FOO')
74
- spinner.update(bar: 'BAR')
75
-
76
- expect(spinner.tokens).to include({foo: 'FOO', bar: 'BAR'})
77
- end
78
-
79
- it "updates more than one token" do
80
- spinner = TTY::Spinner.new(":foo :bar", output: output)
81
- expect(spinner.tokens).to eq({})
82
-
83
- spinner.update(foo: 'FOO', bar: 'BAR')
84
-
85
- expect(spinner.tokens).to include({foo: 'FOO', bar: 'BAR'})
86
- end
87
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Load gem inside irb console'
4
- task :console do
5
- require 'irb'
6
- require 'irb/completion'
7
- require_relative '../lib/tty-spinner'
8
- ARGV.clear
9
- IRB.start
10
- end
11
- task :c => :console
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Measure code coverage'
4
- task :coverage do
5
- begin
6
- original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true'
7
- Rake::Task['spec'].invoke
8
- ensure
9
- ENV['COVERAGE'] = original
10
- end
11
- end