rainbow 2.2.1 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Changelog.md +60 -42
- data/README.markdown +64 -172
- data/lib/rainbow/color.rb +43 -32
- data/lib/rainbow/ext/string.rb +16 -4
- data/lib/rainbow/global.rb +5 -1
- data/lib/rainbow/null_presenter.rb +88 -26
- data/lib/rainbow/presenter.rb +35 -17
- data/lib/rainbow/refinement.rb +14 -0
- data/lib/rainbow/string_utils.rb +10 -8
- data/lib/rainbow/version.rb +3 -1
- data/lib/rainbow/wrapper.rb +2 -2
- data/lib/rainbow/x11_color_names.rb +5 -4
- data/lib/rainbow.rb +2 -13
- metadata +21 -46
- data/.gitignore +0 -17
- data/.rubocop.yml +0 -14
- data/.travis.yml +0 -22
- data/Gemfile +0 -23
- data/Guardfile +0 -9
- data/Rakefile +0 -6
- data/ext/mkrf_conf.rb +0 -22
- data/lib/rainbow/legacy.rb +0 -15
- data/rainbow.gemspec +0 -24
- data/spec/integration/instance_spec.rb +0 -35
- data/spec/integration/rainbow_spec.rb +0 -149
- data/spec/integration/string_spec.rb +0 -80
- data/spec/spec_helper.rb +0 -6
- data/spec/support/presenter_shared_examples.rb +0 -9
- data/spec/unit/color_spec.rb +0 -301
- data/spec/unit/namespace_spec.rb +0 -31
- data/spec/unit/null_presenter_spec.rb +0 -93
- data/spec/unit/presenter_spec.rb +0 -179
- data/spec/unit/string_utils_spec.rb +0 -62
- data/spec/unit/wrapper_spec.rb +0 -34
data/spec/unit/presenter_spec.rb
DELETED
@@ -1,179 +0,0 @@
|
|
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 '#bold' do
|
110
|
-
subject { presenter.bold }
|
111
|
-
|
112
|
-
it_behaves_like "rainbow string method"
|
113
|
-
|
114
|
-
it 'wraps with 1 code' do
|
115
|
-
subject
|
116
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1])
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe '#italic' do
|
121
|
-
subject { presenter.italic }
|
122
|
-
|
123
|
-
it_behaves_like "rainbow string method"
|
124
|
-
|
125
|
-
it 'wraps with 3 code' do
|
126
|
-
subject
|
127
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).
|
128
|
-
with('hello', [3])
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe '#underline' do
|
133
|
-
subject { presenter.underline }
|
134
|
-
|
135
|
-
it_behaves_like "rainbow string method"
|
136
|
-
|
137
|
-
it 'wraps with 4 code' do
|
138
|
-
subject
|
139
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [4])
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe '#blink' do
|
144
|
-
subject { presenter.blink }
|
145
|
-
|
146
|
-
it_behaves_like "rainbow string method"
|
147
|
-
|
148
|
-
it 'wraps with 5 code' do
|
149
|
-
subject
|
150
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [5])
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe '#inverse' do
|
155
|
-
subject { presenter.inverse }
|
156
|
-
|
157
|
-
it_behaves_like "rainbow string method"
|
158
|
-
|
159
|
-
it 'wraps with 7 code' do
|
160
|
-
subject
|
161
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [7])
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe '#hide' do
|
166
|
-
subject { presenter.hide }
|
167
|
-
|
168
|
-
it_behaves_like "rainbow string method"
|
169
|
-
|
170
|
-
it 'wraps with 8 code' do
|
171
|
-
subject
|
172
|
-
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [8])
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
it_behaves_like "presenter with shortcut color methods"
|
177
|
-
|
178
|
-
end
|
179
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rainbow/string_utils'
|
3
|
-
|
4
|
-
module Rainbow
|
5
|
-
describe StringUtils do
|
6
|
-
describe '.wrap_with_sgr' do
|
7
|
-
|
8
|
-
subject { described_class.wrap_with_sgr(string, codes) }
|
9
|
-
|
10
|
-
let(:string) { 'hello' }
|
11
|
-
let(:codes) { [1] }
|
12
|
-
|
13
|
-
it "doesn't mutate original string" do
|
14
|
-
string.freeze
|
15
|
-
expect(subject).to eq("\e[1mhello\e[0m")
|
16
|
-
expect(string).to eq('hello')
|
17
|
-
end
|
18
|
-
|
19
|
-
context "when subclass of String class given" do
|
20
|
-
class Stringgg < ::String; end
|
21
|
-
|
22
|
-
let(:string) { Stringgg.new('hello') }
|
23
|
-
|
24
|
-
it { should eq("\e[1mhello\e[0m") }
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when no codes given" do
|
28
|
-
let(:codes) { [] }
|
29
|
-
|
30
|
-
it "doesn't wrap the given string with any sgr sequence" do
|
31
|
-
expect(subject).to eq("hello")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when single code given" do
|
36
|
-
let(:codes) { [1] }
|
37
|
-
|
38
|
-
it "wraps the given string with sgr sequence for given codes" do
|
39
|
-
expect(subject).to eq("\e[1mhello\e[0m")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when multiple codes given" do
|
44
|
-
let(:codes) { [1, 2] }
|
45
|
-
|
46
|
-
it "wraps the given string with sgr sequence for given codes" do
|
47
|
-
expect(subject).to eq("\e[1;2mhello\e[0m")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when wrapping an already wrapped string" do
|
52
|
-
let(:string) { "\e[1;2mhello\e[0m" }
|
53
|
-
let(:codes) { [3, 4] }
|
54
|
-
|
55
|
-
it "wraps the given string with sgr sequence for given codes" do
|
56
|
-
expect(subject).to eq("\e[1;2m\e[3;4mhello\e[0m")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/spec/unit/wrapper_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rainbow/wrapper'
|
3
|
-
|
4
|
-
module Rainbow
|
5
|
-
describe Wrapper do
|
6
|
-
|
7
|
-
let(:wrapper) { described_class.new(enabled) }
|
8
|
-
|
9
|
-
it "is enabled by default" do
|
10
|
-
expect(described_class.new.enabled).to be(true)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#wrap' do
|
14
|
-
subject { wrapper.wrap(object) }
|
15
|
-
|
16
|
-
let(:object) { Object.new }
|
17
|
-
|
18
|
-
context "when wrapping is enabled" do
|
19
|
-
let(:enabled) { true }
|
20
|
-
|
21
|
-
it { should eq(object.to_s) }
|
22
|
-
it { should be_kind_of(Rainbow::Presenter) }
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when wrapping is disabled" do
|
26
|
-
let(:enabled) { false }
|
27
|
-
|
28
|
-
it { should eq(object.to_s) }
|
29
|
-
it { should be_kind_of(Rainbow::NullPresenter) }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|