rainbow 2.1.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Changelog.md +64 -36
- data/README.markdown +67 -175
- metadata +17 -51
- data/.gitignore +0 -17
- data/.rubocop.yml +0 -14
- data/.travis.yml +0 -11
- data/Gemfile +0 -23
- data/Guardfile +0 -9
- data/Rakefile +0 -6
- data/lib/rainbow/color.rb +0 -135
- data/lib/rainbow/ext/string.rb +0 -52
- data/lib/rainbow/global.rb +0 -21
- data/lib/rainbow/legacy.rb +0 -15
- data/lib/rainbow/null_presenter.rb +0 -30
- data/lib/rainbow/presenter.rb +0 -124
- data/lib/rainbow/string_utils.rb +0 -20
- data/lib/rainbow/version.rb +0 -3
- data/lib/rainbow/wrapper.rb +0 -22
- data/lib/rainbow/x11_color_names.rb +0 -152
- data/lib/rainbow.rb +0 -25
- data/rainbow.gemspec +0 -23
- 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 -168
- 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,168 +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 '#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
|
@@ -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
|