rainbow 1.1.4 → 1.99.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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +11 -0
- data/Gemfile +17 -0
- data/Guardfile +9 -0
- data/README.markdown +91 -48
- data/Rakefile +6 -0
- data/lib/rainbow.rb +14 -96
- data/lib/rainbow/color.rb +109 -0
- data/lib/rainbow/core.rb +16 -0
- data/lib/rainbow/legacy.rb +14 -0
- data/lib/rainbow/string.rb +50 -0
- data/lib/rainbow/string_utils.rb +23 -0
- data/lib/rainbow/version.rb +3 -0
- data/lib/rainbow/wrapper.rb +76 -0
- data/rainbow.gemspec +25 -0
- data/spec/integration/rainbow_spec.rb +132 -0
- data/spec/integration/string_spec.rb +50 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/color_spec.rb +244 -0
- data/spec/unit/namespace_spec.rb +31 -0
- data/spec/unit/string_utils_spec.rb +62 -0
- data/spec/unit/wrapper_spec.rb +149 -0
- metadata +86 -20
- data/lib/ansi_color.rb +0 -71
- data/lib/ansi_rgb.rb +0 -43
- data/test/rainbow_test.rb +0 -277
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'rainbow'
|
|
3
|
+
|
|
4
|
+
describe Sickill::Rainbow do
|
|
5
|
+
|
|
6
|
+
describe '.enabled' do
|
|
7
|
+
before do
|
|
8
|
+
::Rainbow.enabled = :nope
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'returns ::Rainbow.enabled' do
|
|
12
|
+
expect(Sickill::Rainbow.enabled).to eq(:nope)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '.enabled=' do
|
|
17
|
+
before do
|
|
18
|
+
allow(STDERR).to receive(:puts)
|
|
19
|
+
Sickill::Rainbow.enabled = :yep
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'sets ::Rainbow.enabled=' do
|
|
23
|
+
expect(::Rainbow.enabled).to eq(:yep)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'prints the deprecation notice' do
|
|
27
|
+
expect(STDERR).to have_received(:puts)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'rainbow/wrapper'
|
|
3
|
+
|
|
4
|
+
module Rainbow
|
|
5
|
+
describe Wrapper do
|
|
6
|
+
|
|
7
|
+
let(:wrapper) { described_class.new('hello') }
|
|
8
|
+
|
|
9
|
+
shared_examples_for "wrapper 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::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 }
|
|
73
|
+
|
|
74
|
+
it_behaves_like "wrapper method"
|
|
75
|
+
|
|
76
|
+
it 'wraps with 0 code' do
|
|
77
|
+
subject
|
|
78
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [0])
|
|
79
|
+
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
|
+
|
|
140
|
+
it_behaves_like "wrapper method"
|
|
141
|
+
|
|
142
|
+
it 'wraps with 8 code' do
|
|
143
|
+
subject
|
|
144
|
+
expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [8])
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
end
|
|
149
|
+
end
|
metadata
CHANGED
|
@@ -1,51 +1,117 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rainbow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 1.99.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Marcin Kulik
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
13
|
-
dependencies:
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
date: 2013-12-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: Colorize printed text on ANSI terminals
|
|
56
|
+
email:
|
|
57
|
+
- m@ku1ik.com
|
|
16
58
|
executables: []
|
|
17
59
|
extensions: []
|
|
18
60
|
extra_rdoc_files: []
|
|
19
61
|
files:
|
|
20
|
-
-
|
|
62
|
+
- .gitignore
|
|
63
|
+
- .travis.yml
|
|
21
64
|
- Changelog
|
|
65
|
+
- Gemfile
|
|
66
|
+
- Guardfile
|
|
22
67
|
- LICENSE
|
|
68
|
+
- README.markdown
|
|
69
|
+
- Rakefile
|
|
23
70
|
- lib/rainbow.rb
|
|
24
|
-
- lib/
|
|
25
|
-
- lib/
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
71
|
+
- lib/rainbow/color.rb
|
|
72
|
+
- lib/rainbow/core.rb
|
|
73
|
+
- lib/rainbow/legacy.rb
|
|
74
|
+
- lib/rainbow/string.rb
|
|
75
|
+
- lib/rainbow/string_utils.rb
|
|
76
|
+
- lib/rainbow/version.rb
|
|
77
|
+
- lib/rainbow/wrapper.rb
|
|
78
|
+
- rainbow.gemspec
|
|
79
|
+
- spec/integration/rainbow_spec.rb
|
|
80
|
+
- spec/integration/string_spec.rb
|
|
81
|
+
- spec/spec_helper.rb
|
|
82
|
+
- spec/unit/color_spec.rb
|
|
83
|
+
- spec/unit/namespace_spec.rb
|
|
84
|
+
- spec/unit/string_utils_spec.rb
|
|
85
|
+
- spec/unit/wrapper_spec.rb
|
|
86
|
+
homepage: https://github.com/sickill/rainbow
|
|
87
|
+
licenses:
|
|
88
|
+
- MIT
|
|
89
|
+
metadata: {}
|
|
29
90
|
post_install_message:
|
|
30
91
|
rdoc_options: []
|
|
31
92
|
require_paths:
|
|
32
93
|
- lib
|
|
33
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
-
none: false
|
|
35
95
|
requirements:
|
|
36
|
-
- -
|
|
96
|
+
- - '>='
|
|
37
97
|
- !ruby/object:Gem::Version
|
|
38
98
|
version: '0'
|
|
39
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
-
none: false
|
|
41
100
|
requirements:
|
|
42
|
-
- -
|
|
101
|
+
- - '>='
|
|
43
102
|
- !ruby/object:Gem::Version
|
|
44
103
|
version: '0'
|
|
45
104
|
requirements: []
|
|
46
105
|
rubyforge_project:
|
|
47
|
-
rubygems_version: 1.
|
|
106
|
+
rubygems_version: 2.1.11
|
|
48
107
|
signing_key:
|
|
49
|
-
specification_version:
|
|
50
|
-
summary:
|
|
51
|
-
test_files:
|
|
108
|
+
specification_version: 4
|
|
109
|
+
summary: Colorize printed text on ANSI terminals
|
|
110
|
+
test_files:
|
|
111
|
+
- spec/integration/rainbow_spec.rb
|
|
112
|
+
- spec/integration/string_spec.rb
|
|
113
|
+
- spec/spec_helper.rb
|
|
114
|
+
- spec/unit/color_spec.rb
|
|
115
|
+
- spec/unit/namespace_spec.rb
|
|
116
|
+
- spec/unit/string_utils_spec.rb
|
|
117
|
+
- spec/unit/wrapper_spec.rb
|
data/lib/ansi_color.rb
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'ansi_rgb')
|
|
2
|
-
|
|
3
|
-
module Sickill
|
|
4
|
-
module Rainbow
|
|
5
|
-
|
|
6
|
-
# Retrieve ANSI color code from a color name, an html color
|
|
7
|
-
# or an RGB color
|
|
8
|
-
class AnsiColor
|
|
9
|
-
|
|
10
|
-
# +ground+ is one of :foreground, :background
|
|
11
|
-
# +color+ is one of this 3 formats: name, html, rgb
|
|
12
|
-
def initialize(ground, *color)
|
|
13
|
-
@ground = ground
|
|
14
|
-
|
|
15
|
-
if color.size == 1
|
|
16
|
-
@color = color.first
|
|
17
|
-
else
|
|
18
|
-
@color = color
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Get the ANSI color code.
|
|
23
|
-
def code
|
|
24
|
-
case @color
|
|
25
|
-
when Symbol then code_from_name
|
|
26
|
-
when String then code_from_html
|
|
27
|
-
when Array then code_from_rgb
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
def code_from_name #:nodoc:
|
|
34
|
-
validate_color_name
|
|
35
|
-
|
|
36
|
-
TERM_COLORS[@color] + (@ground == :foreground ? 30 : 40)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def code_from_html #:nodoc:
|
|
40
|
-
@color = @color.gsub("#", "")
|
|
41
|
-
AnsiRgb.new(@ground, rgb_from_html).code
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def rgb_from_html #:nodoc:
|
|
45
|
-
red = @color[0..1].to_i(16)
|
|
46
|
-
green = @color[2..3].to_i(16)
|
|
47
|
-
blue = @color[4..5].to_i(16)
|
|
48
|
-
[red, green, blue]
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def code_from_rgb #:nodoc:
|
|
52
|
-
unless @color.size == 3
|
|
53
|
-
raise ArgumentError.new \
|
|
54
|
-
"Bad number of arguments for RGB color definition, should be 3"
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
AnsiRgb.new(@ground, @color).code
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def validate_color_name #:nodoc:
|
|
61
|
-
color_names = TERM_COLORS.keys
|
|
62
|
-
|
|
63
|
-
unless color_names.include?(@color)
|
|
64
|
-
raise ArgumentError.new \
|
|
65
|
-
"Unknown color name, valid names: #{color_names.join(', ')}"
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|