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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitmodules +3 -0
- data/CHANGELOG.md +10 -0
- data/README.md +5 -3
- data/bin/plant +1 -1
- data/docker/Dockerfile +2 -4
- data/docker/Dockerfile-2.6 +3 -5
- data/docker/Dockerfile-2.7 +2 -4
- data/docker/Dockerfile-3.0 +2 -3
- data/docker/Dockerfile-3.3 +11 -0
- data/docker/sources.list +11 -0
- data/lib/planter/filelist.rb +5 -4
- data/lib/planter/plant.rb +3 -3
- data/lib/planter/prompt.rb +5 -5
- data/lib/planter/string.rb +22 -0
- data/lib/planter/tag.rb +39 -2
- data/lib/planter/version.rb +1 -1
- data/lib/planter.rb +30 -17
- data/lib/tty-spinner/.editorconfig +9 -0
- data/lib/tty-spinner/.github/FUNDING.yml +1 -0
- data/lib/tty-spinner/.github/ISSUE_TEMPLATE/BUG_REPORT.md +31 -0
- data/lib/tty-spinner/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +23 -0
- data/lib/tty-spinner/.github/ISSUE_TEMPLATE/config.yml +5 -0
- data/lib/tty-spinner/.github/PULL_REQUEST_TEMPLATE.md +19 -0
- data/lib/tty-spinner/.github/workflows/ci.yml +59 -0
- data/lib/tty-spinner/.gitignore +14 -0
- data/lib/tty-spinner/.rspec +2 -0
- data/lib/tty-spinner/.rubocop.yml +78 -0
- data/lib/tty-spinner/CHANGELOG.md +151 -0
- data/lib/tty-spinner/CODE_OF_CONDUCT.md +132 -0
- data/lib/tty-spinner/Gemfile +17 -0
- data/lib/tty-spinner/LICENSE.txt +22 -0
- data/lib/tty-spinner/README.md +581 -0
- data/lib/tty-spinner/Rakefile +10 -0
- data/lib/tty-spinner/appveyor.yml +33 -0
- data/lib/tty-spinner/bin/console +14 -0
- data/lib/tty-spinner/bin/setup +8 -0
- data/lib/tty-spinner/demo.gif +0 -0
- data/lib/tty-spinner/examples/auto_spin.rb +10 -0
- data/lib/tty-spinner/examples/basic.rb +10 -0
- data/lib/tty-spinner/examples/clear.rb +11 -0
- data/lib/tty-spinner/examples/color.rb +14 -0
- data/lib/tty-spinner/examples/error.rb +11 -0
- data/lib/tty-spinner/examples/formats.rb +13 -0
- data/lib/tty-spinner/examples/hide_cursor.rb +14 -0
- data/lib/tty-spinner/examples/log.rb +13 -0
- data/lib/tty-spinner/examples/multi/basic.rb +15 -0
- data/lib/tty-spinner/examples/multi/basic_top_level.rb +15 -0
- data/lib/tty-spinner/examples/multi/custom_style.rb +28 -0
- data/lib/tty-spinner/examples/multi/files.rb +16 -0
- data/lib/tty-spinner/examples/multi/jobs.rb +11 -0
- data/lib/tty-spinner/examples/multi/multi.rb +19 -0
- data/lib/tty-spinner/examples/multi/multi_top_level.rb +20 -0
- data/lib/tty-spinner/examples/multi/pause.rb +28 -0
- data/lib/tty-spinner/examples/multi/threaded.rb +30 -0
- data/lib/tty-spinner/examples/pause.rb +24 -0
- data/lib/tty-spinner/examples/run.rb +20 -0
- data/lib/tty-spinner/examples/success.rb +11 -0
- data/lib/tty-spinner/examples/threaded.rb +13 -0
- data/lib/tty-spinner/examples/update.rb +13 -0
- data/lib/tty-spinner/lib/tty/spinner/formats.rb +274 -0
- data/lib/tty-spinner/lib/tty/spinner/multi.rb +352 -0
- data/lib/tty-spinner/lib/tty/spinner/version.rb +7 -0
- data/lib/tty-spinner/lib/tty/spinner.rb +604 -0
- data/lib/tty-spinner/lib/tty-spinner.rb +2 -0
- data/lib/tty-spinner/spec/spec_helper.rb +52 -0
- data/lib/tty-spinner/spec/unit/auto_spin_spec.rb +25 -0
- data/lib/tty-spinner/spec/unit/clear_spec.rb +16 -0
- data/lib/tty-spinner/spec/unit/error_spec.rb +53 -0
- data/lib/tty-spinner/spec/unit/events_spec.rb +35 -0
- data/lib/tty-spinner/spec/unit/formats_spec.rb +9 -0
- data/lib/tty-spinner/spec/unit/frames_spec.rb +31 -0
- data/lib/tty-spinner/spec/unit/hide_cursor_spec.rb +51 -0
- data/lib/tty-spinner/spec/unit/job_spec.rb +12 -0
- data/lib/tty-spinner/spec/unit/join_spec.rb +10 -0
- data/lib/tty-spinner/spec/unit/log_spec.rb +60 -0
- data/lib/tty-spinner/spec/unit/multi/auto_spin_spec.rb +32 -0
- data/lib/tty-spinner/spec/unit/multi/error_spec.rb +107 -0
- data/lib/tty-spinner/spec/unit/multi/line_inset_spec.rb +57 -0
- data/lib/tty-spinner/spec/unit/multi/on_spec.rb +11 -0
- data/lib/tty-spinner/spec/unit/multi/register_spec.rb +46 -0
- data/lib/tty-spinner/spec/unit/multi/spin_spec.rb +101 -0
- data/lib/tty-spinner/spec/unit/multi/stop_spec.rb +95 -0
- data/lib/tty-spinner/spec/unit/multi/success_spec.rb +108 -0
- data/lib/tty-spinner/spec/unit/new_spec.rb +25 -0
- data/lib/tty-spinner/spec/unit/pause_spec.rb +43 -0
- data/lib/tty-spinner/spec/unit/reset_spec.rb +19 -0
- data/lib/tty-spinner/spec/unit/run_spec.rb +30 -0
- data/lib/tty-spinner/spec/unit/spin_spec.rb +117 -0
- data/lib/tty-spinner/spec/unit/stop_spec.rb +88 -0
- data/lib/tty-spinner/spec/unit/success_spec.rb +53 -0
- data/lib/tty-spinner/spec/unit/tty_spec.rb +8 -0
- data/lib/tty-spinner/spec/unit/update_spec.rb +85 -0
- data/lib/tty-spinner/tasks/console.rake +11 -0
- data/lib/tty-spinner/tasks/coverage.rake +11 -0
- data/lib/tty-spinner/tasks/spec.rake +29 -0
- data/lib/tty-spinner/tty-spinner.gemspec +36 -0
- data/scripts/runtests.sh +1 -1
- data/spec/cli_spec.rb +27 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/templates/test/_planter.yml +3 -6
- data/src/_README.md +5 -3
- metadata +86 -2
@@ -0,0 +1,53 @@
|
|
1
|
+
RSpec.describe TTY::Spinner, "#error" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "marks spinner as error" do
|
5
|
+
spinner = TTY::Spinner.new(output: output)
|
6
|
+
3.times { spinner.spin }
|
7
|
+
spinner.error
|
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::CROSS}\n"
|
15
|
+
].join)
|
16
|
+
|
17
|
+
expect(spinner.error?).to be(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "marks spinner as error with message" do
|
21
|
+
spinner = TTY::Spinner.new(output: output)
|
22
|
+
3.times { spinner.spin }
|
23
|
+
spinner.error("Error")
|
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::CROSS} Error\n"
|
31
|
+
].join)
|
32
|
+
|
33
|
+
expect(spinner.error?).to be(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "changes error spinner marker" do
|
37
|
+
spinner = TTY::Spinner.new(error_mark: "x", output: output)
|
38
|
+
spinner.error("(error)")
|
39
|
+
output.rewind
|
40
|
+
expect(output.read).to eq("\e[0m\e[2K\e[1Gx (error)\n")
|
41
|
+
|
42
|
+
expect(spinner.error?).to be(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "changes error spinner marker per method call" do
|
46
|
+
spinner = TTY::Spinner.new(error_mark: "x", output: output)
|
47
|
+
spinner.error("(error)", mark: "!")
|
48
|
+
output.rewind
|
49
|
+
expect(output.read).to eq("\e[0m\e[2K\e[1G! (error)\n")
|
50
|
+
|
51
|
+
expect(spinner.error?).to be(true)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
RSpec.describe TTY::Spinner, "events" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "emits :done event" do
|
5
|
+
events = []
|
6
|
+
spinner = TTY::Spinner.new(output: output)
|
7
|
+
spinner.on(:done) { events << :done }
|
8
|
+
|
9
|
+
spinner.stop
|
10
|
+
|
11
|
+
expect(events).to eq([:done])
|
12
|
+
end
|
13
|
+
|
14
|
+
it "emits :success event" do
|
15
|
+
events = []
|
16
|
+
spinner = TTY::Spinner.new(output: output)
|
17
|
+
spinner.on(:done) { events << :done }
|
18
|
+
spinner.on(:success) { events << :success }
|
19
|
+
|
20
|
+
spinner.success
|
21
|
+
|
22
|
+
expect(events).to match_array(%i[done success])
|
23
|
+
end
|
24
|
+
|
25
|
+
it "emits :error event" do
|
26
|
+
events = []
|
27
|
+
spinner = TTY::Spinner.new(output: output)
|
28
|
+
spinner.on(:done) { events << :done }
|
29
|
+
spinner.on(:error) { events << :error }
|
30
|
+
|
31
|
+
spinner.error
|
32
|
+
|
33
|
+
expect(events).to match_array(%i[done error])
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
RSpec.describe TTY::Spinner, ":frames" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "uses custom frames from string" do
|
5
|
+
frames = ".o0@*"
|
6
|
+
spinner = TTY::Spinner.new(frames: frames, output: output)
|
7
|
+
5.times { spinner.spin }
|
8
|
+
output.rewind
|
9
|
+
expect(output.read).to eq([
|
10
|
+
"\e[1G.",
|
11
|
+
"\e[1Go",
|
12
|
+
"\e[1G0",
|
13
|
+
"\e[1G@",
|
14
|
+
"\e[1G*"
|
15
|
+
].join)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "uses custom frames from array" do
|
19
|
+
frames = [".", "o", "0", "@", "*"]
|
20
|
+
spinner = TTY::Spinner.new(frames: frames, output: output)
|
21
|
+
5.times { spinner.spin }
|
22
|
+
output.rewind
|
23
|
+
expect(output.read).to eq([
|
24
|
+
"\e[1G.",
|
25
|
+
"\e[1Go",
|
26
|
+
"\e[1G0",
|
27
|
+
"\e[1G@",
|
28
|
+
"\e[1G*"
|
29
|
+
].join)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
RSpec.describe TTY::Spinner, ":hide_cursor" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "hides cursor" do
|
5
|
+
spinner = TTY::Spinner.new(output: output, hide_cursor: true)
|
6
|
+
4.times { spinner.spin }
|
7
|
+
spinner.stop
|
8
|
+
output.rewind
|
9
|
+
expect(output.read).to eq([
|
10
|
+
"\e[?25l\e[1G|",
|
11
|
+
"\e[1G/",
|
12
|
+
"\e[1G-",
|
13
|
+
"\e[1G\\",
|
14
|
+
"\e[0m\e[2K",
|
15
|
+
"\e[1G\\\n",
|
16
|
+
"\e[?25h"
|
17
|
+
].join)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "restores cursor on success" do
|
21
|
+
spinner = TTY::Spinner.new(output: output, hide_cursor: true)
|
22
|
+
4.times { spinner.spin }
|
23
|
+
spinner.success("success")
|
24
|
+
output.rewind
|
25
|
+
expect(output.read).to eq([
|
26
|
+
"\e[?25l\e[1G|",
|
27
|
+
"\e[1G/",
|
28
|
+
"\e[1G-",
|
29
|
+
"\e[1G\\",
|
30
|
+
"\e[0m\e[2K",
|
31
|
+
"\e[1G\u2714 success\n",
|
32
|
+
"\e[?25h"
|
33
|
+
].join)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "restores cursor on error" do
|
37
|
+
spinner = TTY::Spinner.new(output: output, hide_cursor: true)
|
38
|
+
4.times { spinner.spin }
|
39
|
+
spinner.error("error")
|
40
|
+
output.rewind
|
41
|
+
expect(output.read).to eq([
|
42
|
+
"\e[?25l\e[1G|",
|
43
|
+
"\e[1G/",
|
44
|
+
"\e[1G-",
|
45
|
+
"\e[1G\\",
|
46
|
+
"\e[0m\e[2K",
|
47
|
+
"\e[1G\u2716 error\n",
|
48
|
+
"\e[?25h"
|
49
|
+
].join)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
RSpec.describe TTY::Spinner, "#job" do
|
2
|
+
it "adds and executes job" do
|
3
|
+
spinner = TTY::Spinner.new("[:spinner] :title")
|
4
|
+
called = []
|
5
|
+
work = proc { |sp| called << sp }
|
6
|
+
spinner.job(&work)
|
7
|
+
|
8
|
+
spinner.execute_job
|
9
|
+
|
10
|
+
expect(called).to eq([spinner])
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
RSpec.describe TTY::Spinner, "#join" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "raises exception when not spinning" do
|
5
|
+
spinner = TTY::Spinner.new(output: output)
|
6
|
+
expect {
|
7
|
+
spinner.join
|
8
|
+
}.to raise_error(TTY::Spinner::NotSpinningError)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
RSpec.describe TTY::Spinner, "#log" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "logs a message above a spinner" do
|
5
|
+
spinner = TTY::Spinner.new(output: output)
|
6
|
+
|
7
|
+
2.times {
|
8
|
+
spinner.log "foo\nbar"
|
9
|
+
spinner.spin
|
10
|
+
}
|
11
|
+
output.rewind
|
12
|
+
|
13
|
+
expect(output.read).to eq([
|
14
|
+
"\e[2K\e[1Gfoo\n",
|
15
|
+
"\e[2K\e[1Gbar\n",
|
16
|
+
"\e[1G|",
|
17
|
+
"\e[1G|",
|
18
|
+
"\e[2K\e[1Gfoo\n",
|
19
|
+
"\e[2K\e[1Gbar\n",
|
20
|
+
"\e[1G/",
|
21
|
+
"\e[1G/"
|
22
|
+
].join)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "logs a message ending with a newline above a spinner" do
|
26
|
+
spinner = TTY::Spinner.new(output: output)
|
27
|
+
|
28
|
+
2.times {
|
29
|
+
spinner.log "foo\n"
|
30
|
+
spinner.spin
|
31
|
+
}
|
32
|
+
output.rewind
|
33
|
+
|
34
|
+
expect(output.read).to eq([
|
35
|
+
"\e[2K\e[1Gfoo\n",
|
36
|
+
"\e[1G|",
|
37
|
+
"\e[1G|",
|
38
|
+
"\e[2K\e[1Gfoo\n",
|
39
|
+
"\e[1G/",
|
40
|
+
"\e[1G/"
|
41
|
+
].join)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "logs message under a spinner when done" do
|
45
|
+
spinner = TTY::Spinner.new(output: output)
|
46
|
+
2.times { spinner.spin }
|
47
|
+
spinner.stop
|
48
|
+
|
49
|
+
spinner.log "foo\nbar"
|
50
|
+
|
51
|
+
output.rewind
|
52
|
+
expect(output.read).to eq([
|
53
|
+
"\e[1G|",
|
54
|
+
"\e[1G/",
|
55
|
+
"\e[0m\e[2K\e[1G/\n",
|
56
|
+
"\e[2K\e[1Gfoo\n",
|
57
|
+
"\e[2K\e[1Gbar\n"
|
58
|
+
].join)
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
RSpec.describe TTY::Spinner::Multi, "#auto_spin" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "doesn't auto spin top level spinner" do
|
5
|
+
spinners = TTY::Spinner::Multi.new("Top level spinner", output: output)
|
6
|
+
allow(spinners.top_spinner).to receive(:auto_spin)
|
7
|
+
|
8
|
+
spinners.auto_spin
|
9
|
+
|
10
|
+
expect(spinners.top_spinner).to_not have_received(:auto_spin)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises an exception when called without a top spinner" do
|
14
|
+
spinners = TTY::Spinner::Multi.new(output: output)
|
15
|
+
|
16
|
+
expect {
|
17
|
+
spinners.auto_spin
|
18
|
+
}.to raise_error(RuntimeError, /No top level spinner/)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "auto spins top level & child spinners with jobs" do
|
22
|
+
spinners = TTY::Spinner::Multi.new("top", output: output)
|
23
|
+
jobs = []
|
24
|
+
|
25
|
+
spinners.register("one") { |sp| jobs << "one"; sp.success }
|
26
|
+
spinners.register("two") { |sp| jobs << "two"; sp.success }
|
27
|
+
|
28
|
+
spinners.auto_spin
|
29
|
+
|
30
|
+
expect(jobs).to match_array(%w[one two])
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
RSpec.describe TTY::Spinner::Multi, "#error" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "stops registerd multi spinner and emits an :error 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.error?).to eq(false)
|
11
|
+
expect(sp2.error?).to eq(false)
|
12
|
+
|
13
|
+
spinners.on(:error) { callbacks << :error }
|
14
|
+
.on(:done) { callbacks << :done }
|
15
|
+
.on(:success) { callbacks << :success }
|
16
|
+
|
17
|
+
spinners.error
|
18
|
+
|
19
|
+
expect(sp1.error?).to eq(true)
|
20
|
+
expect(sp2.error?).to eq(true)
|
21
|
+
expect(callbacks).to match_array(%i[done error])
|
22
|
+
end
|
23
|
+
|
24
|
+
it "stops unregistered top level spinner and emits an :error 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.error?).to eq(false)
|
31
|
+
expect(sp2.error?).to eq(false)
|
32
|
+
|
33
|
+
spinners.on(:error) { callbacks << :error }
|
34
|
+
.on(:done) { callbacks << :done }
|
35
|
+
.on(:success) { callbacks << :success }
|
36
|
+
|
37
|
+
spinners.error
|
38
|
+
|
39
|
+
expect(sp1.error?).to eq(true)
|
40
|
+
expect(sp2.error?).to eq(true)
|
41
|
+
expect(callbacks).to match_array(%i[done error])
|
42
|
+
end
|
43
|
+
|
44
|
+
it "stops registed spinners under top level and emits an error 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.error?).to eq(false)
|
51
|
+
expect(sp2.error?).to eq(false)
|
52
|
+
|
53
|
+
spinners.on(:error) { callbacks << :error }
|
54
|
+
.on(:done) { callbacks << :done }
|
55
|
+
.on(:success) { callbacks << :success }
|
56
|
+
|
57
|
+
sp1.error
|
58
|
+
sp2.error
|
59
|
+
|
60
|
+
expect(spinners.error?).to eq(true)
|
61
|
+
expect(callbacks).to match_array(%i[done error])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "stops registed spinners under top level and emits an error 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.error?).to eq(false)
|
71
|
+
expect(sp2.error?).to eq(false)
|
72
|
+
|
73
|
+
spinners.on(:error) { callbacks << :error }
|
74
|
+
.on(:done) { callbacks << :done }
|
75
|
+
.on(:success) { callbacks << :success }
|
76
|
+
|
77
|
+
sp1.error
|
78
|
+
sp2.error
|
79
|
+
|
80
|
+
expect(spinners.error?).to eq(true)
|
81
|
+
expect(callbacks).to match_array(%i[done error])
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns true when any spinner failed" do
|
85
|
+
spinners = TTY::Spinner::Multi.new(output: output)
|
86
|
+
sp1 = spinners.register("one")
|
87
|
+
sp2 = spinners.register("two")
|
88
|
+
|
89
|
+
sp1.success
|
90
|
+
sp2.error
|
91
|
+
|
92
|
+
expect(spinners.error?).to eq(true)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "updates top spinner error state based on child spinners jobs failure" do
|
96
|
+
spinners = TTY::Spinner::Multi.new("top", output: output)
|
97
|
+
|
98
|
+
spinners.register("one") { |sp| sp.success }
|
99
|
+
spinners.register("two") { |sp| sp.error }
|
100
|
+
|
101
|
+
expect(spinners.error?).to eq(false)
|
102
|
+
|
103
|
+
spinners.auto_spin
|
104
|
+
|
105
|
+
expect(spinners.error?).to eq(true)
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
RSpec.describe TTY::Spinner::Multi, "#line_inset" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "doesn't create inset when no top level spinner" do
|
5
|
+
spinners = TTY::Spinner::Multi.new(output: output)
|
6
|
+
|
7
|
+
spinner = spinners.register "example"
|
8
|
+
|
9
|
+
expect(spinners.line_inset(spinner)).to eq("")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "defaults to the empty string for the top level spinner" do
|
13
|
+
spinners = TTY::Spinner::Multi.new("Top level spinner", output: output)
|
14
|
+
|
15
|
+
expect(spinners.line_inset(1))
|
16
|
+
.to eq(TTY::Spinner::Multi::DEFAULT_INSET[:top])
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns four spaces when there is a top level spinner" do
|
20
|
+
spinners = TTY::Spinner::Multi.new("Top level spinner", output: output)
|
21
|
+
|
22
|
+
spinners.register "middle"
|
23
|
+
spinners.register "bottom"
|
24
|
+
|
25
|
+
expect(spinners.line_inset(2))
|
26
|
+
.to eq(TTY::Spinner::Multi::DEFAULT_INSET[:middle])
|
27
|
+
end
|
28
|
+
|
29
|
+
it "decorates last spinner" do
|
30
|
+
spinners = TTY::Spinner::Multi.new("Top spinner", output: output)
|
31
|
+
|
32
|
+
spinners.register "middle"
|
33
|
+
spinners.register "bottom"
|
34
|
+
|
35
|
+
expect(spinners.line_inset(3))
|
36
|
+
.to eq(TTY::Spinner::Multi::DEFAULT_INSET[:bottom])
|
37
|
+
end
|
38
|
+
|
39
|
+
it "allows customization" do
|
40
|
+
opts = {
|
41
|
+
output: output,
|
42
|
+
indent: 4,
|
43
|
+
style: {
|
44
|
+
top: ". ",
|
45
|
+
middle: "--",
|
46
|
+
bottom: "---"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
spinners = TTY::Spinner::Multi.new("Top level spinner", opts)
|
50
|
+
spinners.register ""
|
51
|
+
spinners.register ""
|
52
|
+
|
53
|
+
expect(spinners.line_inset(1)).to eq(". ")
|
54
|
+
expect(spinners.line_inset(2)).to eq("--")
|
55
|
+
expect(spinners.line_inset(3)).to eq("---")
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
RSpec.describe TTY::Spinner::Multi, "#on" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "fails to register a callback with invalid event name" do
|
5
|
+
spinners = TTY::Spinner::Multi.new(output: output)
|
6
|
+
|
7
|
+
expect {
|
8
|
+
spinners.on(:unknown_event) { :noop }
|
9
|
+
}.to raise_error(ArgumentError, /The event unknown_event does not exist/)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe TTY::Spinner::Multi, "#register" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
|
4
|
+
it "registers a TTY::Spinner instance from a pattern" do
|
5
|
+
spinners = TTY::Spinner::Multi.new(output: output, interval: 100)
|
6
|
+
allow_any_instance_of(TTY::Spinner).to receive(:attach_to)
|
7
|
+
expect_any_instance_of(TTY::Spinner).to receive(:attach_to)
|
8
|
+
|
9
|
+
spinner = spinners.register ""
|
10
|
+
|
11
|
+
expect(spinner).to be_instance_of(TTY::Spinner)
|
12
|
+
expect(spinners.length).to eq(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "registers a TTY::Spinner instance from a spinner instance" do
|
16
|
+
spinners = TTY::Spinner::Multi.new(output: output, interval: 100)
|
17
|
+
spinner_to_register = ::TTY::Spinner.new
|
18
|
+
|
19
|
+
spinner = spinners.register spinner_to_register
|
20
|
+
|
21
|
+
expect(spinner).to eq(spinner_to_register)
|
22
|
+
expect(spinners.length).to eq(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises an erro when given neither a string or spinner instance" do
|
26
|
+
spinners = TTY::Spinner::Multi.new(output: output, interval: 100)
|
27
|
+
|
28
|
+
expect { spinners.register [] }
|
29
|
+
.to raise_error(
|
30
|
+
ArgumentError,
|
31
|
+
"Expected a pattern or spinner, got: Array"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "uses global options to register instance" do
|
36
|
+
spinners = TTY::Spinner::Multi.new(output: output, interval: 100)
|
37
|
+
spinner = double(:spinner, attach_to: nil)
|
38
|
+
allow(spinner).to receive(:on).and_return(spinner)
|
39
|
+
allow(TTY::Spinner).to receive(:new).and_return(spinner)
|
40
|
+
|
41
|
+
spinners.register "[:spinner]"
|
42
|
+
|
43
|
+
expect(TTY::Spinner).to have_received(:new)
|
44
|
+
.with("[:spinner]", {interval: 100, output: output})
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
RSpec.describe TTY::Spinner::Multi, "#spin" do
|
2
|
+
let(:output) { StringIO.new("", "w+") }
|
3
|
+
let(:save) { TTY::Cursor.save }
|
4
|
+
let(:restore) { TTY::Cursor.restore }
|
5
|
+
let(:top) { TTY::Spinner::Multi::DEFAULT_INSET[:top] }
|
6
|
+
let(:middle) { TTY::Spinner::Multi::DEFAULT_INSET[:middle] }
|
7
|
+
let(:bottom) { TTY::Spinner::Multi::DEFAULT_INSET[:bottom] }
|
8
|
+
|
9
|
+
it "spins spinners correctly under multi spinner" do
|
10
|
+
spinners = TTY::Spinner::Multi.new(output: output)
|
11
|
+
|
12
|
+
spinner1 = spinners.register(":spinner one")
|
13
|
+
spinner2 = spinners.register(":spinner two")
|
14
|
+
|
15
|
+
spinner2.spin
|
16
|
+
spinner1.spin
|
17
|
+
|
18
|
+
output.rewind
|
19
|
+
expect(output.read).to eq([
|
20
|
+
"\e[1G| two\n",
|
21
|
+
"\e[1G| one\n"
|
22
|
+
].join)
|
23
|
+
|
24
|
+
spinner1.spin
|
25
|
+
|
26
|
+
output.rewind
|
27
|
+
expect(output.read).to eq([
|
28
|
+
"\e[1G| two\n",
|
29
|
+
"\e[1G| one\n",
|
30
|
+
save,
|
31
|
+
"\e[1A", # up 1 line
|
32
|
+
"\e[1G/ one",
|
33
|
+
restore
|
34
|
+
].join)
|
35
|
+
|
36
|
+
spinner2.spin
|
37
|
+
|
38
|
+
output.rewind
|
39
|
+
expect(output.read).to eq([
|
40
|
+
"\e[1G| two\n",
|
41
|
+
"\e[1G| one\n",
|
42
|
+
save,
|
43
|
+
"\e[1A", # up 1 line
|
44
|
+
"\e[1G/ one",
|
45
|
+
restore,
|
46
|
+
save,
|
47
|
+
"\e[2A", # up 2 lines
|
48
|
+
"\e[1G/ two",
|
49
|
+
restore
|
50
|
+
].join)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "spins registerd spinners correctly under top level multi spinner" do
|
54
|
+
spinners = TTY::Spinner::Multi.new(":spinner top", output: output)
|
55
|
+
|
56
|
+
spinner1 = spinners.register(":spinner one")
|
57
|
+
spinner2 = spinners.register(":spinner two")
|
58
|
+
|
59
|
+
spinners.spin
|
60
|
+
|
61
|
+
spinner2.spin
|
62
|
+
spinner1.spin
|
63
|
+
|
64
|
+
output.rewind
|
65
|
+
expect(output.read).to eq([
|
66
|
+
"\e[1G#{top}| top\n",
|
67
|
+
"\e[1G#{middle}| two\n",
|
68
|
+
"\e[1G#{bottom}| one\n"
|
69
|
+
].join)
|
70
|
+
|
71
|
+
spinner1.spin
|
72
|
+
|
73
|
+
output.rewind
|
74
|
+
expect(output.read).to eq([
|
75
|
+
"\e[1G#{top}| top\n",
|
76
|
+
"\e[1G#{middle}| two\n",
|
77
|
+
"\e[1G#{bottom}| one\n",
|
78
|
+
save,
|
79
|
+
"\e[1A", # up 1 line
|
80
|
+
"\e[1G#{bottom}/ one",
|
81
|
+
restore
|
82
|
+
].join)
|
83
|
+
|
84
|
+
spinner2.spin
|
85
|
+
|
86
|
+
output.rewind
|
87
|
+
expect(output.read).to eq([
|
88
|
+
"\e[1G#{top}| top\n",
|
89
|
+
"\e[1G#{middle}| two\n",
|
90
|
+
"\e[1G#{bottom}| one\n",
|
91
|
+
save,
|
92
|
+
"\e[1A", # up 1 line
|
93
|
+
"\e[1G#{bottom}/ one",
|
94
|
+
restore,
|
95
|
+
save,
|
96
|
+
"\e[2A", # up 2 lines
|
97
|
+
"\e[1G#{middle}/ two",
|
98
|
+
restore
|
99
|
+
].join)
|
100
|
+
end
|
101
|
+
end
|