pastel 0.6.1 → 0.8.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 +5 -5
- data/CHANGELOG.md +66 -12
- data/README.md +38 -29
- data/lib/pastel/alias_importer.rb +9 -7
- data/lib/pastel/ansi.rb +2 -2
- data/lib/pastel/color.rb +64 -24
- data/lib/pastel/color_parser.rb +24 -18
- data/lib/pastel/color_resolver.rb +3 -1
- data/lib/pastel/decorator_chain.rb +52 -8
- data/lib/pastel/delegator.rb +57 -26
- data/lib/pastel/detached.rb +41 -5
- data/lib/pastel/version.rb +2 -2
- data/lib/pastel.rb +17 -19
- metadata +35 -104
- data/.gitignore +0 -22
- data/.rspec +0 -3
- data/.travis.yml +0 -25
- data/Gemfile +0 -15
- data/Rakefile +0 -8
- data/assets/pastel_logo.png +0 -0
- data/assets/screenshot.png +0 -0
- data/benchmarks/nesting_speed.rb +0 -41
- data/benchmarks/speed.rb +0 -45
- data/examples/palette.rb +0 -14
- data/pastel.gemspec +0 -26
- data/spec/spec_helper.rb +0 -45
- data/spec/unit/alias_color_spec.rb +0 -24
- data/spec/unit/alias_importer_spec.rb +0 -29
- data/spec/unit/color/alias_color_spec.rb +0 -40
- data/spec/unit/color/code_spec.rb +0 -24
- data/spec/unit/color/colored_spec.rb +0 -15
- data/spec/unit/color/decorate_spec.rb +0 -79
- data/spec/unit/color/equal_spec.rb +0 -22
- data/spec/unit/color/lookup_spec.rb +0 -17
- data/spec/unit/color/new_spec.rb +0 -10
- data/spec/unit/color/strip_spec.rb +0 -56
- data/spec/unit/color/styles_spec.rb +0 -10
- data/spec/unit/color/valid_spec.rb +0 -19
- data/spec/unit/color_parser_spec.rb +0 -67
- data/spec/unit/decorate_dsl_spec.rb +0 -94
- data/spec/unit/decorator_chain_spec.rb +0 -47
- data/spec/unit/delegator_spec.rb +0 -38
- data/spec/unit/detach_spec.rb +0 -48
- data/spec/unit/new_spec.rb +0 -52
- data/spec/unit/respond_to_spec.rb +0 -17
- data/spec/unit/undecorate_spec.rb +0 -12
- data/tasks/console.rake +0 -10
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
RSpec.describe Pastel, 'coloring dsl' do
|
|
4
|
-
|
|
5
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
|
6
|
-
|
|
7
|
-
it "colors string" do
|
|
8
|
-
expect(pastel.red("unicorn")).to eq("\e[31municorn\e[0m")
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "allows to specify variable number of arguments" do
|
|
12
|
-
expect(pastel.red("unicorn", "running")).to eq("\e[31municornrunning\e[0m")
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "combines colored strings with regular ones" do
|
|
16
|
-
expect(pastel.red("Unicorns") + ' will rule ' + pastel.green('the World!')).
|
|
17
|
-
to eq("\e[31mUnicorns\e[0m will rule \e[32mthe World!\e[0m")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "composes two color strings " do
|
|
21
|
-
expect(pastel.red.on_green("unicorn")).to eq("\e[31;42municorn\e[0m")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "composes three color strings" do
|
|
25
|
-
expect(pastel.red.on_green.underline("unicorn")).
|
|
26
|
-
to eq("\e[31;42;4municorn\e[0m")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "combines colored composed strings with regular ones" do
|
|
30
|
-
expect(pastel.red.on_green("Unicorns") + ' will rule ' +
|
|
31
|
-
pastel.green.on_red('the World!')).
|
|
32
|
-
to eq("\e[31;42mUnicorns\e[0m will rule \e[32;41mthe World!\e[0m")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "allows one level nesting" do
|
|
36
|
-
expect(pastel.red("Unicorn" + pastel.blue("rule!"))).
|
|
37
|
-
to eq("\e[31mUnicorn\e[34mrule!\e[0m\e[0m")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "allows to nest mixed styles" do
|
|
41
|
-
expect(pastel.red("Unicorn" + pastel.green.on_yellow.underline('running') + '!')).
|
|
42
|
-
to eq("\e[31mUnicorn\e[32;43;4mrunning\e[0m\e[31m!\e[0m")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "allows for deep nesting" do
|
|
46
|
-
expect(pastel.red('r' + pastel.green('g' + pastel.yellow('y') + 'g') + 'r')).
|
|
47
|
-
to eq("\e[31mr\e[32mg\e[33my\e[0m\e[32mg\e[0m\e[31mr\e[0m")
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "allows for variable nested arguments" do
|
|
51
|
-
expect(pastel.red('r', pastel.green('g'), 'r')).
|
|
52
|
-
to eq("\e[31mr\e[32mg\e[0m\e[31mr\e[0m")
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "nests color foreground & background" do
|
|
56
|
-
expect(pastel.on_red('foo', pastel.green('bar'), 'foo')).
|
|
57
|
-
to eq("\e[41mfoo\e[32mbar\e[0m\e[41mfoo\e[0m")
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "allows to nest styles within block" do
|
|
61
|
-
string = pastel.red.on_green('Unicorns' +
|
|
62
|
-
pastel.green.on_red('will ', 'dominate' + pastel.yellow('the world!')))
|
|
63
|
-
|
|
64
|
-
expect(pastel.red.on_green('Unicorns') do
|
|
65
|
-
green.on_red('will ', 'dominate') do
|
|
66
|
-
yellow('the world!')
|
|
67
|
-
end
|
|
68
|
-
end).to eq(string)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "doesn't decorate nil" do
|
|
72
|
-
expect(pastel.red(nil)).to eq('')
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "doesn't apply styles to empty string" do
|
|
76
|
-
expect(pastel.red('')).to eq('')
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it "applies styles to empty with width more than 1" do
|
|
80
|
-
expect(pastel.red(' ')).to eq("\e[31m \e[0m")
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "raises error when chained with unrecognized color" do
|
|
84
|
-
expect {
|
|
85
|
-
pastel.unknown.on_red('unicorn')
|
|
86
|
-
}.to raise_error(Pastel::InvalidAttributeNameError)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "raises error when doesn't recognize color" do
|
|
90
|
-
expect {
|
|
91
|
-
pastel.unknown('unicorn')
|
|
92
|
-
}.to raise_error(Pastel::InvalidAttributeNameError)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
RSpec.describe Pastel::DecoratorChain do
|
|
4
|
-
it "is enumerable" do
|
|
5
|
-
expect(described_class.new).to be_a(Enumerable)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
it "is equatable" do
|
|
9
|
-
expect(described_class.new).to be_a(Equatable)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe ".each" do
|
|
13
|
-
it "yields each decorator" do
|
|
14
|
-
first = double('first')
|
|
15
|
-
second = double('second')
|
|
16
|
-
chain = described_class.new.add(first).add(second)
|
|
17
|
-
yielded = []
|
|
18
|
-
|
|
19
|
-
expect {
|
|
20
|
-
chain.each { |decorator| yielded << decorator }
|
|
21
|
-
}.to change { yielded }.from([]).to([first, second])
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe ".==" do
|
|
26
|
-
it "is equivalent with the same decorator" do
|
|
27
|
-
expect(described_class.new.add(:foo).add(:bar)).
|
|
28
|
-
to eq(described_class.new.add(:foo).add(:bar))
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "is not equivalent with different decorator" do
|
|
32
|
-
expect(described_class.new.add(:foo).add(:bar)).
|
|
33
|
-
not_to eq(described_class.new.add(:foo).add(:baz))
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "is not equivalent to another type" do
|
|
37
|
-
expect(described_class.new.add(:foo).add(:bar)).
|
|
38
|
-
not_to eq(:other)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe ".inspect" do
|
|
43
|
-
it "displays object information" do
|
|
44
|
-
expect(described_class.new.inspect).to match(/decorators=\[\]/)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
data/spec/unit/delegator_spec.rb
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
RSpec.describe Pastel::Delegator do
|
|
4
|
-
|
|
5
|
-
it "returns delegator for color without argument" do
|
|
6
|
-
pastel = Pastel.new(enabled: true)
|
|
7
|
-
expect(pastel.red).to be_a(Pastel::Delegator)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe ".inspect" do
|
|
11
|
-
it "inspects delegator styles chain" do
|
|
12
|
-
chain = ['red', 'on_green']
|
|
13
|
-
delegator = described_class.new(:resolver, chain)
|
|
14
|
-
allow(delegator).to receive(:styles).and_return({red: 31, on_green: 42})
|
|
15
|
-
expect(delegator.inspect).to eq("#<Pastel @styles=[\"red\", \"on_green\"]>")
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe ".respond_to_missing?" do
|
|
20
|
-
context 'for a method defined on' do
|
|
21
|
-
it "returns true" do
|
|
22
|
-
resolver = double(:resolver)
|
|
23
|
-
chain = double(:chain)
|
|
24
|
-
decorator = described_class.new(resolver, chain)
|
|
25
|
-
expect(decorator.method(:styles)).not_to be_nil
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "for an undefined method " do
|
|
30
|
-
it "returns false" do
|
|
31
|
-
resolver = double(:resolver, color: true)
|
|
32
|
-
chain = double(:chain)
|
|
33
|
-
decorator = described_class.new(resolver, chain)
|
|
34
|
-
expect { decorator.method(:unknown) }.to raise_error(NameError)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
data/spec/unit/detach_spec.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
RSpec.describe Pastel, '.detach' do
|
|
4
|
-
|
|
5
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
|
6
|
-
|
|
7
|
-
it "creates detached instance" do
|
|
8
|
-
error = pastel.red.bold.detach
|
|
9
|
-
expect(error).to be_a(Pastel::Detached)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "ensures instance is immutable" do
|
|
13
|
-
error = pastel.red.detach
|
|
14
|
-
expect(error.frozen?).to be(true)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "detaches colors combination" do
|
|
18
|
-
error = pastel.red.bold.detach
|
|
19
|
-
expect(error.call('unicorn')).to eq("\e[31;1municorn\e[0m")
|
|
20
|
-
expect(error.call('error')).to eq("\e[31;1merror\e[0m")
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "allows array like access" do
|
|
24
|
-
error = pastel.red.bold.detach
|
|
25
|
-
expect(error['unicorn']).to eq("\e[31;1municorn\e[0m")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "allows alternative call invocation" do
|
|
29
|
-
error = pastel.red.bold.detach
|
|
30
|
-
expect(error.('unicorn')).to eq("\e[31;1municorn\e[0m")
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "calls detached colors with no arguments" do
|
|
34
|
-
warning = pastel.yellow.detach
|
|
35
|
-
expect(warning.call('')).to eq('')
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "inspects detached colors" do
|
|
39
|
-
warning = pastel.yellow.bold.detach
|
|
40
|
-
expect(warning.inspect).to eq('#<Pastel::Detached styles=[:yellow, :bold]>')
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "accepts multiple strings" do
|
|
44
|
-
error = pastel.red.bold.detach
|
|
45
|
-
expect(error.call('Unicorns', ' run ', 'wild')).
|
|
46
|
-
to eq("\e[31;1mUnicorns run wild\e[0m")
|
|
47
|
-
end
|
|
48
|
-
end
|
data/spec/unit/new_spec.rb
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
RSpec.describe Pastel, '#new' do
|
|
4
|
-
|
|
5
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
|
6
|
-
|
|
7
|
-
it { is_expected.to respond_to(:lookup) }
|
|
8
|
-
|
|
9
|
-
it { is_expected.to respond_to(:decorate) }
|
|
10
|
-
|
|
11
|
-
it { is_expected.to respond_to(:undecorate) }
|
|
12
|
-
|
|
13
|
-
it { is_expected.to respond_to(:strip) }
|
|
14
|
-
|
|
15
|
-
describe '#valid?' do
|
|
16
|
-
it "when valid returns true" do
|
|
17
|
-
expect(pastel.valid?(:red)).to eq(true)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "returns false when invalid" do
|
|
21
|
-
expect(pastel.valid?(:unknown)).to eq(false)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe '#colored?' do
|
|
26
|
-
it "checks if string is colored" do
|
|
27
|
-
expect(pastel.colored?("\e[31mfoo\e[0m")).to eq(true)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe 'options passed in' do
|
|
32
|
-
it 'defaults enabled to color detection' do
|
|
33
|
-
allow(TTY::Color).to receive(:color?).and_return(true)
|
|
34
|
-
|
|
35
|
-
pastel = described_class.new
|
|
36
|
-
|
|
37
|
-
expect(pastel.enabled?).to eq(true)
|
|
38
|
-
expect(TTY::Color).to have_received(:color?)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "sets enabled option" do
|
|
42
|
-
pastel = described_class.new(enabled: false)
|
|
43
|
-
expect(pastel.enabled?).to eq(false)
|
|
44
|
-
expect(pastel.red('Unicorn', pastel.green('!'))).to eq('Unicorn!')
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "sets eachline option" do
|
|
48
|
-
pastel = described_class.new(enabled: true, eachline: "\n")
|
|
49
|
-
expect(pastel.red("foo\nbar")).to eq("\e[31mfoo\e[0m\n\e[31mbar\e[0m")
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
RSpec.describe Pastel, '.respond_to?' do
|
|
4
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
|
5
|
-
|
|
6
|
-
it "responds correctly to color method" do
|
|
7
|
-
expect(pastel.respond_to?(:decorate)).to eq(true)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "responds correctly to color property" do
|
|
11
|
-
expect(pastel.respond_to?(:red)).to eq(true)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "responds correctly to unkown method" do
|
|
15
|
-
expect(pastel.respond_to?(:unknown)).to eq(false)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
RSpec.describe Pastel, '#undecorate' do
|
|
4
|
-
subject(:pastel) { described_class.new(enabled: true) }
|
|
5
|
-
|
|
6
|
-
it "undecorates string detecting color escape codes" do
|
|
7
|
-
string = pastel.red.on_green('foo')
|
|
8
|
-
expect(pastel.undecorate(string)).to eq([
|
|
9
|
-
{foreground: :red, background: :on_green, text: 'foo'}
|
|
10
|
-
])
|
|
11
|
-
end
|
|
12
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
begin
|
|
4
|
-
require 'rspec/core/rake_task'
|
|
5
|
-
|
|
6
|
-
desc 'Run all specs'
|
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
|
8
|
-
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
namespace :spec do
|
|
12
|
-
desc 'Run unit specs'
|
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
|
14
|
-
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
desc 'Run integration specs'
|
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
|
19
|
-
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
rescue LoadError
|
|
24
|
-
%w[spec spec:unit spec:integration].each do |name|
|
|
25
|
-
task name do
|
|
26
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|