tty-spinner 0.9.2 → 0.9.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 +9 -3
- data/lib/tty/spinner/version.rb +1 -1
- metadata +16 -102
- data/Rakefile +0 -8
- data/examples/auto_spin.rb +0 -8
- data/examples/basic.rb +0 -8
- data/examples/clear.rb +0 -9
- data/examples/color.rb +0 -12
- data/examples/error.rb +0 -9
- data/examples/formats.rb +0 -11
- data/examples/hide_cursor.rb +0 -12
- data/examples/multi/basic.rb +0 -13
- data/examples/multi/basic_top_level.rb +0 -13
- data/examples/multi/custom_style.rb +0 -26
- data/examples/multi/files.rb +0 -14
- data/examples/multi/jobs.rb +0 -10
- data/examples/multi/multi.rb +0 -17
- data/examples/multi/multi_top_level.rb +0 -18
- data/examples/multi/pause.rb +0 -26
- data/examples/multi/threaded.rb +0 -30
- data/examples/pause.rb +0 -19
- data/examples/run.rb +0 -18
- data/examples/success.rb +0 -9
- data/examples/threaded.rb +0 -11
- data/examples/update.rb +0 -11
- data/spec/spec_helper.rb +0 -51
- data/spec/unit/auto_spin_spec.rb +0 -27
- data/spec/unit/clear_spec.rb +0 -18
- data/spec/unit/error_spec.rb +0 -46
- data/spec/unit/events_spec.rb +0 -37
- data/spec/unit/formats_spec.rb +0 -9
- data/spec/unit/frames_spec.rb +0 -33
- data/spec/unit/hide_cursor_spec.rb +0 -53
- data/spec/unit/job_spec.rb +0 -14
- data/spec/unit/join_spec.rb +0 -12
- data/spec/unit/multi/auto_spin_spec.rb +0 -34
- data/spec/unit/multi/error_spec.rb +0 -109
- data/spec/unit/multi/line_inset_spec.rb +0 -59
- data/spec/unit/multi/on_spec.rb +0 -13
- data/spec/unit/multi/register_spec.rb +0 -47
- data/spec/unit/multi/spin_spec.rb +0 -103
- data/spec/unit/multi/stop_spec.rb +0 -97
- data/spec/unit/multi/success_spec.rb +0 -110
- data/spec/unit/new_spec.rb +0 -26
- data/spec/unit/pause_spec.rb +0 -25
- data/spec/unit/reset_spec.rb +0 -21
- data/spec/unit/run_spec.rb +0 -32
- data/spec/unit/spin_spec.rb +0 -119
- data/spec/unit/stop_spec.rb +0 -64
- data/spec/unit/success_spec.rb +0 -46
- data/spec/unit/update_spec.rb +0 -87
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-spinner.gemspec +0 -27
data/examples/multi/threaded.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../lib/tty-spinner'
|
4
|
-
|
5
|
-
def spinner_options
|
6
|
-
[
|
7
|
-
":spinner \e[1mNo\e[0m :number Row :line",
|
8
|
-
format: :dots,
|
9
|
-
error_mark: '✖',
|
10
|
-
success_mark: "\e[1m\e[32m✓\e[0m\e[0m"
|
11
|
-
]
|
12
|
-
end
|
13
|
-
|
14
|
-
spinners = TTY::Spinner::Multi.new(*spinner_options)
|
15
|
-
threads = []
|
16
|
-
|
17
|
-
20.times do |i|
|
18
|
-
threads << Thread.new do
|
19
|
-
spinner = spinners.register(*spinner_options)
|
20
|
-
sleep Random.rand(0.1..0.3)
|
21
|
-
|
22
|
-
10.times do
|
23
|
-
sleep Random.rand(0.1..0.3)
|
24
|
-
spinner.update(number: "(#{i})", line: spinner.row)
|
25
|
-
spinner.spin
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
threads.each(&:join)
|
data/examples/pause.rb
DELETED
data/examples/run.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative '../lib/tty-spinner'
|
2
|
-
|
3
|
-
# without block
|
4
|
-
spinner = TTY::Spinner.new(":title :spinner ...", format: :pulse_3)
|
5
|
-
|
6
|
-
def long_task
|
7
|
-
10000000.times do |n|
|
8
|
-
n * n
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
spinner.update(title: 'Task 1')
|
13
|
-
spinner.run 'done' do
|
14
|
-
long_task
|
15
|
-
end
|
16
|
-
|
17
|
-
spinner.update(title: 'Task 2')
|
18
|
-
spinner.run('done') { long_task }
|
data/examples/success.rb
DELETED
data/examples/threaded.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require_relative '../lib/tty-spinner'
|
2
|
-
|
3
|
-
spinner = TTY::Spinner.new("[:spinner]")
|
4
|
-
|
5
|
-
th1 = Thread.new { 10.times { spinner.spin; sleep(0.1) } }
|
6
|
-
th2 = Thread.new { 10.times { spinner.spin; sleep(0.1) } }
|
7
|
-
th3 = Thread.new { 10.times { spinner.spin; sleep(0.1) } }
|
8
|
-
|
9
|
-
[th1, th2, th3].each(&:join)
|
10
|
-
|
11
|
-
spinner.success
|
data/examples/update.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require_relative '../lib/tty-spinner'
|
2
|
-
|
3
|
-
spinner = TTY::Spinner.new(":spinner :title", format: :pulse_3)
|
4
|
-
|
5
|
-
spinner.update(title: 'task aaaaa')
|
6
|
-
|
7
|
-
20.times { spinner.spin; sleep(0.1) }
|
8
|
-
|
9
|
-
spinner.update(title: 'task b')
|
10
|
-
|
11
|
-
20.times { spinner.spin; sleep(0.1) }
|
data/spec/spec_helper.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if ENV['COVERAGE'] || ENV['TRAVIS']
|
4
|
-
require 'simplecov'
|
5
|
-
require 'coveralls'
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
Coveralls::SimpleCov::Formatter
|
10
|
-
])
|
11
|
-
|
12
|
-
SimpleCov.start do
|
13
|
-
command_name 'spec'
|
14
|
-
add_filter 'spec'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'tty-spinner'
|
19
|
-
|
20
|
-
class StringIO
|
21
|
-
def tty?
|
22
|
-
true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
RSpec.configure do |config|
|
27
|
-
config.expect_with :rspec do |expectations|
|
28
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
29
|
-
end
|
30
|
-
|
31
|
-
config.mock_with :rspec do |mocks|
|
32
|
-
mocks.verify_partial_doubles = true
|
33
|
-
end
|
34
|
-
|
35
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
36
|
-
config.disable_monkey_patching!
|
37
|
-
|
38
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
39
|
-
# be too noisy due to issues in dependencies.
|
40
|
-
config.warnings = true
|
41
|
-
|
42
|
-
if config.files_to_run.one?
|
43
|
-
config.default_formatter = 'doc'
|
44
|
-
end
|
45
|
-
|
46
|
-
config.profile_examples = 2
|
47
|
-
|
48
|
-
config.order = :random
|
49
|
-
|
50
|
-
Kernel.srand config.seed
|
51
|
-
end
|
data/spec/unit/auto_spin_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Spinner, '#auto_spin' do
|
4
|
-
let(:output) { StringIO.new('', 'w+') }
|
5
|
-
|
6
|
-
it "starts and auto spins" do
|
7
|
-
spinner = TTY::Spinner.new(output: output, interval: 100)
|
8
|
-
allow(spinner).to receive(:spin)
|
9
|
-
|
10
|
-
spinner.auto_spin
|
11
|
-
sleep 0.1
|
12
|
-
spinner.stop
|
13
|
-
|
14
|
-
expect(spinner).to have_received(:spin).at_least(5).times
|
15
|
-
end
|
16
|
-
|
17
|
-
it "restores cursor when erorr is raised" do
|
18
|
-
spinner = TTY::Spinner.new(output: output, hide_cursor: true)
|
19
|
-
|
20
|
-
spinner.auto_spin {
|
21
|
-
raise 'boom'
|
22
|
-
}
|
23
|
-
|
24
|
-
output.rewind
|
25
|
-
expect(output.read).to start_with("\e[?25l").and end_with("\e[?25h")
|
26
|
-
end
|
27
|
-
end
|
data/spec/unit/clear_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Spinner, ':clear' do
|
4
|
-
let(:output) { StringIO.new('', 'w+') }
|
5
|
-
|
6
|
-
it "clears output when done" do
|
7
|
-
spinner = TTY::Spinner.new(clear: true, output: output)
|
8
|
-
3.times { spinner.spin }
|
9
|
-
spinner.stop('Done!')
|
10
|
-
output.rewind
|
11
|
-
expect(output.read).to eq([
|
12
|
-
"\e[1G|",
|
13
|
-
"\e[1G/",
|
14
|
-
"\e[1G-",
|
15
|
-
"\e[0m\e[2K\e[1G"
|
16
|
-
].join)
|
17
|
-
end
|
18
|
-
end
|
data/spec/unit/error_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Spinner, '#error' do
|
4
|
-
let(:output) { StringIO.new('', 'w+') }
|
5
|
-
|
6
|
-
it "marks spinner as error" do
|
7
|
-
spinner = TTY::Spinner.new(output: output)
|
8
|
-
3.times { spinner.spin }
|
9
|
-
spinner.error
|
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::CROSS}\n"
|
17
|
-
].join)
|
18
|
-
|
19
|
-
expect(spinner.error?).to be(true)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "marks spinner as error with message" do
|
23
|
-
spinner = TTY::Spinner.new(output: output)
|
24
|
-
3.times { spinner.spin }
|
25
|
-
spinner.error('Error')
|
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::CROSS} Error\n"
|
33
|
-
].join)
|
34
|
-
|
35
|
-
expect(spinner.error?).to be(true)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "changes error spinner marker" do
|
39
|
-
spinner = TTY::Spinner.new(error_mark: 'x', output: output)
|
40
|
-
spinner.error('(error)')
|
41
|
-
output.rewind
|
42
|
-
expect(output.read).to eq("\e[0m\e[2K\e[1Gx (error)\n")
|
43
|
-
|
44
|
-
expect(spinner.error?).to be(true)
|
45
|
-
end
|
46
|
-
end
|
data/spec/unit/events_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Spinner, 'events' do
|
4
|
-
let(:output) { StringIO.new('', 'w+') }
|
5
|
-
|
6
|
-
it "emits :done event" do
|
7
|
-
events = []
|
8
|
-
spinner = TTY::Spinner.new(output: output)
|
9
|
-
spinner.on(:done) { events << :done }
|
10
|
-
|
11
|
-
spinner.stop
|
12
|
-
|
13
|
-
expect(events).to eq([:done])
|
14
|
-
end
|
15
|
-
|
16
|
-
it "emits :success event" do
|
17
|
-
events = []
|
18
|
-
spinner = TTY::Spinner.new(output: output)
|
19
|
-
spinner.on(:done) { events << :done }
|
20
|
-
spinner.on(:success) { events << :success }
|
21
|
-
|
22
|
-
spinner.success
|
23
|
-
|
24
|
-
expect(events).to match_array([:done, :success])
|
25
|
-
end
|
26
|
-
|
27
|
-
it "emits :error event" do
|
28
|
-
events = []
|
29
|
-
spinner = TTY::Spinner.new(output: output)
|
30
|
-
spinner.on(:done) { events << :done }
|
31
|
-
spinner.on(:error) { events << :error }
|
32
|
-
|
33
|
-
spinner.error
|
34
|
-
|
35
|
-
expect(events).to match_array([:done, :error])
|
36
|
-
end
|
37
|
-
end
|
data/spec/unit/formats_spec.rb
DELETED
data/spec/unit/frames_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Spinner, ':frames' do
|
4
|
-
let(:output) { StringIO.new('', 'w+') }
|
5
|
-
|
6
|
-
it "uses custom frames from string" do
|
7
|
-
frames = ".o0@*"
|
8
|
-
spinner = TTY::Spinner.new(frames: frames, output: output)
|
9
|
-
5.times { spinner.spin }
|
10
|
-
output.rewind
|
11
|
-
expect(output.read).to eq([
|
12
|
-
"\e[1G.",
|
13
|
-
"\e[1Go",
|
14
|
-
"\e[1G0",
|
15
|
-
"\e[1G@",
|
16
|
-
"\e[1G*"
|
17
|
-
].join)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "uses custom frames from array" do
|
21
|
-
frames = [".", "o", "0", "@", "*"]
|
22
|
-
spinner = TTY::Spinner.new(frames: frames, output: output)
|
23
|
-
5.times { spinner.spin }
|
24
|
-
output.rewind
|
25
|
-
expect(output.read).to eq([
|
26
|
-
"\e[1G.",
|
27
|
-
"\e[1Go",
|
28
|
-
"\e[1G0",
|
29
|
-
"\e[1G@",
|
30
|
-
"\e[1G*"
|
31
|
-
].join)
|
32
|
-
end
|
33
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Spinner, ':hide_cursor' do
|
4
|
-
let(:output) { StringIO.new('', 'w+') }
|
5
|
-
|
6
|
-
it "hides cursor" do
|
7
|
-
spinner = TTY::Spinner.new(output: output, hide_cursor: true)
|
8
|
-
4.times { spinner.spin }
|
9
|
-
spinner.stop
|
10
|
-
output.rewind
|
11
|
-
expect(output.read).to eq([
|
12
|
-
"\e[?25l\e[1G|",
|
13
|
-
"\e[1G/",
|
14
|
-
"\e[1G-",
|
15
|
-
"\e[1G\\",
|
16
|
-
"\e[0m\e[2K",
|
17
|
-
"\e[1G\\\n",
|
18
|
-
"\e[?25h"
|
19
|
-
].join)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "restores cursor on success" do
|
23
|
-
spinner = TTY::Spinner.new(output: output, hide_cursor: true)
|
24
|
-
4.times { spinner.spin }
|
25
|
-
spinner.success('success')
|
26
|
-
output.rewind
|
27
|
-
expect(output.read).to eq([
|
28
|
-
"\e[?25l\e[1G|",
|
29
|
-
"\e[1G/",
|
30
|
-
"\e[1G-",
|
31
|
-
"\e[1G\\",
|
32
|
-
"\e[0m\e[2K",
|
33
|
-
"\e[1G\u2714 success\n",
|
34
|
-
"\e[?25h"
|
35
|
-
].join)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "restores cursor on error" do
|
39
|
-
spinner = TTY::Spinner.new(output: output, hide_cursor: true)
|
40
|
-
4.times { spinner.spin }
|
41
|
-
spinner.error('error')
|
42
|
-
output.rewind
|
43
|
-
expect(output.read).to eq([
|
44
|
-
"\e[?25l\e[1G|",
|
45
|
-
"\e[1G/",
|
46
|
-
"\e[1G-",
|
47
|
-
"\e[1G\\",
|
48
|
-
"\e[0m\e[2K",
|
49
|
-
"\e[1G\u2716 error\n",
|
50
|
-
"\e[?25h"
|
51
|
-
].join)
|
52
|
-
end
|
53
|
-
end
|
data/spec/unit/job_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Spinner, '#job' do
|
4
|
-
it "adds and executes job" do
|
5
|
-
spinner = TTY::Spinner.new("[:spinner] :title")
|
6
|
-
called = []
|
7
|
-
work = proc { |sp| called << sp }
|
8
|
-
spinner.job(&work)
|
9
|
-
|
10
|
-
spinner.execute_job
|
11
|
-
|
12
|
-
expect(called).to eq([spinner])
|
13
|
-
end
|
14
|
-
end
|
data/spec/unit/join_spec.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Spinner, '#join' do
|
4
|
-
let(:output) { StringIO.new('', 'w+') }
|
5
|
-
|
6
|
-
it "raises exception when not spinning" do
|
7
|
-
spinner = TTY::Spinner.new(output: output)
|
8
|
-
expect {
|
9
|
-
spinner.join
|
10
|
-
}.to raise_error(TTY::Spinner::NotSpinningError)
|
11
|
-
end
|
12
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
RSpec.describe TTY::Spinner::Multi, '#auto_spin' do
|
4
|
-
let(:output) { StringIO.new('', 'w+') }
|
5
|
-
|
6
|
-
it "doesn't auto spin top level spinner" do
|
7
|
-
spinners = TTY::Spinner::Multi.new("Top level spinner", output: output)
|
8
|
-
allow(spinners.top_spinner).to receive(:auto_spin)
|
9
|
-
|
10
|
-
spinners.auto_spin
|
11
|
-
|
12
|
-
expect(spinners.top_spinner).to_not have_received(:auto_spin)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "raises an exception when called without a top spinner" do
|
16
|
-
spinners = TTY::Spinner::Multi.new(output: output)
|
17
|
-
|
18
|
-
expect {
|
19
|
-
spinners.auto_spin
|
20
|
-
}.to raise_error(RuntimeError, /No top level spinner/)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "auto spins top level & child spinners with jobs" do
|
24
|
-
spinners = TTY::Spinner::Multi.new("top", output: output)
|
25
|
-
jobs = []
|
26
|
-
|
27
|
-
spinners.register("one") { |sp| jobs << 'one'; sp.success }
|
28
|
-
spinners.register("two") { |sp| jobs << 'two'; sp.success }
|
29
|
-
|
30
|
-
spinners.auto_spin
|
31
|
-
|
32
|
-
expect(jobs).to match_array(['one', 'two'])
|
33
|
-
end
|
34
|
-
end
|