infopark-user_io 0.2.1 → 1.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/infopark/user_io/version.rb +1 -1
- data/lib/infopark/user_io.rb +14 -0
- data/spec/progress_spec.rb +157 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a15ce6d28285af37873131efa6a552e1171dc387
|
4
|
+
data.tar.gz: 2a4db190e4f9006fe8243fd31c4708a63bbff4d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f167e78f28d95e5926003ee9397717613bb24c0ecf8f1d5d52f0e49c64ea544d4b0861ab59f13b5144c63d4a1303d0bb0613cff7738067ff5918a22eea466afe
|
7
|
+
data.tar.gz: 5124a94caedb71bfd0404a3f352f6bc2b9d8513158426a6fa4aeae38a6d481d13f97d923f99f4997e6fbc4b5f3b49bdb1265670e519813e544aa704f5d573225
|
data/.gitignore
CHANGED
data/lib/infopark/user_io.rb
CHANGED
@@ -16,30 +16,44 @@ class UserIO
|
|
16
16
|
def initialize(label, user_io)
|
17
17
|
@label = label
|
18
18
|
@user_io = user_io
|
19
|
+
@spinner = "-\\|/"
|
19
20
|
end
|
20
21
|
|
21
22
|
def start
|
22
23
|
unless @started
|
23
24
|
user_io.tell("#{label} ", newline: false)
|
24
25
|
@started = true
|
26
|
+
reset_spinner
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
def increment
|
29
31
|
raise ImplementationError, "progress not started yet" unless @started
|
30
32
|
user_io.tell(".", newline: false)
|
33
|
+
reset_spinner
|
31
34
|
end
|
32
35
|
|
33
36
|
def finish
|
34
37
|
if @started
|
35
38
|
user_io.tell("… ", newline: false)
|
36
39
|
user_io.tell("OK", color: :green, bright: true)
|
40
|
+
@started = false
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
44
|
+
def spin
|
45
|
+
raise ImplementationError, "progress not started yet" unless @started
|
46
|
+
user_io.tell("#{@spinner[@spin_pos % @spinner.size]}\b", newline: false)
|
47
|
+
@spin_pos += 1
|
48
|
+
end
|
49
|
+
|
40
50
|
private
|
41
51
|
|
42
52
|
attr_reader :label, :user_io
|
53
|
+
|
54
|
+
def reset_spinner
|
55
|
+
@spin_pos = 0
|
56
|
+
end
|
43
57
|
end
|
44
58
|
|
45
59
|
class << self
|
@@ -0,0 +1,157 @@
|
|
1
|
+
module Infopark
|
2
|
+
|
3
|
+
RSpec.describe UserIO::Progress do
|
4
|
+
COLOR_BRIGHT_GREEN = "\e[1;32m"
|
5
|
+
COLOR_NORMAL = "\e[22;39m"
|
6
|
+
|
7
|
+
let(:user_io) { UserIO.new }
|
8
|
+
|
9
|
+
subject(:progress) { UserIO::Progress.new("the label", user_io) }
|
10
|
+
|
11
|
+
before { allow($stdout).to receive(:write) }
|
12
|
+
|
13
|
+
describe "#start" do
|
14
|
+
subject(:start) { progress.start }
|
15
|
+
|
16
|
+
it "starts the progress" do
|
17
|
+
expect($stdout).to receive(:write).with("the label ")
|
18
|
+
start
|
19
|
+
end
|
20
|
+
|
21
|
+
context "if already started" do
|
22
|
+
before { progress.start }
|
23
|
+
|
24
|
+
it "does nothing" do
|
25
|
+
expect($stdout).to_not receive(:write)
|
26
|
+
start
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#increment" do
|
32
|
+
subject(:increment) { progress.increment }
|
33
|
+
|
34
|
+
context "on a started progress" do
|
35
|
+
before { progress.start }
|
36
|
+
|
37
|
+
it "increments" do
|
38
|
+
expect($stdout).to receive(:write).with(".")
|
39
|
+
increment
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "on a not started progress" do
|
44
|
+
it "fails" do
|
45
|
+
expect { increment }.to raise_error(/not started/)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "on a finished progress" do
|
50
|
+
before do
|
51
|
+
progress.start
|
52
|
+
progress.finish
|
53
|
+
end
|
54
|
+
|
55
|
+
it "fails" do
|
56
|
+
expect { increment }.to raise_error(/not started/)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#spin" do
|
62
|
+
subject(:spin) { progress.spin }
|
63
|
+
|
64
|
+
|
65
|
+
context "on a started progress" do
|
66
|
+
before { progress.start }
|
67
|
+
|
68
|
+
it "spins" do
|
69
|
+
expect($stdout).to receive(:write).with("-\b").ordered
|
70
|
+
progress.spin
|
71
|
+
expect($stdout).to receive(:write).with("\\\b").ordered
|
72
|
+
progress.spin
|
73
|
+
expect($stdout).to receive(:write).with("|\b").ordered
|
74
|
+
progress.spin
|
75
|
+
expect($stdout).to receive(:write).with("/\b").ordered
|
76
|
+
progress.spin
|
77
|
+
expect($stdout).to receive(:write).with("-\b").ordered
|
78
|
+
progress.spin
|
79
|
+
expect($stdout).to receive(:write).with("\\\b").ordered
|
80
|
+
progress.spin
|
81
|
+
expect($stdout).to receive(:write).with("|\b").ordered
|
82
|
+
progress.spin
|
83
|
+
expect($stdout).to receive(:write).with("/\b").ordered
|
84
|
+
progress.spin
|
85
|
+
end
|
86
|
+
|
87
|
+
it "starts spinning from begin when interrupted by an increment" do
|
88
|
+
expect($stdout).to receive(:write).with("-\b").ordered
|
89
|
+
progress.spin
|
90
|
+
expect($stdout).to receive(:write).with("\\\b").ordered
|
91
|
+
progress.spin
|
92
|
+
expect($stdout).to receive(:write).with(".").ordered
|
93
|
+
progress.increment
|
94
|
+
expect($stdout).to receive(:write).with("-\b").ordered
|
95
|
+
progress.spin
|
96
|
+
expect($stdout).to receive(:write).with("\\\b").ordered
|
97
|
+
progress.spin
|
98
|
+
expect($stdout).to receive(:write).with("|\b").ordered
|
99
|
+
progress.spin
|
100
|
+
expect($stdout).to receive(:write).with("/\b").ordered
|
101
|
+
progress.spin
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "on a not started progress" do
|
106
|
+
it "fails" do
|
107
|
+
expect { spin }.to raise_error(/not started/)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "on a finished progress" do
|
112
|
+
before do
|
113
|
+
progress.start
|
114
|
+
progress.finish
|
115
|
+
end
|
116
|
+
|
117
|
+
it "fails" do
|
118
|
+
expect { spin }.to raise_error(/not started/)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#finish" do
|
124
|
+
subject(:finish) { progress.finish }
|
125
|
+
|
126
|
+
context "on a started progress" do
|
127
|
+
before { progress.start }
|
128
|
+
|
129
|
+
it "finishes" do
|
130
|
+
expect($stdout).to receive(:write).with("… ")
|
131
|
+
expect($stdout).to receive(:write).with("#{COLOR_BRIGHT_GREEN}OK#{COLOR_NORMAL}\n")
|
132
|
+
finish
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "on a not started progress" do
|
137
|
+
it "does nothing" do
|
138
|
+
expect($stdout).to_not receive(:write)
|
139
|
+
finish
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "on a finished progress" do
|
144
|
+
before do
|
145
|
+
progress.start
|
146
|
+
progress.finish
|
147
|
+
end
|
148
|
+
|
149
|
+
it "does nothing" do
|
150
|
+
expect($stdout).to_not receive(:write)
|
151
|
+
finish
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark-user_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tilo Prütz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/infopark/user_io.rb
|
67
67
|
- lib/infopark/user_io/global.rb
|
68
68
|
- lib/infopark/user_io/version.rb
|
69
|
+
- spec/progress_spec.rb
|
69
70
|
- spec/spec_helper.rb
|
70
71
|
- spec/user_io/global_spec.rb
|
71
72
|
- spec/user_io_spec.rb
|
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
93
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.6.13
|
94
95
|
signing_key:
|
95
96
|
specification_version: 4
|
96
97
|
summary: A utility lib to interact with the user on the command line.
|