rainbow 2.2.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -3
- data/.rubocop_todo.yml +29 -0
- data/.travis.yml +13 -11
- data/Changelog.md +52 -46
- data/Gemfile +9 -4
- data/Guardfile +0 -1
- data/README.markdown +33 -26
- data/Rakefile +5 -2
- data/appveyor.yml +40 -0
- data/lib/rainbow.rb +0 -13
- data/lib/rainbow/color.rb +22 -23
- data/lib/rainbow/ext/string.rb +2 -4
- data/lib/rainbow/global.rb +3 -1
- data/lib/rainbow/null_presenter.rb +81 -29
- data/lib/rainbow/presenter.rb +13 -13
- data/lib/rainbow/refinement.rb +12 -0
- data/lib/rainbow/string_utils.rb +5 -4
- data/lib/rainbow/version.rb +1 -1
- data/lib/rainbow/wrapper.rb +0 -2
- data/lib/rainbow/x11_color_names.rb +3 -4
- data/rainbow.gemspec +4 -8
- data/spec/integration/instance_spec.rb +1 -3
- data/spec/integration/rainbow_spec.rb +27 -30
- data/spec/integration/refinement_spec.rb +36 -0
- data/spec/integration/string_spec.rb +11 -14
- data/spec/integration/uncolor_spec.rb +14 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/presenter_shared_examples.rb +2 -2
- data/spec/unit/color_spec.rb +5 -10
- data/spec/unit/null_presenter_spec.rb +1 -2
- data/spec/unit/presenter_spec.rb +11 -13
- data/spec/unit/string_utils_spec.rb +34 -2
- data/spec/unit/wrapper_spec.rb +1 -3
- metadata +20 -31
- data/ext/mkrf_conf.rb +0 -22
- data/lib/rainbow/legacy.rb +0 -15
- data/spec/unit/namespace_spec.rb +0 -31
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rainbow'
|
3
|
+
|
4
|
+
RSpec.describe 'Rainbow refinement' do
|
5
|
+
before do
|
6
|
+
require 'rainbow/refinement'
|
7
|
+
|
8
|
+
class ScopeNotIncluded
|
9
|
+
def self.red_hello
|
10
|
+
'hello'.red
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ScopeIncluded
|
15
|
+
using Rainbow
|
16
|
+
def self.red_hello
|
17
|
+
'hello'.red
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'is not active by default' do
|
23
|
+
expect do
|
24
|
+
ScopeNotIncluded.red_hello
|
25
|
+
end.to raise_error(NoMethodError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'is available when used' do
|
29
|
+
expect(ScopeIncluded.red_hello).to eq(Rainbow('hello').red)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'respects disabled state' do
|
33
|
+
Rainbow.enabled = false
|
34
|
+
expect(ScopeIncluded.red_hello).to eq('hello')
|
35
|
+
end
|
36
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'rainbow/ext/string'
|
3
3
|
|
4
|
-
describe 'String mixin' do
|
5
|
-
|
4
|
+
RSpec.describe 'String mixin' do
|
6
5
|
before do
|
7
6
|
Rainbow.enabled = true
|
8
7
|
end
|
@@ -60,25 +59,23 @@ describe 'String mixin' do
|
|
60
59
|
end
|
61
60
|
|
62
61
|
context "when Rainbow is disabled" do
|
63
|
-
|
64
62
|
before do
|
65
63
|
Rainbow.enabled = false
|
66
64
|
end
|
67
65
|
|
68
66
|
it "allows chaining but doesn't wrap with escape codes" do
|
69
|
-
result = 'hello'
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
67
|
+
result = 'hello'
|
68
|
+
.foreground(:red)
|
69
|
+
.bright
|
70
|
+
.italic
|
71
|
+
.background('#ff8040')
|
72
|
+
.underline
|
73
|
+
.color(:blue)
|
74
|
+
.blink
|
75
|
+
.inverse
|
76
|
+
.hide
|
79
77
|
|
80
78
|
expect(result).to eq('hello')
|
81
79
|
end
|
82
80
|
end
|
83
|
-
|
84
81
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rainbow'
|
3
|
+
|
4
|
+
RSpec.describe 'uncolor method' do
|
5
|
+
|
6
|
+
it 'strips ansi color escape code' do
|
7
|
+
expect(Rainbow.uncolor("\e[35mhello\e[0mm")).to eq 'hellom'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'does not strip scroll down escape code' do
|
11
|
+
expect(Rainbow.uncolor("\e[1Thello")).to eq "\e[1Thello"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
shared_examples_for "presenter with shortcut color methods" do
|
2
|
-
[
|
1
|
+
RSpec.shared_examples_for "presenter with shortcut color methods" do
|
2
|
+
%i[black red green yellow blue magenta cyan white aqua].each do |name|
|
3
3
|
describe "##{name}" do
|
4
4
|
subject { presenter.public_send(name) }
|
5
5
|
|
data/spec/unit/color_spec.rb
CHANGED
@@ -2,9 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'rainbow/color'
|
3
3
|
|
4
4
|
module Rainbow
|
5
|
-
describe Color do
|
5
|
+
RSpec.describe Color do
|
6
6
|
describe '.build' do
|
7
|
-
|
8
7
|
subject { described_class.build(ground, values) }
|
9
8
|
|
10
9
|
let(:ground) { :foreground }
|
@@ -75,11 +74,10 @@ module Rainbow
|
|
75
74
|
expect { subject }.to raise_error(ArgumentError)
|
76
75
|
end
|
77
76
|
end
|
78
|
-
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
82
|
-
describe Color::Indexed do
|
80
|
+
RSpec.describe Color::Indexed do
|
83
81
|
let(:color) { described_class.new(ground, 5) }
|
84
82
|
|
85
83
|
describe '#codes' do
|
@@ -99,7 +97,7 @@ module Rainbow
|
|
99
97
|
end
|
100
98
|
end
|
101
99
|
|
102
|
-
describe Color::Named do
|
100
|
+
RSpec.describe Color::Named do
|
103
101
|
let(:color) { described_class.new(ground, name) }
|
104
102
|
|
105
103
|
describe '#codes' do
|
@@ -227,7 +225,7 @@ module Rainbow
|
|
227
225
|
end
|
228
226
|
end
|
229
227
|
|
230
|
-
describe Color::RGB do
|
228
|
+
RSpec.describe Color::RGB do
|
231
229
|
let(:color) { described_class.new(ground, r, g, b) }
|
232
230
|
|
233
231
|
describe '#codes' do
|
@@ -265,11 +263,10 @@ module Rainbow
|
|
265
263
|
expect { subject }.to raise_error(ArgumentError)
|
266
264
|
end
|
267
265
|
end
|
268
|
-
|
269
266
|
end
|
270
267
|
end
|
271
268
|
|
272
|
-
describe Color::X11Named do
|
269
|
+
RSpec.describe Color::X11Named do
|
273
270
|
let(:color) { described_class.new(ground, name) }
|
274
271
|
|
275
272
|
describe '#codes' do
|
@@ -294,8 +291,6 @@ module Rainbow
|
|
294
291
|
expect { subject }.to raise_error(ArgumentError)
|
295
292
|
end
|
296
293
|
end
|
297
|
-
|
298
294
|
end
|
299
295
|
end
|
300
|
-
|
301
296
|
end
|
data/spec/unit/presenter_spec.rb
CHANGED
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'rainbow/presenter'
|
3
3
|
|
4
4
|
module Rainbow
|
5
|
-
describe Presenter do
|
6
|
-
|
5
|
+
RSpec.describe Presenter do
|
7
6
|
let(:presenter) { described_class.new('hello') }
|
8
7
|
|
9
8
|
shared_examples_for "rainbow string method" do
|
@@ -20,16 +19,16 @@ module Rainbow
|
|
20
19
|
let(:color) { double('color', codes: [1, 2]) }
|
21
20
|
|
22
21
|
before do
|
23
|
-
allow(Color).to receive(:build)
|
24
|
-
with(:foreground, [:arg1, 'arg2']) { color }
|
22
|
+
allow(Color).to receive(:build)
|
23
|
+
.with(:foreground, [:arg1, 'arg2']) { color }
|
25
24
|
end
|
26
25
|
|
27
26
|
it_behaves_like "rainbow string method"
|
28
27
|
|
29
28
|
it 'wraps with color codes' do
|
30
29
|
subject
|
31
|
-
expect(StringUtils).to have_received(:wrap_with_sgr)
|
32
|
-
with('hello', [1, 2])
|
30
|
+
expect(StringUtils).to have_received(:wrap_with_sgr)
|
31
|
+
.with('hello', [1, 2])
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
@@ -37,16 +36,16 @@ module Rainbow
|
|
37
36
|
let(:color) { double('color', codes: [1, 2]) }
|
38
37
|
|
39
38
|
before do
|
40
|
-
allow(Color).to receive(:build)
|
41
|
-
with(:background, [:arg1, 'arg2']) { color }
|
39
|
+
allow(Color).to receive(:build)
|
40
|
+
.with(:background, [:arg1, 'arg2']) { color }
|
42
41
|
end
|
43
42
|
|
44
43
|
it_behaves_like "rainbow string method"
|
45
44
|
|
46
45
|
it 'wraps with color codes' do
|
47
46
|
subject
|
48
|
-
expect(StringUtils).to have_received(:wrap_with_sgr)
|
49
|
-
with('hello', [1, 2])
|
47
|
+
expect(StringUtils).to have_received(:wrap_with_sgr)
|
48
|
+
.with('hello', [1, 2])
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
@@ -146,8 +145,8 @@ module Rainbow
|
|
146
145
|
|
147
146
|
it 'wraps with 3 code' do
|
148
147
|
subject
|
149
|
-
expect(StringUtils).to have_received(:wrap_with_sgr)
|
150
|
-
with('hello', [3])
|
148
|
+
expect(StringUtils).to have_received(:wrap_with_sgr)
|
149
|
+
.with('hello', [3])
|
151
150
|
end
|
152
151
|
end
|
153
152
|
|
@@ -196,6 +195,5 @@ module Rainbow
|
|
196
195
|
end
|
197
196
|
|
198
197
|
it_behaves_like "presenter with shortcut color methods"
|
199
|
-
|
200
198
|
end
|
201
199
|
end
|
@@ -2,9 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'rainbow/string_utils'
|
3
3
|
|
4
4
|
module Rainbow
|
5
|
-
describe StringUtils do
|
5
|
+
RSpec.describe StringUtils do
|
6
6
|
describe '.wrap_with_sgr' do
|
7
|
-
|
8
7
|
subject { described_class.wrap_with_sgr(string, codes) }
|
9
8
|
|
10
9
|
let(:string) { 'hello' }
|
@@ -56,7 +55,40 @@ module Rainbow
|
|
56
55
|
expect(subject).to eq("\e[1;2m\e[3;4mhello\e[0m")
|
57
56
|
end
|
58
57
|
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.uncolor' do
|
61
|
+
subject { described_class.uncolor(string) }
|
62
|
+
|
63
|
+
context "when string with ansi color escape is passed" do
|
64
|
+
let(:string) do
|
65
|
+
rainbow = Rainbow.new
|
66
|
+
rainbow.enabled = true
|
67
|
+
rainbow.wrap('hello').
|
68
|
+
foreground(:red).
|
69
|
+
bright.
|
70
|
+
bold.
|
71
|
+
italic.
|
72
|
+
background('#ff8040').
|
73
|
+
underline.
|
74
|
+
color(:blue).
|
75
|
+
blink.
|
76
|
+
inverse.
|
77
|
+
hide
|
78
|
+
end
|
79
|
+
|
80
|
+
it "removes ansi color codes" do
|
81
|
+
expect(subject).to eq 'hello'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when string with scroll down ansi escape is passed" do
|
86
|
+
let(:string) { "\e[1Thello" }
|
59
87
|
|
88
|
+
it "does not remove ansi scroll down escape" do
|
89
|
+
expect(subject).to eq "\e[1Thello"
|
90
|
+
end
|
91
|
+
end
|
60
92
|
end
|
61
93
|
end
|
62
94
|
end
|
data/spec/unit/wrapper_spec.rb
CHANGED
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'rainbow/wrapper'
|
3
3
|
|
4
4
|
module Rainbow
|
5
|
-
describe Wrapper do
|
6
|
-
|
5
|
+
RSpec.describe Wrapper do
|
7
6
|
let(:wrapper) { described_class.new(enabled) }
|
8
7
|
|
9
8
|
it "is enabled by default" do
|
@@ -29,6 +28,5 @@ module Rainbow
|
|
29
28
|
it { should be_kind_of(Rainbow::NullPresenter) }
|
30
29
|
end
|
31
30
|
end
|
32
|
-
|
33
31
|
end
|
34
32
|
end
|
metadata
CHANGED
@@ -1,68 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rainbow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Kulik
|
8
|
+
- Olle Jonsson
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2017-
|
12
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
14
|
- !ruby/object:Gem::Dependency
|
28
15
|
name: bundler
|
29
16
|
requirement: !ruby/object:Gem::Requirement
|
30
17
|
requirements:
|
31
|
-
- - ~>
|
18
|
+
- - "~>"
|
32
19
|
- !ruby/object:Gem::Version
|
33
20
|
version: '1.3'
|
34
21
|
type: :development
|
35
22
|
prerelease: false
|
36
23
|
version_requirements: !ruby/object:Gem::Requirement
|
37
24
|
requirements:
|
38
|
-
- - ~>
|
25
|
+
- - "~>"
|
39
26
|
- !ruby/object:Gem::Version
|
40
27
|
version: '1.3'
|
41
28
|
description: Colorize printed text on ANSI terminals
|
42
29
|
email:
|
43
30
|
- m@ku1ik.com
|
44
31
|
executables: []
|
45
|
-
extensions:
|
46
|
-
- ext/mkrf_conf.rb
|
32
|
+
extensions: []
|
47
33
|
extra_rdoc_files: []
|
48
34
|
files:
|
49
|
-
- .gitignore
|
50
|
-
- .rubocop.yml
|
51
|
-
- .
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- ".rubocop_todo.yml"
|
38
|
+
- ".travis.yml"
|
52
39
|
- Changelog.md
|
53
40
|
- Gemfile
|
54
41
|
- Guardfile
|
55
42
|
- LICENSE
|
56
43
|
- README.markdown
|
57
44
|
- Rakefile
|
58
|
-
-
|
45
|
+
- appveyor.yml
|
59
46
|
- lib/rainbow.rb
|
60
47
|
- lib/rainbow/color.rb
|
61
48
|
- lib/rainbow/ext/string.rb
|
62
49
|
- lib/rainbow/global.rb
|
63
|
-
- lib/rainbow/legacy.rb
|
64
50
|
- lib/rainbow/null_presenter.rb
|
65
51
|
- lib/rainbow/presenter.rb
|
52
|
+
- lib/rainbow/refinement.rb
|
66
53
|
- lib/rainbow/string_utils.rb
|
67
54
|
- lib/rainbow/version.rb
|
68
55
|
- lib/rainbow/wrapper.rb
|
@@ -70,11 +57,12 @@ files:
|
|
70
57
|
- rainbow.gemspec
|
71
58
|
- spec/integration/instance_spec.rb
|
72
59
|
- spec/integration/rainbow_spec.rb
|
60
|
+
- spec/integration/refinement_spec.rb
|
73
61
|
- spec/integration/string_spec.rb
|
62
|
+
- spec/integration/uncolor_spec.rb
|
74
63
|
- spec/spec_helper.rb
|
75
64
|
- spec/support/presenter_shared_examples.rb
|
76
65
|
- spec/unit/color_spec.rb
|
77
|
-
- spec/unit/namespace_spec.rb
|
78
66
|
- spec/unit/null_presenter_spec.rb
|
79
67
|
- spec/unit/presenter_spec.rb
|
80
68
|
- spec/unit/string_utils_spec.rb
|
@@ -89,28 +77,29 @@ require_paths:
|
|
89
77
|
- lib
|
90
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
79
|
requirements:
|
92
|
-
- -
|
80
|
+
- - ">="
|
93
81
|
- !ruby/object:Gem::Version
|
94
|
-
version: 1.
|
82
|
+
version: 2.1.0
|
95
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
84
|
requirements:
|
97
|
-
- -
|
85
|
+
- - ">="
|
98
86
|
- !ruby/object:Gem::Version
|
99
87
|
version: '0'
|
100
88
|
requirements: []
|
101
89
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.6.11
|
103
91
|
signing_key:
|
104
92
|
specification_version: 4
|
105
93
|
summary: Colorize printed text on ANSI terminals
|
106
94
|
test_files:
|
107
95
|
- spec/integration/instance_spec.rb
|
108
96
|
- spec/integration/rainbow_spec.rb
|
97
|
+
- spec/integration/refinement_spec.rb
|
109
98
|
- spec/integration/string_spec.rb
|
99
|
+
- spec/integration/uncolor_spec.rb
|
110
100
|
- spec/spec_helper.rb
|
111
101
|
- spec/support/presenter_shared_examples.rb
|
112
102
|
- spec/unit/color_spec.rb
|
113
|
-
- spec/unit/namespace_spec.rb
|
114
103
|
- spec/unit/null_presenter_spec.rb
|
115
104
|
- spec/unit/presenter_spec.rb
|
116
105
|
- spec/unit/string_utils_spec.rb
|