rainbow 1.99.0 → 1.99.1
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/.rubocop.yml +14 -0
- data/.travis.yml +0 -1
- data/Changelog.md +59 -0
- data/Gemfile +2 -2
- data/Guardfile +1 -1
- data/README.markdown +91 -35
- data/lib/rainbow.rb +18 -19
- data/lib/rainbow/color.rb +28 -22
- data/lib/rainbow/ext/string.rb +52 -0
- data/lib/rainbow/global.rb +21 -0
- data/lib/rainbow/legacy.rb +2 -1
- data/lib/rainbow/null_presenter.rb +30 -0
- data/lib/rainbow/presenter.rb +113 -0
- data/lib/rainbow/version.rb +1 -1
- data/lib/rainbow/wrapper.rb +12 -66
- data/rainbow.gemspec +9 -9
- data/spec/integration/instance_spec.rb +35 -0
- data/spec/integration/rainbow_spec.rb +13 -6
- data/spec/integration/string_spec.rb +27 -1
- data/spec/spec_helper.rb +1 -5
- data/spec/support/presenter_shared_examples.rb +9 -0
- data/spec/unit/null_presenter_spec.rb +93 -0
- data/spec/unit/presenter_spec.rb +168 -0
- data/spec/unit/wrapper_spec.rb +11 -132
- metadata +17 -6
- data/Changelog +0 -3
- data/lib/rainbow/core.rb +0 -16
- data/lib/rainbow/string.rb +0 -50
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rainbow/null_presenter'
|
3
|
+
|
4
|
+
module Rainbow
|
5
|
+
describe NullPresenter do
|
6
|
+
|
7
|
+
let(:presenter) { described_class.new('hello') }
|
8
|
+
|
9
|
+
shared_examples_for "rainbow null string method" do
|
10
|
+
it "doesn't wrap the text with any sgr sequence" do
|
11
|
+
expect(subject).to eq('hello')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns an instance of Rainbow::NullPresenter" do
|
15
|
+
expect(subject).to be_kind_of(Rainbow::NullPresenter)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#color' do
|
20
|
+
subject { presenter.color(:arg1, 'arg2') }
|
21
|
+
|
22
|
+
it_behaves_like "rainbow null string method"
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#foreground' do
|
26
|
+
subject { presenter.foreground(:arg1, 'arg2') }
|
27
|
+
|
28
|
+
it_behaves_like "rainbow null string method"
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#fg' do
|
32
|
+
subject { presenter.fg(:arg1, 'arg2') }
|
33
|
+
|
34
|
+
it_behaves_like "rainbow null string method"
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#background' do
|
38
|
+
subject { presenter.background(:arg1, 'arg2') }
|
39
|
+
|
40
|
+
it_behaves_like "rainbow null string method"
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#bg' do
|
44
|
+
subject { presenter.bg(:arg1, 'arg2') }
|
45
|
+
|
46
|
+
it_behaves_like "rainbow null string method"
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#reset' do
|
50
|
+
subject { presenter.reset }
|
51
|
+
|
52
|
+
it_behaves_like "rainbow null string method"
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#bright' do
|
56
|
+
subject { presenter.bright }
|
57
|
+
|
58
|
+
it_behaves_like "rainbow null string method"
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#italic' do
|
62
|
+
subject { presenter.italic }
|
63
|
+
|
64
|
+
it_behaves_like "rainbow null string method"
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#underline' do
|
68
|
+
subject { presenter.underline }
|
69
|
+
|
70
|
+
it_behaves_like "rainbow null string method"
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#blink' do
|
74
|
+
subject { presenter.blink }
|
75
|
+
|
76
|
+
it_behaves_like "rainbow null string method"
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#inverse' do
|
80
|
+
subject { presenter.inverse }
|
81
|
+
|
82
|
+
it_behaves_like "rainbow null string method"
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#hide' do
|
86
|
+
subject { presenter.hide }
|
87
|
+
|
88
|
+
it_behaves_like "rainbow null string method"
|
89
|
+
end
|
90
|
+
|
91
|
+
it_behaves_like "presenter with shortcut color methods"
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rainbow/presenter'
|
3
|
+
|
4
|
+
module Rainbow
|
5
|
+
describe Presenter do
|
6
|
+
|
7
|
+
let(:presenter) { described_class.new('hello') }
|
8
|
+
|
9
|
+
shared_examples_for "rainbow string method" do
|
10
|
+
it "wraps the text with a sgr sequence" do
|
11
|
+
expect(subject).to eq('[hello]')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns an instance of Rainbow::Presenter" do
|
15
|
+
expect(subject).to be_kind_of(Rainbow::Presenter)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
shared_examples_for "text color method" do
|
20
|
+
let(:color) { double('color', codes: [1, 2]) }
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(Color).to receive(:build).
|
24
|
+
with(:foreground, [:arg1, 'arg2']) { color }
|
25
|
+
end
|
26
|
+
|
27
|
+
it_behaves_like "rainbow string method"
|
28
|
+
|
29
|
+
it 'wraps with color codes' do
|
30
|
+
subject
|
31
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).
|
32
|
+
with('hello', [1, 2])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
shared_examples_for "text background method" do
|
37
|
+
let(:color) { double('color', codes: [1, 2]) }
|
38
|
+
|
39
|
+
before do
|
40
|
+
allow(Color).to receive(:build).
|
41
|
+
with(:background, [:arg1, 'arg2']) { color }
|
42
|
+
end
|
43
|
+
|
44
|
+
it_behaves_like "rainbow string method"
|
45
|
+
|
46
|
+
it 'wraps with color codes' do
|
47
|
+
subject
|
48
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).
|
49
|
+
with('hello', [1, 2])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
before do
|
54
|
+
allow(StringUtils).to receive(:wrap_with_sgr) { '[hello]' }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#color' do
|
58
|
+
subject { presenter.color(:arg1, 'arg2') }
|
59
|
+
|
60
|
+
it_behaves_like "text color method"
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#foreground' do
|
64
|
+
subject { presenter.foreground(:arg1, 'arg2') }
|
65
|
+
|
66
|
+
it_behaves_like "text color method"
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#fg' do
|
70
|
+
subject { presenter.fg(:arg1, 'arg2') }
|
71
|
+
|
72
|
+
it_behaves_like "text color method"
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#background' do
|
76
|
+
subject { presenter.background(:arg1, 'arg2') }
|
77
|
+
|
78
|
+
it_behaves_like "text background method"
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#bg' do
|
82
|
+
subject { presenter.bg(:arg1, 'arg2') }
|
83
|
+
|
84
|
+
it_behaves_like "text background method"
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#reset' do
|
88
|
+
subject { presenter.reset }
|
89
|
+
|
90
|
+
it_behaves_like "rainbow string method"
|
91
|
+
|
92
|
+
it 'wraps with 0 code' do
|
93
|
+
subject
|
94
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [0])
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#bright' do
|
99
|
+
subject { presenter.bright }
|
100
|
+
|
101
|
+
it_behaves_like "rainbow string method"
|
102
|
+
|
103
|
+
it 'wraps with 1 code' do
|
104
|
+
subject
|
105
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#italic' do
|
110
|
+
subject { presenter.italic }
|
111
|
+
|
112
|
+
it_behaves_like "rainbow string method"
|
113
|
+
|
114
|
+
it 'wraps with 3 code' do
|
115
|
+
subject
|
116
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).
|
117
|
+
with('hello', [3])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#underline' do
|
122
|
+
subject { presenter.underline }
|
123
|
+
|
124
|
+
it_behaves_like "rainbow string method"
|
125
|
+
|
126
|
+
it 'wraps with 4 code' do
|
127
|
+
subject
|
128
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [4])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe '#blink' do
|
133
|
+
subject { presenter.blink }
|
134
|
+
|
135
|
+
it_behaves_like "rainbow string method"
|
136
|
+
|
137
|
+
it 'wraps with 5 code' do
|
138
|
+
subject
|
139
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [5])
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#inverse' do
|
144
|
+
subject { presenter.inverse }
|
145
|
+
|
146
|
+
it_behaves_like "rainbow string method"
|
147
|
+
|
148
|
+
it 'wraps with 7 code' do
|
149
|
+
subject
|
150
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [7])
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#hide' do
|
155
|
+
subject { presenter.hide }
|
156
|
+
|
157
|
+
it_behaves_like "rainbow string method"
|
158
|
+
|
159
|
+
it 'wraps with 8 code' do
|
160
|
+
subject
|
161
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [8])
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it_behaves_like "presenter with shortcut color methods"
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
data/spec/unit/wrapper_spec.rb
CHANGED
@@ -4,144 +4,23 @@ require 'rainbow/wrapper'
|
|
4
4
|
module Rainbow
|
5
5
|
describe Wrapper do
|
6
6
|
|
7
|
-
let(:wrapper) { described_class.new(
|
7
|
+
let(:wrapper) { described_class.new(enabled) }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
expect(subject).to eq('[hello]')
|
12
|
-
end
|
13
|
-
|
14
|
-
it "returns an instance of Rainbow::Wrapper" do
|
15
|
-
expect(subject).to be_kind_of(Rainbow::Wrapper)
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when Rainbow is disabled" do
|
19
|
-
before do
|
20
|
-
allow(Rainbow).to receive(:enabled) { false }
|
21
|
-
end
|
22
|
-
|
23
|
-
it "doesn't wrap the text" do
|
24
|
-
expect(subject).to eq('hello')
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns an instance of Rainbow::Wrapper" do
|
28
|
-
expect(subject).to be_kind_of(Rainbow::Wrapper)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
before do
|
34
|
-
allow(StringUtils).to receive(:wrap_with_sgr) { '[hello]' }
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#foreground' do
|
38
|
-
subject { wrapper.foreground(:arg1, 'arg2') }
|
39
|
-
|
40
|
-
let(:color) { double('color', :codes => [1, 2]) }
|
41
|
-
|
42
|
-
before do
|
43
|
-
allow(Color).to receive(:build).with(:foreground, [:arg1, 'arg2']) { color }
|
44
|
-
end
|
45
|
-
|
46
|
-
it_behaves_like "wrapper method"
|
47
|
-
|
48
|
-
it 'wraps with color codes' do
|
49
|
-
subject
|
50
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1, 2])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '#background' do
|
55
|
-
subject { wrapper.background(:arg1, 'arg2') }
|
56
|
-
|
57
|
-
let(:color) { double('color', :codes => [1, 2]) }
|
58
|
-
|
59
|
-
before do
|
60
|
-
allow(Color).to receive(:build).with(:background, [:arg1, 'arg2']) { color }
|
61
|
-
end
|
62
|
-
|
63
|
-
it_behaves_like "wrapper method"
|
64
|
-
|
65
|
-
it 'wraps with color codes' do
|
66
|
-
subject
|
67
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1, 2])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#reset' do
|
72
|
-
subject { wrapper.reset }
|
9
|
+
describe '#wrap' do
|
10
|
+
subject { wrapper.wrap('hello') }
|
73
11
|
|
74
|
-
|
12
|
+
context "when wrapping is enabled" do
|
13
|
+
let(:enabled) { true }
|
75
14
|
|
76
|
-
|
77
|
-
|
78
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [0])
|
15
|
+
it { should eq('hello') }
|
16
|
+
it { should be_kind_of(Rainbow::Presenter) }
|
79
17
|
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe '#bright' do
|
83
|
-
subject { wrapper.bright }
|
84
|
-
|
85
|
-
it_behaves_like "wrapper method"
|
86
|
-
|
87
|
-
it 'wraps with 1 code' do
|
88
|
-
subject
|
89
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1])
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe '#italic' do
|
94
|
-
subject { wrapper.italic }
|
95
|
-
|
96
|
-
it_behaves_like "wrapper method"
|
97
|
-
|
98
|
-
it 'wraps with 3 code' do
|
99
|
-
subject
|
100
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [3])
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe '#underline' do
|
105
|
-
subject { wrapper.underline }
|
106
|
-
|
107
|
-
it_behaves_like "wrapper method"
|
108
|
-
|
109
|
-
it 'wraps with 4 code' do
|
110
|
-
subject
|
111
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [4])
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe '#blink' do
|
116
|
-
subject { wrapper.blink }
|
117
|
-
|
118
|
-
it_behaves_like "wrapper method"
|
119
|
-
|
120
|
-
it 'wraps with 5 code' do
|
121
|
-
subject
|
122
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [5])
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '#inverse' do
|
127
|
-
subject { wrapper.inverse }
|
128
|
-
|
129
|
-
it_behaves_like "wrapper method"
|
130
|
-
|
131
|
-
it 'wraps with 7 code' do
|
132
|
-
subject
|
133
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [7])
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe '#hide' do
|
138
|
-
subject { wrapper.hide }
|
139
18
|
|
140
|
-
|
19
|
+
context "when wrapping is disabled" do
|
20
|
+
let(:enabled) { false }
|
141
21
|
|
142
|
-
|
143
|
-
|
144
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [8])
|
22
|
+
it { should eq('hello') }
|
23
|
+
it { should be_kind_of(Rainbow::NullPresenter) }
|
145
24
|
end
|
146
25
|
end
|
147
26
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rainbow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.99.
|
4
|
+
version: 1.99.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Kulik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,8 +60,9 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
|
+
- .rubocop.yml
|
63
64
|
- .travis.yml
|
64
|
-
- Changelog
|
65
|
+
- Changelog.md
|
65
66
|
- Gemfile
|
66
67
|
- Guardfile
|
67
68
|
- LICENSE
|
@@ -69,18 +70,24 @@ files:
|
|
69
70
|
- Rakefile
|
70
71
|
- lib/rainbow.rb
|
71
72
|
- lib/rainbow/color.rb
|
72
|
-
- lib/rainbow/
|
73
|
+
- lib/rainbow/ext/string.rb
|
74
|
+
- lib/rainbow/global.rb
|
73
75
|
- lib/rainbow/legacy.rb
|
74
|
-
- lib/rainbow/
|
76
|
+
- lib/rainbow/null_presenter.rb
|
77
|
+
- lib/rainbow/presenter.rb
|
75
78
|
- lib/rainbow/string_utils.rb
|
76
79
|
- lib/rainbow/version.rb
|
77
80
|
- lib/rainbow/wrapper.rb
|
78
81
|
- rainbow.gemspec
|
82
|
+
- spec/integration/instance_spec.rb
|
79
83
|
- spec/integration/rainbow_spec.rb
|
80
84
|
- spec/integration/string_spec.rb
|
81
85
|
- spec/spec_helper.rb
|
86
|
+
- spec/support/presenter_shared_examples.rb
|
82
87
|
- spec/unit/color_spec.rb
|
83
88
|
- spec/unit/namespace_spec.rb
|
89
|
+
- spec/unit/null_presenter_spec.rb
|
90
|
+
- spec/unit/presenter_spec.rb
|
84
91
|
- spec/unit/string_utils_spec.rb
|
85
92
|
- spec/unit/wrapper_spec.rb
|
86
93
|
homepage: https://github.com/sickill/rainbow
|
@@ -95,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
102
|
requirements:
|
96
103
|
- - '>='
|
97
104
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
105
|
+
version: 1.9.2
|
99
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
107
|
requirements:
|
101
108
|
- - '>='
|
@@ -108,10 +115,14 @@ signing_key:
|
|
108
115
|
specification_version: 4
|
109
116
|
summary: Colorize printed text on ANSI terminals
|
110
117
|
test_files:
|
118
|
+
- spec/integration/instance_spec.rb
|
111
119
|
- spec/integration/rainbow_spec.rb
|
112
120
|
- spec/integration/string_spec.rb
|
113
121
|
- spec/spec_helper.rb
|
122
|
+
- spec/support/presenter_shared_examples.rb
|
114
123
|
- spec/unit/color_spec.rb
|
115
124
|
- spec/unit/namespace_spec.rb
|
125
|
+
- spec/unit/null_presenter_spec.rb
|
126
|
+
- spec/unit/presenter_spec.rb
|
116
127
|
- spec/unit/string_utils_spec.rb
|
117
128
|
- spec/unit/wrapper_spec.rb
|