pastel 0.7.1 → 0.7.2
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 +4 -4
- data/.travis.yml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +0 -1
- data/README.md +9 -7
- data/appveyor.yml +2 -4
- data/lib/pastel.rb +6 -6
- data/lib/pastel/alias_importer.rb +5 -4
- data/lib/pastel/color.rb +12 -11
- data/lib/pastel/color_parser.rb +1 -1
- data/lib/pastel/color_resolver.rb +1 -1
- data/lib/pastel/delegator.rb +2 -2
- data/lib/pastel/version.rb +1 -1
- data/pastel.gemspec +1 -0
- data/spec/unit/alias_color_spec.rb +4 -4
- data/spec/unit/alias_importer_spec.rb +2 -2
- data/spec/unit/color/alias_color_spec.rb +3 -3
- data/spec/unit/color/code_spec.rb +2 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9423d9bb23567a05cccb8fa304de88cf791f01d
|
4
|
+
data.tar.gz: 4c251c76dfabc80d5e2a48b031983eec254c8faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c32d02d36f105e11ee28bf219556088bc2a2b84e625490cdc23ab4a5aad99eee136270662a78f779ea13549a278795510d8e97176ce8487f91a6c76441557906
|
7
|
+
data.tar.gz: 925733ccb1ef6cd33cf11362da01eb28b830b8cdb36e681d4b65ae3305816d37fb4c437451c6387cb2d2d6fd6dbb7ef3106e540d922570e61ba99563b0da06bb
|
data/.travis.yml
CHANGED
@@ -2,23 +2,23 @@
|
|
2
2
|
language: ruby
|
3
3
|
sudo: false
|
4
4
|
cache: bundler
|
5
|
+
before_install: "gem update bundler"
|
5
6
|
bundler_args: --without yard benchmarks
|
6
7
|
script: "bundle exec rake ci"
|
7
8
|
rvm:
|
8
9
|
- 1.9.3
|
9
10
|
- 2.0.0
|
10
11
|
- 2.1.10
|
11
|
-
- 2.2.
|
12
|
-
- 2.3.
|
12
|
+
- 2.2.8
|
13
|
+
- 2.3.5
|
14
|
+
- 2.4.2
|
13
15
|
- jruby-9000
|
14
16
|
- jruby-head
|
15
17
|
- ruby-head
|
16
|
-
- rbx-2
|
17
18
|
matrix:
|
18
19
|
allow_failures:
|
19
20
|
- rvm: ruby-head
|
20
21
|
- rvm: jruby-head
|
21
|
-
- rvm: rbx-2
|
22
22
|
fast_finish: true
|
23
23
|
branches:
|
24
24
|
only: master
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.7.2] - 2017-11-09
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change to load relative file paths
|
7
|
+
* Change to allow `#alias_color` to accept multiple colors by Jared Ning (@ordinaryzelig)
|
8
|
+
|
3
9
|
## [v0.7.1] - 2017-01-09
|
4
10
|
|
5
11
|
### Changed
|
@@ -102,6 +108,7 @@
|
|
102
108
|
* Change gemspec to include equatable as dependency
|
103
109
|
* Change Delegator to stop creating instances and improve performance
|
104
110
|
|
111
|
+
[v0.7.2]: https://github.com/peter-murach/pastel/compare/v0.7.1...v0.7.2
|
105
112
|
[v0.7.1]: https://github.com/peter-murach/pastel/compare/v0.7.0...v0.7.1
|
106
113
|
[v0.7.0]: https://github.com/peter-murach/pastel/compare/v0.6.1...v0.7.0
|
107
114
|
[v0.6.1]: https://github.com/peter-murach/pastel/compare/v0.6.0...v0.6.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
<div align="center">
|
2
2
|
<img width="215" src="https://cdn.rawgit.com/piotrmurach/pastel/master/assets/pastel_logo.png" alt="pastel logo" />
|
3
3
|
</div>
|
4
|
+
|
4
5
|
# Pastel
|
6
|
+
|
5
7
|
[][gem]
|
6
8
|
[][travis]
|
7
9
|
[][appveyor]
|
@@ -119,7 +121,7 @@ pastel.red.on_green('Unicorns') {
|
|
119
121
|
}
|
120
122
|
```
|
121
123
|
|
122
|
-
When dealing with multiline strings you can set `eachline` option(more info see [eachline](#
|
124
|
+
When dealing with multiline strings you can set `eachline` option(more info see [eachline](#211-eachline)):
|
123
125
|
|
124
126
|
```
|
125
127
|
pastel = Pastel.new(eachline: "\n")
|
@@ -266,16 +268,16 @@ pastel.red("foo\nbar") # => "\e[31mfoo\e[0m\n\e[31mbar\e[0m"
|
|
266
268
|
|
267
269
|
### 2.12 Alias Color
|
268
270
|
|
269
|
-
In order to setup an alias for
|
271
|
+
In order to setup an alias for standard colors do:
|
270
272
|
|
271
273
|
```ruby
|
272
|
-
pastel.alias_color(:funky, :red)
|
274
|
+
pastel.alias_color(:funky, :red, :bold)
|
273
275
|
```
|
274
276
|
|
275
|
-
From that point forward, `:funky` alias can be passed to `decorate`, `valid?` with the same meaning as standard
|
277
|
+
From that point forward, `:funky` alias can be passed to `decorate`, `valid?` with the same meaning as standard colors:
|
276
278
|
|
277
279
|
```ruby
|
278
|
-
pastel.funky.on_green('unicorn') # => will use :red color
|
280
|
+
pastel.funky.on_green('unicorn') # => will use :red, :bold color
|
279
281
|
```
|
280
282
|
|
281
283
|
This method allows you to give more meaningful names to existing colors.
|
@@ -345,10 +347,10 @@ Generic styles:
|
|
345
347
|
|
346
348
|
This environment variable allows you to specify custom color aliases at runtime that will be understood by **Pastel**. The environment variable is read and used when the instance of **Pastel** is created. You can also use `alias_color` to create aliases.
|
347
349
|
|
348
|
-
Only alphanumeric and `_` are allowed in the alias names with the following format:
|
350
|
+
Only alphanumeric and `_` and `.` are allowed in the alias names with the following format:
|
349
351
|
|
350
352
|
```ruby
|
351
|
-
PASTEL_COLORS_ALIASES='newcolor_1=red,newcolor_2=on_green'
|
353
|
+
PASTEL_COLORS_ALIASES='newcolor_1=red,newcolor_2=on_green,funky=red.bold'
|
352
354
|
```
|
353
355
|
|
354
356
|
## 5. Command line
|
data/appveyor.yml
CHANGED
@@ -9,7 +9,6 @@ test_script:
|
|
9
9
|
- bundle exec rake ci
|
10
10
|
environment:
|
11
11
|
matrix:
|
12
|
-
- ruby_version: "193"
|
13
12
|
- ruby_version: "200"
|
14
13
|
- ruby_version: "200-x64"
|
15
14
|
- ruby_version: "21"
|
@@ -18,6 +17,5 @@ environment:
|
|
18
17
|
- ruby_version: "22-x64"
|
19
18
|
- ruby_version: "23"
|
20
19
|
- ruby_version: "23-x64"
|
21
|
-
|
22
|
-
|
23
|
-
- ruby_version: "193"
|
20
|
+
- ruby_version: "24"
|
21
|
+
- ruby_version: "24-x64"
|
data/lib/pastel.rb
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'tty-color'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
require_relative 'pastel/alias_importer'
|
6
|
+
require_relative 'pastel/color'
|
7
|
+
require_relative 'pastel/color_resolver'
|
8
|
+
require_relative 'pastel/delegator'
|
9
|
+
require_relative 'pastel/decorator_chain'
|
10
|
+
require_relative 'pastel/version'
|
11
11
|
|
12
12
|
module Pastel
|
13
13
|
# Raised when the style attribute is not supported
|
@@ -18,7 +18,7 @@ module Pastel
|
|
18
18
|
# Import aliases from the environment
|
19
19
|
#
|
20
20
|
# @example
|
21
|
-
# importer = Pastel::AliasImporter.new(Pastel::Color.new)
|
21
|
+
# importer = Pastel::AliasImporter.new(Pastel::Color.new, {})
|
22
22
|
# importer.import
|
23
23
|
#
|
24
24
|
# @return [nil]
|
@@ -28,11 +28,12 @@ module Pastel
|
|
28
28
|
color_aliases = env['PASTEL_COLORS_ALIASES']
|
29
29
|
return unless color_aliases
|
30
30
|
color_aliases.split(',').each do |color_alias|
|
31
|
-
new_color,
|
32
|
-
if !new_color || !
|
31
|
+
new_color, old_colors = color_alias.split('=')
|
32
|
+
if !new_color || !old_colors
|
33
33
|
output.puts "Bad color mapping `#{color_alias}`"
|
34
34
|
else
|
35
|
-
color.alias_color(new_color,
|
35
|
+
color.alias_color(new_color.to_sym,
|
36
|
+
*old_colors.split('.').map(&:to_sym))
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
data/lib/pastel/color.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'equatable'
|
4
|
-
|
4
|
+
|
5
|
+
require_relative 'ansi'
|
5
6
|
|
6
7
|
module Pastel
|
7
8
|
# A class responsible for coloring strings.
|
@@ -194,19 +195,19 @@ module Pastel
|
|
194
195
|
colors.all? { |color| style_names.include?(color.to_sym) }
|
195
196
|
end
|
196
197
|
|
197
|
-
# Define a new
|
198
|
+
# Define a new colors alias
|
198
199
|
#
|
199
200
|
# @param [String] alias_name
|
200
|
-
# the
|
201
|
-
# @param [String] color
|
202
|
-
# the
|
201
|
+
# the colors alias to define
|
202
|
+
# @param [Array[Symbol,String]] color
|
203
|
+
# the colors the alias will correspond to
|
203
204
|
#
|
204
|
-
# @return [String]
|
205
|
-
# the standard color
|
205
|
+
# @return [Array[String]]
|
206
|
+
# the standard color values of the alias
|
206
207
|
#
|
207
208
|
# @api public
|
208
|
-
def alias_color(alias_name,
|
209
|
-
validate(
|
209
|
+
def alias_color(alias_name, *colors)
|
210
|
+
validate(*colors)
|
210
211
|
|
211
212
|
if !(alias_name.to_s =~ /^[\w]+$/)
|
212
213
|
fail InvalidAliasNameError, "Invalid alias name `#{alias_name}`"
|
@@ -215,8 +216,8 @@ module Pastel
|
|
215
216
|
"Cannot alias standard color `#{alias_name}`"
|
216
217
|
end
|
217
218
|
|
218
|
-
ALIASES[alias_name.to_sym] = ANSI::ATTRIBUTES[
|
219
|
-
|
219
|
+
ALIASES[alias_name.to_sym] = colors.map(&ANSI::ATTRIBUTES.method(:[]))
|
220
|
+
colors
|
220
221
|
end
|
221
222
|
|
222
223
|
private
|
data/lib/pastel/color_parser.rb
CHANGED
data/lib/pastel/delegator.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'equatable'
|
4
4
|
require 'forwardable'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
require_relative 'color_parser'
|
7
|
+
require_relative 'decorator_chain'
|
8
8
|
|
9
9
|
module Pastel
|
10
10
|
# Wrapes the {DecoratorChain} to allow for easy resolution
|
data/lib/pastel/version.rb
CHANGED
data/pastel.gemspec
CHANGED
@@ -5,13 +5,13 @@ RSpec.describe Pastel, '#alias_color' do
|
|
5
5
|
subject(:pastel) { described_class.new(enabled: true) }
|
6
6
|
|
7
7
|
it "aliases color" do
|
8
|
-
pastel.alias_color(:funky, :red)
|
9
|
-
expect(pastel.funky('unicorn')).to eq("\e[
|
8
|
+
pastel.alias_color(:funky, :red, :bold)
|
9
|
+
expect(pastel.funky('unicorn')).to eq("\e[31;1municorn\e[0m")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "aliases color and combines with regular ones" do
|
13
|
-
pastel.alias_color(:funky, :red)
|
14
|
-
expect(pastel.funky.on_green('unicorn')).to eq("\e[31;42municorn\e[0m")
|
13
|
+
pastel.alias_color(:funky, :red, :bold)
|
14
|
+
expect(pastel.funky.on_green('unicorn')).to eq("\e[31;1;42municorn\e[0m")
|
15
15
|
end
|
16
16
|
|
17
17
|
it "reads aliases from the environment" do
|
@@ -5,13 +5,13 @@ RSpec.describe Pastel::AliasImporter, '#import' do
|
|
5
5
|
let(:output) { StringIO.new }
|
6
6
|
|
7
7
|
it "imports aliases from environment" do
|
8
|
-
color_aliases = "funky=red,base=bright_yellow"
|
8
|
+
color_aliases = "funky=red.bold,base=bright_yellow"
|
9
9
|
env = {'PASTEL_COLORS_ALIASES' => color_aliases}
|
10
10
|
importer = described_class.new(color, env)
|
11
11
|
|
12
12
|
importer.import
|
13
13
|
|
14
|
-
expect(color).to have_received(:alias_color).with(:funky, :red)
|
14
|
+
expect(color).to have_received(:alias_color).with(:funky, :red, :bold)
|
15
15
|
expect(color).to have_received(:alias_color).with(:base, :bright_yellow)
|
16
16
|
end
|
17
17
|
|
@@ -23,10 +23,10 @@ RSpec.describe Pastel::Color, '.alias_color' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'aliases color :red to :funky' do
|
26
|
-
color.alias_color(:funky, :red)
|
26
|
+
color.alias_color(:funky, :red, :bold)
|
27
27
|
expect(color.valid?(:funky)).to eq(true)
|
28
|
-
expect(color.code(:funky)).to eq([31])
|
29
|
-
expect(color.lookup(:funky)).to eq("\e[
|
28
|
+
expect(color.code(:funky)).to eq([[31, 1]])
|
29
|
+
expect(color.lookup(:funky)).to eq("\e[31;1m")
|
30
30
|
end
|
31
31
|
|
32
32
|
it "has global aliases" do
|
@@ -18,7 +18,7 @@ RSpec.describe Pastel::Color, '#code' do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "finds alias code" do
|
21
|
-
color.alias_color(:funky, :red)
|
22
|
-
expect(color.code(:funky)).to eq(color.code(:red))
|
21
|
+
color.alias_color(:funky, :red, :bold)
|
22
|
+
expect(color.code(:funky)).to eq([color.code(:red) + color.code(:bold)])
|
23
23
|
end
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pastel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equatable
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.1'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.1'
|
75
89
|
description: Terminal strings styling with intuitive and clean API.
|
76
90
|
email:
|
77
91
|
- ''
|