planter-cli 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitmodules +3 -0
  4. data/CHANGELOG.md +10 -0
  5. data/README.md +5 -3
  6. data/bin/plant +1 -1
  7. data/docker/Dockerfile +2 -4
  8. data/docker/Dockerfile-2.6 +3 -5
  9. data/docker/Dockerfile-2.7 +2 -4
  10. data/docker/Dockerfile-3.0 +2 -3
  11. data/docker/Dockerfile-3.3 +11 -0
  12. data/docker/sources.list +11 -0
  13. data/lib/planter/filelist.rb +5 -4
  14. data/lib/planter/plant.rb +3 -3
  15. data/lib/planter/prompt.rb +5 -5
  16. data/lib/planter/string.rb +22 -0
  17. data/lib/planter/tag.rb +39 -2
  18. data/lib/planter/version.rb +1 -1
  19. data/lib/planter.rb +30 -17
  20. data/lib/tty-spinner/.editorconfig +9 -0
  21. data/lib/tty-spinner/.github/FUNDING.yml +1 -0
  22. data/lib/tty-spinner/.github/ISSUE_TEMPLATE/BUG_REPORT.md +31 -0
  23. data/lib/tty-spinner/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +23 -0
  24. data/lib/tty-spinner/.github/ISSUE_TEMPLATE/config.yml +5 -0
  25. data/lib/tty-spinner/.github/PULL_REQUEST_TEMPLATE.md +19 -0
  26. data/lib/tty-spinner/.github/workflows/ci.yml +59 -0
  27. data/lib/tty-spinner/.gitignore +14 -0
  28. data/lib/tty-spinner/.rspec +2 -0
  29. data/lib/tty-spinner/.rubocop.yml +78 -0
  30. data/lib/tty-spinner/CHANGELOG.md +151 -0
  31. data/lib/tty-spinner/CODE_OF_CONDUCT.md +132 -0
  32. data/lib/tty-spinner/Gemfile +17 -0
  33. data/lib/tty-spinner/LICENSE.txt +22 -0
  34. data/lib/tty-spinner/README.md +581 -0
  35. data/lib/tty-spinner/Rakefile +10 -0
  36. data/lib/tty-spinner/appveyor.yml +33 -0
  37. data/lib/tty-spinner/bin/console +14 -0
  38. data/lib/tty-spinner/bin/setup +8 -0
  39. data/lib/tty-spinner/demo.gif +0 -0
  40. data/lib/tty-spinner/examples/auto_spin.rb +10 -0
  41. data/lib/tty-spinner/examples/basic.rb +10 -0
  42. data/lib/tty-spinner/examples/clear.rb +11 -0
  43. data/lib/tty-spinner/examples/color.rb +14 -0
  44. data/lib/tty-spinner/examples/error.rb +11 -0
  45. data/lib/tty-spinner/examples/formats.rb +13 -0
  46. data/lib/tty-spinner/examples/hide_cursor.rb +14 -0
  47. data/lib/tty-spinner/examples/log.rb +13 -0
  48. data/lib/tty-spinner/examples/multi/basic.rb +15 -0
  49. data/lib/tty-spinner/examples/multi/basic_top_level.rb +15 -0
  50. data/lib/tty-spinner/examples/multi/custom_style.rb +28 -0
  51. data/lib/tty-spinner/examples/multi/files.rb +16 -0
  52. data/lib/tty-spinner/examples/multi/jobs.rb +11 -0
  53. data/lib/tty-spinner/examples/multi/multi.rb +19 -0
  54. data/lib/tty-spinner/examples/multi/multi_top_level.rb +20 -0
  55. data/lib/tty-spinner/examples/multi/pause.rb +28 -0
  56. data/lib/tty-spinner/examples/multi/threaded.rb +30 -0
  57. data/lib/tty-spinner/examples/pause.rb +24 -0
  58. data/lib/tty-spinner/examples/run.rb +20 -0
  59. data/lib/tty-spinner/examples/success.rb +11 -0
  60. data/lib/tty-spinner/examples/threaded.rb +13 -0
  61. data/lib/tty-spinner/examples/update.rb +13 -0
  62. data/lib/tty-spinner/lib/tty/spinner/formats.rb +274 -0
  63. data/lib/tty-spinner/lib/tty/spinner/multi.rb +352 -0
  64. data/lib/tty-spinner/lib/tty/spinner/version.rb +7 -0
  65. data/lib/tty-spinner/lib/tty/spinner.rb +604 -0
  66. data/lib/tty-spinner/lib/tty-spinner.rb +2 -0
  67. data/lib/tty-spinner/spec/spec_helper.rb +52 -0
  68. data/lib/tty-spinner/spec/unit/auto_spin_spec.rb +25 -0
  69. data/lib/tty-spinner/spec/unit/clear_spec.rb +16 -0
  70. data/lib/tty-spinner/spec/unit/error_spec.rb +53 -0
  71. data/lib/tty-spinner/spec/unit/events_spec.rb +35 -0
  72. data/lib/tty-spinner/spec/unit/formats_spec.rb +9 -0
  73. data/lib/tty-spinner/spec/unit/frames_spec.rb +31 -0
  74. data/lib/tty-spinner/spec/unit/hide_cursor_spec.rb +51 -0
  75. data/lib/tty-spinner/spec/unit/job_spec.rb +12 -0
  76. data/lib/tty-spinner/spec/unit/join_spec.rb +10 -0
  77. data/lib/tty-spinner/spec/unit/log_spec.rb +60 -0
  78. data/lib/tty-spinner/spec/unit/multi/auto_spin_spec.rb +32 -0
  79. data/lib/tty-spinner/spec/unit/multi/error_spec.rb +107 -0
  80. data/lib/tty-spinner/spec/unit/multi/line_inset_spec.rb +57 -0
  81. data/lib/tty-spinner/spec/unit/multi/on_spec.rb +11 -0
  82. data/lib/tty-spinner/spec/unit/multi/register_spec.rb +46 -0
  83. data/lib/tty-spinner/spec/unit/multi/spin_spec.rb +101 -0
  84. data/lib/tty-spinner/spec/unit/multi/stop_spec.rb +95 -0
  85. data/lib/tty-spinner/spec/unit/multi/success_spec.rb +108 -0
  86. data/lib/tty-spinner/spec/unit/new_spec.rb +25 -0
  87. data/lib/tty-spinner/spec/unit/pause_spec.rb +43 -0
  88. data/lib/tty-spinner/spec/unit/reset_spec.rb +19 -0
  89. data/lib/tty-spinner/spec/unit/run_spec.rb +30 -0
  90. data/lib/tty-spinner/spec/unit/spin_spec.rb +117 -0
  91. data/lib/tty-spinner/spec/unit/stop_spec.rb +88 -0
  92. data/lib/tty-spinner/spec/unit/success_spec.rb +53 -0
  93. data/lib/tty-spinner/spec/unit/tty_spec.rb +8 -0
  94. data/lib/tty-spinner/spec/unit/update_spec.rb +85 -0
  95. data/lib/tty-spinner/tasks/console.rake +11 -0
  96. data/lib/tty-spinner/tasks/coverage.rake +11 -0
  97. data/lib/tty-spinner/tasks/spec.rake +29 -0
  98. data/lib/tty-spinner/tty-spinner.gemspec +36 -0
  99. data/scripts/runtests.sh +1 -1
  100. data/spec/cli_spec.rb +27 -0
  101. data/spec/spec_helper.rb +26 -0
  102. data/spec/templates/test/_planter.yml +3 -6
  103. data/src/_README.md +5 -3
  104. metadata +86 -2
@@ -0,0 +1,95 @@
1
+ RSpec.describe TTY::Spinner::Multi, "#stop" do
2
+ let(:output) { StringIO.new("", "w+") }
3
+
4
+ it "stops unregisterd multi spinner and emits a :done message" do
5
+ spinners = TTY::Spinner::Multi.new(output: output)
6
+ callbacks = []
7
+ sp1 = spinners.register "[:spinner] one"
8
+ sp2 = spinners.register "[:spinner] two"
9
+
10
+ expect(sp1.done?).to eq(false)
11
+ expect(sp2.done?).to eq(false)
12
+
13
+ spinners.on(:error) { callbacks << :error }
14
+ .on(:done) { callbacks << :done }
15
+ .on(:success) { callbacks << :success }
16
+
17
+ spinners.stop
18
+
19
+ expect(sp1.done?).to eq(true)
20
+ expect(sp2.done?).to eq(true)
21
+ expect(callbacks).to eq([:done])
22
+ end
23
+
24
+ it "stops registerd multi spinner and emits a :done message" do
25
+ spinners = TTY::Spinner::Multi.new(":spinner", output: output)
26
+ callbacks = []
27
+ sp1 = spinners.register "[:spinner] one"
28
+ sp2 = spinners.register "[:spinner] two"
29
+
30
+ expect(sp1.done?).to eq(false)
31
+ expect(sp2.done?).to eq(false)
32
+
33
+ spinners.on(:error) { callbacks << :error }
34
+ .on(:done) { callbacks << :done }
35
+ .on(:success) { callbacks << :success }
36
+
37
+ spinners.stop
38
+
39
+ expect(sp1.done?).to eq(true)
40
+ expect(sp2.done?).to eq(true)
41
+ expect(callbacks).to eq([:done])
42
+ end
43
+
44
+ it "stops all registered spinners and emits a :done message" do
45
+ spinners = TTY::Spinner::Multi.new(output: output)
46
+ callbacks = []
47
+ sp1 = spinners.register "[:spinner] one"
48
+ sp2 = spinners.register "[:spinner] two"
49
+
50
+ expect(sp1.done?).to eq(false)
51
+ expect(sp2.done?).to eq(false)
52
+
53
+ spinners.on(:error) { callbacks << :error }
54
+ .on(:done) { callbacks << :done }
55
+ .on(:success) { callbacks << :success }
56
+
57
+ sp1.stop
58
+ sp2.stop
59
+
60
+ expect(spinners.done?).to eq(true)
61
+ expect(callbacks).to eq([:done])
62
+ end
63
+
64
+ it "stops all registered spinners under multispinner and emits a :done message" do
65
+ spinners = TTY::Spinner::Multi.new(":spinner", output: output)
66
+ callbacks = []
67
+ sp1 = spinners.register "[:spinner] one"
68
+ sp2 = spinners.register "[:spinner] two"
69
+
70
+ expect(sp1.done?).to eq(false)
71
+ expect(sp2.done?).to eq(false)
72
+
73
+ spinners.on(:error) { callbacks << :error }
74
+ .on(:done) { callbacks << :done }
75
+ .on(:success) { callbacks << :success }
76
+
77
+ sp1.stop
78
+ sp2.stop
79
+
80
+ expect(spinners.done?).to eq(true)
81
+ expect(callbacks).to eq([:done])
82
+ end
83
+
84
+ it "returns true when spinner is done" do
85
+ spinners = TTY::Spinner::Multi.new(output: output)
86
+
87
+ sp1 = spinners.register "[:spinner] one"
88
+ sp2 = spinners.register "[:spinner] two"
89
+
90
+ sp1.stop
91
+ sp2.error
92
+
93
+ expect(spinners.done?).to eq(true)
94
+ end
95
+ end
@@ -0,0 +1,108 @@
1
+ RSpec.describe TTY::Spinner::Multi, "#success" do
2
+ let(:output) { StringIO.new("", "w+") }
3
+
4
+ it "stops registerd multi spinner and emits a :success message" do
5
+ spinners = TTY::Spinner::Multi.new(":spinner", output: output)
6
+ callbacks = []
7
+ sp1 = spinners.register "[:spinner] one"
8
+ sp2 = spinners.register "[:spinner] two"
9
+
10
+ expect(sp1.success?).to eq(false)
11
+ expect(sp2.success?).to eq(false)
12
+
13
+ spinners.on(:error) { callbacks << :error }
14
+ .on(:done) { callbacks << :done }
15
+ .on(:success) { callbacks << :success }
16
+
17
+ spinners.success
18
+
19
+ expect(sp1.success?).to eq(true)
20
+ expect(sp2.success?).to eq(true)
21
+ expect(callbacks).to match_array(%i[success done])
22
+ end
23
+
24
+ it "stops unregistered multi spinner and emits a :success message" do
25
+ spinners = TTY::Spinner::Multi.new(output: output)
26
+ callbacks = []
27
+ sp1 = spinners.register "[:spinner] one"
28
+ sp2 = spinners.register "[:spinner] two"
29
+
30
+ expect(sp1.success?).to eq(false)
31
+ expect(sp2.success?).to eq(false)
32
+
33
+ spinners.on(:error) { callbacks << :error }
34
+ .on(:done) { callbacks << :done }
35
+ .on(:success) { callbacks << :success }
36
+
37
+ spinners.success
38
+
39
+ expect(sp1.success?).to eq(true)
40
+ expect(sp2.success?).to eq(true)
41
+ expect(callbacks).to match_array(%i[success done])
42
+ end
43
+
44
+ it "stops all registered spinners under top level and emits a :success message" do
45
+ spinners = TTY::Spinner::Multi.new(":spinner", output: output)
46
+ callbacks = []
47
+ sp1 = spinners.register "[:spinner] one"
48
+ sp2 = spinners.register "[:spinner] two"
49
+
50
+ expect(sp1.success?).to eq(false)
51
+ expect(sp2.success?).to eq(false)
52
+
53
+ spinners.on(:error) { callbacks << :error }
54
+ .on(:done) { callbacks << :done }
55
+ .on(:success) { callbacks << :success }
56
+
57
+ sp1.success
58
+ sp2.success
59
+
60
+ expect(spinners.success?).to eq(true)
61
+ expect(callbacks).to match_array(%i[success done])
62
+ end
63
+
64
+ it "stops all registered spinners and emits a success message" do
65
+ spinners = TTY::Spinner::Multi.new(output: output)
66
+ callbacks = []
67
+ sp1 = spinners.register "[:spinner] one"
68
+ sp2 = spinners.register "[:spinner] two"
69
+
70
+ expect(sp1.success?).to eq(false)
71
+ expect(sp2.success?).to eq(false)
72
+
73
+ spinners.on(:error) { callbacks << :error }
74
+ .on(:done) { callbacks << :done }
75
+ .on(:success) { callbacks << :success }
76
+
77
+ sp1.success
78
+ sp2.success
79
+
80
+ expect(spinners.success?).to eq(true)
81
+ expect(callbacks).to match_array(%i[success done])
82
+ end
83
+
84
+ it "returns false when a spinner has errored" do
85
+ spinners = TTY::Spinner::Multi.new(output: output)
86
+
87
+ sp1 = spinners.register("")
88
+ sp2 = spinners.register("")
89
+
90
+ sp1.success
91
+ sp2.error
92
+
93
+ expect(spinners.success?).to eq(false)
94
+ end
95
+
96
+ it "updates top spinner success state based on child spinners jobs status" do
97
+ spinners = TTY::Spinner::Multi.new("top", output: output)
98
+
99
+ spinners.register("one") { |sp| sp.success }
100
+ spinners.register("two") { |sp| sp.success }
101
+
102
+ expect(spinners.success?).to eq(false)
103
+
104
+ spinners.auto_spin
105
+
106
+ expect(spinners.success?).to eq(true)
107
+ end
108
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe TTY::Spinner, "#new" do
4
+ it "creates spinner with default format" do
5
+ spinner = TTY::Spinner.new
6
+ expect(spinner.format).to eq(:classic)
7
+ end
8
+
9
+ it "doesn't accept unknown formatting tokens" do
10
+ expect {
11
+ TTY::Spinner.new(format: :unknown)
12
+ }.to raise_error(ArgumentError, /Unknown format token `:unknown`/)
13
+ end
14
+
15
+ it "creates spinner with custom format" do
16
+ spinner = TTY::Spinner.new("Initializing... :spinner ")
17
+ expect(spinner.message).to eq("Initializing... :spinner ")
18
+ end
19
+
20
+ it "allows to set default output" do
21
+ output = $stdout
22
+ spinner = TTY::Spinner.new(output: output)
23
+ expect(spinner.output).to eq(output)
24
+ end
25
+ end
@@ -0,0 +1,43 @@
1
+ RSpec.describe TTY::Spinner, "#pause" do
2
+ let(:output) { StringIO.new("", "w+") }
3
+
4
+ it "allows to pause auto spinning" do
5
+ spinner = TTY::Spinner.new(output: output, interval: 100)
6
+ allow(spinner).to receive(:spin)
7
+
8
+ spinner.auto_spin
9
+ expect(spinner.paused?).to eq(false)
10
+
11
+ sleep(0.02)
12
+
13
+ spinner.pause
14
+ expect(spinner.paused?).to eq(true)
15
+
16
+ spinner.resume
17
+ expect(spinner.paused?).to eq(true)
18
+
19
+ spinner.stop
20
+
21
+ expect(spinner).to have_received(:spin).at_least(1)
22
+ end
23
+
24
+ it "pauses auto-spin with a custom mark" do
25
+ spinner = TTY::Spinner.new("[:spinner]", output: output)
26
+ thread = spy(:thread)
27
+ allow(Thread).to receive(:new).and_return(thread)
28
+ spinner.auto_spin
29
+
30
+ allow(spinner).to receive(:paused?).and_return(false)
31
+ spinner.pause(mark: "?")
32
+ allow(spinner).to receive(:paused?).and_return(true)
33
+ spinner.resume
34
+ spinner.auto_spin
35
+
36
+ output.rewind
37
+ expect(output.read).to eq([
38
+ "\e[1G[|]",
39
+ "\e[1G[?]",
40
+ "\e[1G[|]"
41
+ ].join)
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ RSpec.describe TTY::Spinner, "#reset" do
2
+ let(:output) { StringIO.new("", "w+") }
3
+
4
+ it "spins default frames" do
5
+ spinner = TTY::Spinner.new(output: output)
6
+ 5.times do |n|
7
+ spinner.spin
8
+ spinner.reset if n == 2
9
+ end
10
+ output.rewind
11
+ expect(output.read).to eq([
12
+ "\e[1G|",
13
+ "\e[1G/",
14
+ "\e[1G-",
15
+ "\e[1G|",
16
+ "\e[1G/"
17
+ ].join)
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ RSpec.describe TTY::Spinner, "#run" do
2
+ let(:output) { StringIO.new("", "w+") }
3
+
4
+ it "runs animation while executing block" do
5
+ spinner = TTY::Spinner.new(output: output, interval: 100)
6
+ allow(spinner).to receive(:spin)
7
+ spinner.run("done") { sleep(0.1) }
8
+ expect(spinner).to have_received(:spin).at_least(5).times
9
+ end
10
+
11
+ it "runs animation and executes block within context" do
12
+ context = spy("context")
13
+ spinner = TTY::Spinner.new(":title", output: output)
14
+
15
+ spinner.run("done") do
16
+ context.call
17
+ spinner.update(title: "executing")
18
+ end
19
+
20
+ expect(context).to have_received(:call).once
21
+ end
22
+
23
+ it "yields spinner instance when block argument is provided" do
24
+ spinner = TTY::Spinner.new(":title", output: output)
25
+
26
+ expect { |job|
27
+ spinner.run("done", &job)
28
+ }.to yield_with_args(spinner)
29
+ end
30
+ end
@@ -0,0 +1,117 @@
1
+ RSpec.describe TTY::Spinner, "#spin" do
2
+ let(:output) { StringIO.new("", "w+") }
3
+ let(:save) { TTY::Cursor.save }
4
+ let(:restore) { TTY::Cursor.restore }
5
+
6
+ it "spins default frames" do
7
+ spinner = TTY::Spinner.new(output: output)
8
+
9
+ expect(spinner.done?).to eq(false)
10
+
11
+ 5.times { spinner.spin }
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
+
22
+ it "spins chosen frame" do
23
+ spinner = TTY::Spinner.new(output: output, format: :spin)
24
+ 5.times { spinner.spin }
25
+ output.rewind
26
+ expect(output.read).to eq([
27
+ "\e[1G◴",
28
+ "\e[1G◷",
29
+ "\e[1G◶",
30
+ "\e[1G◵",
31
+ "\e[1G◴"
32
+ ].join)
33
+ end
34
+
35
+ it "spins with message" do
36
+ spinner = TTY::Spinner.new("Loading ... :spinner", output: output)
37
+ 4.times { spinner.spin }
38
+ output.rewind
39
+ expect(output.read).to eq([
40
+ "\e[1GLoading ... |",
41
+ "\e[1GLoading ... /",
42
+ "\e[1GLoading ... -",
43
+ "\e[1GLoading ... \\"
44
+ ].join)
45
+ end
46
+
47
+ context "with the cursor" do
48
+ before do
49
+ multi_spinner = double("MultiSpinner")
50
+ allow(multi_spinner).to receive(:synchronize).and_yield
51
+ allow(multi_spinner).to receive(:next_row).and_return(1)
52
+ allow(multi_spinner).to receive(:rows).and_return(1)
53
+ allow(multi_spinner).to receive(:line_inset).and_return("--- ")
54
+
55
+ spinner = TTY::Spinner.new(output: output, hide_cursor: hide_cursor)
56
+ spinner.attach_to(multi_spinner)
57
+ spinner.spin
58
+ spinner.redraw_indent
59
+
60
+ output.rewind
61
+ end
62
+
63
+ context "on" do
64
+ let(:hide_cursor) { false }
65
+
66
+ it "can spin and redraw indent" do
67
+ expect(output.read).to eq([
68
+ "\e[1G--- |\n",
69
+ save,
70
+ "\e[1A",
71
+ "--- ",
72
+ restore
73
+ ].join)
74
+ end
75
+ end
76
+
77
+ context "off" do
78
+ let(:hide_cursor) { true }
79
+
80
+ it "can spin and redraw indent" do
81
+ expect(output.read).to eq([
82
+ "--- ",
83
+ "\e[?25l\n",
84
+ save,
85
+ "\e[1A",
86
+ "\e[1G",
87
+ "--- |",
88
+ restore,
89
+ save,
90
+ "\e[1A",
91
+ "--- ",
92
+ restore
93
+ ].join)
94
+ end
95
+ end
96
+ end
97
+
98
+ it "spins with many threads" do
99
+ spinner = TTY::Spinner.new(output: output)
100
+
101
+ th1 = Thread.new { 3.times { spinner.spin; sleep(0.05) } }
102
+ th2 = Thread.new { 4.times { spinner.spin; sleep(0.05) } }
103
+
104
+ [th1, th2].each(&:join)
105
+
106
+ output.rewind
107
+ expect(output.read).to eq([
108
+ "\e[1G|",
109
+ "\e[1G/",
110
+ "\e[1G-",
111
+ "\e[1G\\",
112
+ "\e[1G|",
113
+ "\e[1G/",
114
+ "\e[1G-"
115
+ ].join)
116
+ end
117
+ end
@@ -0,0 +1,88 @@
1
+ RSpec.describe TTY::Spinner, "#stop" do
2
+ let(:output) { StringIO.new("", "w+") }
3
+
4
+ it "doesn't reprint stop message" do
5
+ spinner = TTY::Spinner.new(output: output)
6
+ spinner.spin
7
+ 3.times { spinner.stop }
8
+ output.rewind
9
+ expect(output.read).to eq([
10
+ "\e[1G|",
11
+ "\e[0m\e[2K",
12
+ "\e[1G|\n"
13
+ ].join)
14
+ end
15
+
16
+ it "stops after 2 spins" do
17
+ spinner = TTY::Spinner.new(output: output)
18
+ 5.times do |n|
19
+ spinner.spin
20
+ spinner.stop if n == 1
21
+ end
22
+ output.rewind
23
+ expect(output.read).to eq([
24
+ "\e[1G|",
25
+ "\e[1G/",
26
+ "\e[0m\e[2K",
27
+ "\e[1G/\n"
28
+ ].join)
29
+ end
30
+
31
+ it "stops after 2 spins and prints stop message" do
32
+ spinner = TTY::Spinner.new(output: output)
33
+ 5.times do |n|
34
+ spinner.spin
35
+ spinner.stop("Done!") if n == 1
36
+ end
37
+ output.rewind
38
+ expect(output.read).to eq([
39
+ "\e[1G|",
40
+ "\e[1G/",
41
+ "\e[0m\e[2K",
42
+ "\e[1G/ Done!\n"
43
+ ].join)
44
+
45
+ expect(spinner.done?).to eq(true)
46
+ end
47
+
48
+ it "stops after 2 spins with message and prints stop message" do
49
+ spinner = TTY::Spinner.new("Loading ... :spinner", output: output)
50
+ 5.times do |n|
51
+ spinner.spin
52
+ spinner.stop("Done!") if n == 1
53
+ end
54
+ output.rewind
55
+ expect(output.read).to eq([
56
+ "\e[1GLoading ... |",
57
+ "\e[1GLoading ... /",
58
+ "\e[0m\e[2K",
59
+ "\e[1GLoading ... / Done!\n"
60
+ ].join)
61
+ end
62
+
63
+ it "sets a custom mark when done" do
64
+ spinner = TTY::Spinner.new("[:spinner]", output: output)
65
+ 2.times { spinner.spin }
66
+ spinner.stop(mark: "!")
67
+
68
+ output.rewind
69
+ expect(output.read).to eq([
70
+ "\e[1G[|]\e[1G[/]",
71
+ "\e[0m\e[2K",
72
+ "\e[1G[!]\n"
73
+ ].join)
74
+ end
75
+
76
+ it "sets a custom message and mark when done" do
77
+ spinner = TTY::Spinner.new("[:spinner]", output: output)
78
+ 2.times { spinner.spin }
79
+ spinner.stop("Done", mark: "!")
80
+
81
+ output.rewind
82
+ expect(output.read).to eq([
83
+ "\e[1G[|]\e[1G[/]",
84
+ "\e[0m\e[2K",
85
+ "\e[1G[!] Done\n"
86
+ ].join)
87
+ end
88
+ end
@@ -0,0 +1,53 @@
1
+ RSpec.describe TTY::Spinner, "#success" do
2
+ let(:output) { StringIO.new("", "w+") }
3
+
4
+ it "marks spinner as success" do
5
+ spinner = TTY::Spinner.new(output: output)
6
+ 3.times { spinner.spin }
7
+ spinner.success
8
+ output.rewind
9
+ expect(output.read).to eq([
10
+ "\e[1G|",
11
+ "\e[1G/",
12
+ "\e[1G-",
13
+ "\e[0m\e[2K",
14
+ "\e[1G#{TTY::Spinner::TICK}\n"
15
+ ].join)
16
+
17
+ expect(spinner.success?).to eq(true)
18
+ end
19
+
20
+ it "marks spinner as success with message" do
21
+ spinner = TTY::Spinner.new(output: output)
22
+ 3.times { spinner.spin }
23
+ spinner.success("Successful")
24
+ output.rewind
25
+ expect(output.read).to eq([
26
+ "\e[1G|",
27
+ "\e[1G/",
28
+ "\e[1G-",
29
+ "\e[0m\e[2K",
30
+ "\e[1G#{TTY::Spinner::TICK} Successful\n"
31
+ ].join)
32
+
33
+ expect(spinner.success?).to be(true)
34
+ end
35
+
36
+ it "changes success spinner marker" do
37
+ spinner = TTY::Spinner.new(success_mark: "*", output: output)
38
+ spinner.success("(successful)")
39
+ output.rewind
40
+ expect(output.read).to eq("\e[0m\e[2K\e[1G* (successful)\n")
41
+
42
+ expect(spinner.success?).to be(true)
43
+ end
44
+
45
+ it "changes success spinner marker per method call" do
46
+ spinner = TTY::Spinner.new(success_mark: "*", output: output)
47
+ spinner.success("(success)", mark: "V")
48
+ output.rewind
49
+ expect(output.read).to eq("\e[0m\e[2K\e[1GV (success)\n")
50
+
51
+ expect(spinner.success?).to be(true)
52
+ end
53
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe TTY::Spinner, "#tty?" do
4
+ it "responds to tty?" do
5
+ spinner = TTY::Spinner.new
6
+ expect(spinner).to respond_to(:tty?)
7
+ end
8
+ end
@@ -0,0 +1,85 @@
1
+ RSpec.describe TTY::Spinner, "#update" do
2
+ let(:output) { StringIO.new("", "w+") }
3
+
4
+ it "updates message content with custom token" do
5
+ spinner = TTY::Spinner.new(":title :spinner", output: output, interval: 100)
6
+ spinner.update(title: "task")
7
+ 5.times { spinner.spin }
8
+ spinner.stop("done")
9
+ output.rewind
10
+ expect(output.read).to eq([
11
+ "\e[1Gtask |",
12
+ "\e[1Gtask /",
13
+ "\e[1Gtask -",
14
+ "\e[1Gtask \\",
15
+ "\e[1Gtask |",
16
+ "\e[0m\e[2K",
17
+ "\e[1Gtask | done\n"
18
+ ].join)
19
+ end
20
+
21
+ it "updates message many times before stopping" do
22
+ spinner = TTY::Spinner.new(":title :spinner", output: output)
23
+
24
+ spinner.update(title: "task_a")
25
+ 2.times { spinner.spin }
26
+ spinner.update(title: "task_b")
27
+ 2.times { spinner.spin }
28
+ spinner.stop("done")
29
+ output.rewind
30
+
31
+ expect(output.read).to eq([
32
+ "\e[1Gtask_a |",
33
+ "\e[1Gtask_a /",
34
+ "\e[0m\e[2K\e[1G",
35
+ "\e[1Gtask_b -",
36
+ "\e[1Gtask_b \\",
37
+ "\e[0m\e[2K",
38
+ "\e[1Gtask_b \\ done\n"
39
+ ].join)
40
+ end
41
+
42
+ it "updates message after stopping" do
43
+ spinner = TTY::Spinner.new(":title :spinner", output: output)
44
+
45
+ spinner.update(title: "task_a")
46
+ 2.times { spinner.spin }
47
+ spinner.stop("done")
48
+
49
+ spinner.start
50
+ spinner.update(title: "task_b")
51
+ 2.times { spinner.spin }
52
+ spinner.stop("done")
53
+
54
+ output.rewind
55
+ expect(output.read).to eq([
56
+ "\e[1Gtask_a |",
57
+ "\e[1Gtask_a /",
58
+ "\e[0m\e[2K",
59
+ "\e[1Gtask_a / done\n",
60
+ "\e[1Gtask_b |",
61
+ "\e[1Gtask_b /",
62
+ "\e[0m\e[2K",
63
+ "\e[1Gtask_b / done\n"
64
+ ].join)
65
+ end
66
+
67
+ it "maintains current tokens" do
68
+ spinner = TTY::Spinner.new(":foo :bar", output: output)
69
+ expect(spinner.tokens).to eq({})
70
+
71
+ spinner.update(foo: "FOO")
72
+ spinner.update(bar: "BAR")
73
+
74
+ expect(spinner.tokens).to include({foo: "FOO", bar: "BAR"})
75
+ end
76
+
77
+ it "updates more than one token" do
78
+ spinner = TTY::Spinner.new(":foo :bar", output: output)
79
+ expect(spinner.tokens).to eq({})
80
+
81
+ spinner.update(foo: "FOO", bar: "BAR")
82
+
83
+ expect(spinner.tokens).to include({foo: "FOO", bar: "BAR"})
84
+ end
85
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
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