pastel 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +57 -13
  3. data/README.md +36 -29
  4. data/lib/pastel.rb +17 -19
  5. data/lib/pastel/alias_importer.rb +9 -7
  6. data/lib/pastel/ansi.rb +2 -2
  7. data/lib/pastel/color.rb +63 -23
  8. data/lib/pastel/color_parser.rb +24 -18
  9. data/lib/pastel/color_resolver.rb +3 -1
  10. data/lib/pastel/decorator_chain.rb +47 -7
  11. data/lib/pastel/delegator.rb +57 -26
  12. data/lib/pastel/detached.rb +41 -5
  13. data/lib/pastel/version.rb +2 -2
  14. metadata +27 -97
  15. data/.gitignore +0 -22
  16. data/.rspec +0 -3
  17. data/.travis.yml +0 -26
  18. data/Gemfile +0 -16
  19. data/Rakefile +0 -8
  20. data/appveyor.yml +0 -23
  21. data/assets/pastel_logo.png +0 -0
  22. data/assets/screenshot.png +0 -0
  23. data/benchmarks/nesting_speed.rb +0 -41
  24. data/benchmarks/speed.rb +0 -45
  25. data/examples/palette.rb +0 -14
  26. data/pastel.gemspec +0 -26
  27. data/spec/spec_helper.rb +0 -45
  28. data/spec/unit/alias_color_spec.rb +0 -24
  29. data/spec/unit/alias_importer_spec.rb +0 -29
  30. data/spec/unit/color/alias_color_spec.rb +0 -40
  31. data/spec/unit/color/code_spec.rb +0 -24
  32. data/spec/unit/color/colored_spec.rb +0 -15
  33. data/spec/unit/color/decorate_spec.rb +0 -79
  34. data/spec/unit/color/equal_spec.rb +0 -22
  35. data/spec/unit/color/lookup_spec.rb +0 -17
  36. data/spec/unit/color/new_spec.rb +0 -10
  37. data/spec/unit/color/strip_spec.rb +0 -56
  38. data/spec/unit/color/styles_spec.rb +0 -10
  39. data/spec/unit/color/valid_spec.rb +0 -19
  40. data/spec/unit/color_parser_spec.rb +0 -67
  41. data/spec/unit/decorate_dsl_spec.rb +0 -98
  42. data/spec/unit/decorator_chain_spec.rb +0 -47
  43. data/spec/unit/delegator_spec.rb +0 -38
  44. data/spec/unit/detach_spec.rb +0 -48
  45. data/spec/unit/new_spec.rb +0 -63
  46. data/spec/unit/respond_to_spec.rb +0 -17
  47. data/spec/unit/undecorate_spec.rb +0 -12
  48. data/tasks/console.rake +0 -11
  49. data/tasks/coverage.rake +0 -11
  50. data/tasks/spec.rake +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e0dff6fb46a4686e16dadf14dbc302c03bec710a
4
- data.tar.gz: b3bb1f08fa7a1eb0c6a5529f32d1405419bcc024
2
+ SHA256:
3
+ metadata.gz: '06693f6ff4f804468ff3802df48c725067fb8eb425e9ba4301627f7c496099bb'
4
+ data.tar.gz: 0752767e8bbe626d683e5eb8b576f5c1229c322f72475d41b1041f4f15eb2c11
5
5
  SHA512:
6
- metadata.gz: 9aad90942603ae1740ee11c2e213b8e4a1058fb7fdffc52ee42bb3764d7e20b74bdd1759421b5a84513b7e140f3d7d72c6605f23b874d22f8d3654a44ba8233c
7
- data.tar.gz: c021e7b94a64d5d3d63288fac62346064c99beb3fbec2f0f9a7c162e6d39d440d72a1f03960b2d5fe0f229ec397c53d2ccac197c13d5f3f7286b190406aeef56
6
+ metadata.gz: 2239724d8aa9165ec045a2f43b6b8ce336c35ad487bc9e5ca1a8005c0321c682a73fff711316710848fee9931790c47a72dc5469afda25e98975bf6c38a9dfc5
7
+ data.tar.gz: b8f59e4fa1c52973d91d41d4e3f8602da3b164a41125a7416c7f119f53f880e81f4d3a79ea52e25b4e9de4dcb338d37ff1045f9b7b4437056cb7dc1597ce87df
@@ -1,5 +1,44 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.8.0] - 2020-07-04
4
+
5
+ ### Changed
6
+ * Change gemspec to require Ruby 2.0 or higher
7
+ * Change Pastel#new to use keyword arguments in place of hash options
8
+ * Change to freeze all strings
9
+ * Remove equatable dependency
10
+
11
+ ### Fixed
12
+ * Fix Pastel#strip to recognise no-number reset by DanielVartanov(@DanielVartanov)
13
+ * Fix Pastel#undecorate to correctly assign styles for nested colors
14
+
15
+ ## [v0.7.4] - 2020-05-08
16
+
17
+ ### Fixed
18
+ * Fix ColorParser#undecorate to require direct dependency by Nick Pezza(@npezza93)
19
+
20
+ ## [v0.7.3] - 2019-06-16
21
+
22
+ ### Changed
23
+ * Change gemspec to load required files directly without git
24
+ * Change to update tty-color & equatable dependency versions
25
+
26
+ ### Fixed
27
+ * Fix Delegator warning
28
+
29
+ ## [v0.7.2] - 2017-11-09
30
+
31
+ ### Changed
32
+ * Change to load relative file paths
33
+ * Change to allow `#alias_color` to accept multiple colors by Jared Ning (@ordinaryzelig)
34
+
35
+ ## [v0.7.1] - 2017-01-09
36
+
37
+ ### Changed
38
+ * Change to load specific files when needed
39
+ * Change to freeze ANSI attributes
40
+ * Change to directly assign enabled attribute
41
+
3
42
  ## [v0.7.0] - 2016-12-27
4
43
 
5
44
  ### Changed
@@ -17,7 +56,7 @@
17
56
  ## [v0.6.0] - 2016-01-15
18
57
 
19
58
  ### Added
20
- * Add helper functions #foreground?, #backgroud?, #style to ANSI module
59
+ * Add helper functions #foreground?, #background?, #style to ANSI module
21
60
  * Add ColorParser for parsing color symbols out of text
22
61
  * Add Pastel#undecorate for parsing color names out of strings
23
62
 
@@ -95,15 +134,20 @@
95
134
  * Change gemspec to include equatable as dependency
96
135
  * Change Delegator to stop creating instances and improve performance
97
136
 
98
- [v0.7.0]: https://github.com/peter-murach/pastel/compare/v0.6.1...v0.7.0
99
- [v0.6.1]: https://github.com/peter-murach/pastel/compare/v0.6.0...v0.6.1
100
- [v0.6.0]: https://github.com/peter-murach/pastel/compare/v0.5.3...v0.6.0
101
- [v0.5.3]: https://github.com/peter-murach/pastel/compare/v0.5.2...v0.5.3
102
- [v0.5.2]: https://github.com/peter-murach/pastel/compare/v0.5.1...v0.5.2
103
- [v0.5.1]: https://github.com/peter-murach/pastel/compare/v0.5.0...v0.5.1
104
- [v0.5.0]: https://github.com/peter-murach/pastel/compare/v0.4.0...v0.5.0
105
- [v0.4.0]: https://github.com/peter-murach/pastel/compare/v0.3.0...v0.4.0
106
- [v0.3.0]: https://github.com/peter-murach/pastel/compare/v0.2.1...v0.3.0
107
- [v0.2.1]: https://github.com/peter-murach/pastel/compare/v0.2.0...v0.2.1
108
- [v0.2.0]: https://github.com/peter-murach/pastel/compare/v0.1.0...v0.2.0
109
- [v0.1.0]: https://github.com/peter-murach/pastel/compare/v0.1.0
137
+ [v0.8.0]: https://github.com/piotrmurach/pastel/compare/v0.7.4...v0.8.0
138
+ [v0.7.4]: https://github.com/piotrmurach/pastel/compare/v0.7.3...v0.7.4
139
+ [v0.7.3]: https://github.com/piotrmurach/pastel/compare/v0.7.2...v0.7.3
140
+ [v0.7.2]: https://github.com/piotrmurach/pastel/compare/v0.7.1...v0.7.2
141
+ [v0.7.1]: https://github.com/piotrmurach/pastel/compare/v0.7.0...v0.7.1
142
+ [v0.7.0]: https://github.com/piotrmurach/pastel/compare/v0.6.1...v0.7.0
143
+ [v0.6.1]: https://github.com/piotrmurach/pastel/compare/v0.6.0...v0.6.1
144
+ [v0.6.0]: https://github.com/piotrmurach/pastel/compare/v0.5.3...v0.6.0
145
+ [v0.5.3]: https://github.com/piotrmurach/pastel/compare/v0.5.2...v0.5.3
146
+ [v0.5.2]: https://github.com/piotrmurach/pastel/compare/v0.5.1...v0.5.2
147
+ [v0.5.1]: https://github.com/piotrmurach/pastel/compare/v0.5.0...v0.5.1
148
+ [v0.5.0]: https://github.com/piotrmurach/pastel/compare/v0.4.0...v0.5.0
149
+ [v0.4.0]: https://github.com/piotrmurach/pastel/compare/v0.3.0...v0.4.0
150
+ [v0.3.0]: https://github.com/piotrmurach/pastel/compare/v0.2.1...v0.3.0
151
+ [v0.2.1]: https://github.com/piotrmurach/pastel/compare/v0.2.0...v0.2.1
152
+ [v0.2.0]: https://github.com/piotrmurach/pastel/compare/v0.1.0...v0.2.0
153
+ [v0.1.0]: https://github.com/piotrmurach/pastel/compare/v0.1.0
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 Version](https://badge.fury.io/rb/pastel.svg)][gem]
6
8
  [![Build Status](https://secure.travis-ci.org/piotrmurach/pastel.svg?branch=master)][travis]
7
9
  [![Build status](https://ci.appveyor.com/api/projects/status/9blbjfq42o4v1rk4?svg=true)][appveyor]
@@ -37,7 +39,7 @@
37
39
 
38
40
  Add this line to your application's Gemfile:
39
41
 
40
- gem 'pastel'
42
+ gem "pastel"
41
43
 
42
44
  And then execute:
43
45
 
@@ -74,7 +76,7 @@ Or install it yourself as:
74
76
  ```ruby
75
77
  pastel = Pastel.new
76
78
 
77
- puts pastel.red('Unicorns!')
79
+ puts pastel.red("Unicorns!")
78
80
  ```
79
81
 
80
82
  **Pastel** doesn't print the colored string out, just returns it, you'll have to print it yourself.
@@ -82,46 +84,46 @@ puts pastel.red('Unicorns!')
82
84
  You can compose multiple styles through chainable API:
83
85
 
84
86
  ```ruby
85
- pastel.red.on_green.bold('Unicorns!')
87
+ pastel.red.on_green.bold("Unicorns!")
86
88
  ```
87
89
 
88
90
  It allows you to combine styled strings with unstyled ones:
89
91
 
90
92
  ```ruby
91
- pastel.red('Unicorns') + ' will rule ' + pastel.green('the World!')
93
+ pastel.red("Unicorns") + " will rule " + pastel.green("the World!")
92
94
  ```
93
95
 
94
96
  It supports variable number of arguments:
95
97
 
96
98
  ```ruby
97
- pastel.red('Unicorns', 'are', 'running', 'everywhere!')
99
+ pastel.red("Unicorns", "are", "running", "everywhere!")
98
100
  ```
99
101
 
100
102
  You can also nest styles as follows:
101
103
 
102
104
  ```ruby
103
- pastel.red('Unicorns ', pastel.on_green('everywhere!'))
105
+ pastel.red("Unicorns ", pastel.on_green("everywhere!"))
104
106
  ```
105
107
 
106
108
  Nesting is smart enough to know where one color ends and another one starts:
107
109
 
108
110
  ```ruby
109
- pastel.red('Unicorns ' + pastel.green('everywhere') + pastel.on_yellow('!'))
111
+ pastel.red("Unicorns " + pastel.green("everywhere") + pastel.on_yellow("!"))
110
112
  ```
111
113
 
112
114
  You can also nest styles inside blocks:
113
115
 
114
116
  ```ruby
115
- pastel.red.on_green('Unicorns') {
116
- green.on_red('will ', 'dominate') {
117
- yellow('the world!')
117
+ pastel.red.on_green("Unicorns") {
118
+ green.on_red("will ", "dominate") {
119
+ yellow("the world!")
118
120
  }
119
121
  }
120
122
  ```
121
123
 
122
- When dealing with multiline strings you can set `eachline` option(more info see [eachline](#29-eachline)):
124
+ When dealing with multiline strings you can set `eachline` option(more info see [eachline](#211-eachline)):
123
125
 
124
- ```
126
+ ```ruby
125
127
  pastel = Pastel.new(eachline: "\n")
126
128
  ```
127
129
 
@@ -131,8 +133,8 @@ You can also predefine needed styles and reuse them:
131
133
  error = pastel.red.bold.detach
132
134
  warning = pastel.yellow.detach
133
135
 
134
- puts error.('Error!')
135
- puts warning.('Warning')
136
+ puts error.("Error!")
137
+ puts warning.("Warning")
136
138
  ```
137
139
 
138
140
  If your output is redirected to a file, you probably don't want Pastel to add color to your text.
@@ -141,7 +143,7 @@ See https://github.com/piotrmurach/pastel#210-enabled for a way to easily accomp
141
143
  **Pastel** has companion library called `pastel-cli` that allows you to style text in terminal via `pastel` executable:
142
144
 
143
145
  ```bash
144
- $ pastel green 'Unicorns & rainbows!'
146
+ $ pastel green "Unicorns & rainbows!"
145
147
  ```
146
148
 
147
149
  ## 2 Interface
@@ -153,7 +155,7 @@ pastel.`[....](string, [string...])`
153
155
  Color styles are invoked as method calls with a string argument. A given color can take any number of strings as arguments. Then it returns a colored string which isn't printed out to terminal. You need to print it yourself if you need to. This is done so that you can save it as a string, pass to something else, send it to a file handle and so on.
154
156
 
155
157
  ```ruby
156
- pastel.red('Unicorns ', pastel.bold.underline('everywhere'), '!')
158
+ pastel.red("Unicorns ", pastel.bold.underline("everywhere"), "!")
157
159
  ```
158
160
 
159
161
  Please refer to [3. Supported Colors](#3-supported-colors) section for full list of supported styles.
@@ -163,7 +165,7 @@ Please refer to [3. Supported Colors](#3-supported-colors) section for full list
163
165
  This method is a lower level string styling call that takes as the first argument the string to style followed by any number of color attributes, and returns string wrapped in styles.
164
166
 
165
167
  ```ruby
166
- pastel.decorate('Unicorn', :green, :on_blue, :bold)
168
+ pastel.decorate("Unicorn", :green, :on_blue, :bold)
167
169
  ```
168
170
 
169
171
  This method will be useful in situations where colors are provided as a list of parameters that have been generated dynamically.
@@ -174,7 +176,7 @@ It performs the opposite to `decorate` method by turning color escape sequences
174
176
 
175
177
  ```ruby
176
178
  pastel.undecorate("\e[32mfoo\e[0m \e[31mbar\e[0m")
177
- # => [{foreground: :green, text: 'foo'}, {text: ' '}, {foreground: :red, text: 'bar'}]
179
+ # => [{foreground: :green, text: "foo"}, {text: " "}, {foreground: :red, text: "bar"}]
178
180
  ```
179
181
 
180
182
  To translate the color name into sequence use [lookup](#27-lookup)
@@ -186,9 +188,9 @@ The `detach` method allows to keep all the associated colors with the detached i
186
188
  ```ruby
187
189
  notice = pastel.blue.bold.detach
188
190
 
189
- notice.call('Unicorns running')
190
- notice.('Unicorns running')
191
- notice['Unicorns running']
191
+ notice.call("Unicorns running")
192
+ notice.("Unicorns running")
193
+ notice["Unicorns running"]
192
194
  ```
193
195
 
194
196
  ### 2.5 Strip
@@ -212,7 +214,8 @@ pastel.styles
212
214
  To perform translation of color name into ansi escape code use `lookup`:
213
215
 
214
216
  ```ruby
215
- color.lookup(:red) # => "\e[31m"
217
+ pastel.lookup(:red) # => "\e[31m"
218
+ pastel.lookup(:reset) # => "\e[0m"
216
219
  ```
217
220
 
218
221
  ### 2.8 Valid?
@@ -266,16 +269,16 @@ pastel.red("foo\nbar") # => "\e[31mfoo\e[0m\n\e[31mbar\e[0m"
266
269
 
267
270
  ### 2.12 Alias Color
268
271
 
269
- In order to setup an alias for the standard color do:
272
+ In order to setup an alias for standard colors do:
270
273
 
271
274
  ```ruby
272
- pastel.alias_color(:funky, :red)
275
+ pastel.alias_color(:funky, :red, :bold)
273
276
  ```
274
277
 
275
- From that point forward, `:funky` alias can be passed to `decorate`, `valid?` with the same meaning as standard color:
278
+ From that point forward, `:funky` alias can be passed to `decorate`, `valid?` with the same meaning as standard colors:
276
279
 
277
280
  ```ruby
278
- pastel.funky.on_green('unicorn') # => will use :red color
281
+ pastel.funky.on_green("unicorn") # => will use :red, :bold color
279
282
  ```
280
283
 
281
284
  This method allows you to give more meaningful names to existing colors.
@@ -345,10 +348,10 @@ Generic styles:
345
348
 
346
349
  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
350
 
348
- Only alphanumeric and `_` are allowed in the alias names with the following format:
351
+ Only alphanumeric and `_` and `.` are allowed in the alias names with the following format:
349
352
 
350
353
  ```ruby
351
- PASTEL_COLORS_ALIASES='newcolor_1=red,newcolor_2=on_green'
354
+ PASTEL_COLORS_ALIASES="newcolor_1=red,newcolor_2=on_green,funky=red.bold"
352
355
  ```
353
356
 
354
357
  ## 5. Command line
@@ -367,6 +370,10 @@ $ pastel green 'Unicorns & rainbows!'
367
370
  4. Push to the branch (`git push origin my-new-feature`)
368
371
  5. Create a new Pull Request
369
372
 
373
+ ## Code of Conduct
374
+
375
+ Everyone interacting in the Pastel project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/pastel/blob/master/CODE_OF_CONDUCT.md).
376
+
370
377
  ## Copyright
371
378
 
372
- Copyright (c) 2014-2017 Piotr Murach. See LICENSE for further details.
379
+ Copyright (c) 2014 Piotr Murach. See LICENSE for further details.
@@ -1,18 +1,12 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
4
- require 'equatable'
5
- require 'tty-color'
3
+ require "tty-color"
6
4
 
7
- require 'pastel/ansi'
8
- require 'pastel/alias_importer'
9
- require 'pastel/color'
10
- require 'pastel/color_parser'
11
- require 'pastel/color_resolver'
12
- require 'pastel/delegator'
13
- require 'pastel/detached'
14
- require 'pastel/decorator_chain'
15
- require 'pastel/version'
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/version"
16
10
 
17
11
  module Pastel
18
12
  # Raised when the style attribute is not supported
@@ -26,19 +20,23 @@ module Pastel
26
20
  # @example
27
21
  # pastel = Pastel.new enabled: true
28
22
  #
23
+ # @param [Boolean] :enabled
24
+ # whether or not to disable coloring
25
+ # @param [Boolean] :eachline
26
+ # whether or not to wrap eachline with separate coloring
27
+ #
29
28
  # @return [Delegator]
30
29
  #
31
30
  # @api public
32
- def new(options = {})
33
- unless options.key?(:enabled)
34
- options.merge!(enabled: TTY::Color.windows? || TTY::Color.color?)
31
+ def new(enabled: nil, eachline: false)
32
+ if enabled.nil?
33
+ enabled = (TTY::Color.windows? || TTY::Color.color?)
35
34
  end
36
- color = Color.new(options)
35
+ color = Color.new(enabled: enabled, eachline: eachline)
37
36
  importer = AliasImporter.new(color, ENV)
38
37
  importer.import
39
38
  resolver = ColorResolver.new(color)
40
- Delegator.for(resolver, DecoratorChain.empty)
39
+ Delegator.wrap(resolver)
41
40
  end
42
-
43
41
  module_function :new
44
42
  end # Pastel
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Pastel
4
4
  # A class responsible for importing color aliases
@@ -18,21 +18,23 @@ 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]
25
25
  #
26
26
  # @api public
27
27
  def import
28
- color_aliases = env['PASTEL_COLORS_ALIASES']
28
+ color_aliases = env["PASTEL_COLORS_ALIASES"]
29
29
  return unless color_aliases
30
- color_aliases.split(',').each do |color_alias|
31
- new_color, old_color = color_alias.split('=').map(&:to_sym)
32
- if !new_color || !old_color
30
+
31
+ color_aliases.split(",").each do |color_alias|
32
+ new_color, old_colors = color_alias.split("=")
33
+ if !new_color || !old_colors
33
34
  output.puts "Bad color mapping `#{color_alias}`"
34
35
  else
35
- color.alias_color(new_color, old_color)
36
+ color.alias_color(new_color.to_sym,
37
+ *old_colors.split(".").map(&:to_sym))
36
38
  end
37
39
  end
38
40
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Pastel
4
4
  # Mixin that provides ANSI codes
@@ -51,7 +51,7 @@ module Pastel
51
51
  on_bright_magenta: 105,
52
52
  on_bright_cyan: 106,
53
53
  on_bright_white: 107
54
- }
54
+ }.freeze
55
55
 
56
56
  module_function
57
57
 
@@ -1,28 +1,29 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ansi"
2
4
 
3
5
  module Pastel
4
6
  # A class responsible for coloring strings.
5
7
  class Color
6
- include Equatable
7
8
  include ANSI
8
9
 
9
10
  # All color aliases
10
11
  ALIASES = {}
11
12
 
12
13
  # Match all color escape sequences
13
- ANSI_COLOR_REGEXP = /\x1b+(\[|\[\[)[0-9;:?]+m/mo.freeze
14
+ ANSI_COLOR_REGEXP = /\x1b\[{1,2}[0-9;:?]*m/mo.freeze
14
15
 
15
16
  attr_reader :enabled
16
- alias_method :enabled?, :enabled
17
+ alias enabled? enabled
17
18
 
18
19
  attr_reader :eachline
19
20
 
20
21
  # Initialize a Terminal Color
21
22
  #
22
23
  # @api public
23
- def initialize(options = {})
24
- @enabled = options[:enabled]
25
- @eachline = options.fetch(:eachline) { false }
24
+ def initialize(enabled: nil, eachline: false)
25
+ @enabled = enabled
26
+ @eachline = eachline
26
27
  @cache = {}
27
28
  end
28
29
 
@@ -100,7 +101,7 @@ module Pastel
100
101
  #
101
102
  # @api public
102
103
  def strip(*strings)
103
- modified = strings.map { |string| string.dup.gsub(ANSI_COLOR_REGEXP, '') }
104
+ modified = strings.map { |string| string.dup.gsub(ANSI_COLOR_REGEXP, "") }
104
105
  modified.size == 1 ? modified[0] : modified
105
106
  end
106
107
 
@@ -191,29 +192,67 @@ module Pastel
191
192
  colors.all? { |color| style_names.include?(color.to_sym) }
192
193
  end
193
194
 
194
- # Define a new color alias
195
+ # Define a new colors alias
195
196
  #
196
197
  # @param [String] alias_name
197
- # the color alias to define
198
- # @param [String] color
199
- # the color the alias will correspond to
198
+ # the colors alias to define
199
+ # @param [Array[Symbol,String]] color
200
+ # the colors the alias will correspond to
200
201
  #
201
- # @return [String]
202
- # the standard color value of the alias
202
+ # @return [Array[String]]
203
+ # the standard color values of the alias
203
204
  #
204
205
  # @api public
205
- def alias_color(alias_name, color)
206
- validate(color)
206
+ def alias_color(alias_name, *colors)
207
+ validate(*colors)
207
208
 
208
209
  if !(alias_name.to_s =~ /^[\w]+$/)
209
- fail InvalidAliasNameError, "Invalid alias name `#{alias_name}`"
210
+ raise InvalidAliasNameError, "Invalid alias name `#{alias_name}`"
210
211
  elsif ANSI::ATTRIBUTES[alias_name]
211
- fail InvalidAliasNameError,
212
- "Cannot alias standard color `#{alias_name}`"
212
+ raise InvalidAliasNameError,
213
+ "Cannot alias standard color `#{alias_name}`"
213
214
  end
214
215
 
215
- ALIASES[alias_name.to_sym] = ANSI::ATTRIBUTES[color]
216
- color
216
+ ALIASES[alias_name.to_sym] = colors.map(&ANSI::ATTRIBUTES.method(:[]))
217
+ colors
218
+ end
219
+
220
+ # Compare colors for equality of attributes
221
+ #
222
+ # @return [Boolean]
223
+ #
224
+ # @api public
225
+ def eql?(other)
226
+ instance_of?(other.class) &&
227
+ enabled.eql?(other.enabled) && eachline.eql?(other.eachline)
228
+ end
229
+
230
+ # Compare colors for equivalence of attributes
231
+ #
232
+ # @return [Boolean]
233
+ #
234
+ # @api public
235
+ def ==(other)
236
+ other.is_a?(self.class) &&
237
+ enabled == other.enabled && eachline == other.eachline
238
+ end
239
+
240
+ # Inspect this instance attributes
241
+ #
242
+ # @return [String]
243
+ #
244
+ # @api public
245
+ def inspect
246
+ "#<#{self.class.name} enabled=#{enabled.inspect} eachline=#{eachline.inspect}>"
247
+ end
248
+
249
+ # Hash for this instance and its attributes
250
+ #
251
+ # @return [Numeric]
252
+ #
253
+ # @api public
254
+ def hash
255
+ [self.class, enabled, eachline].hash
217
256
  end
218
257
 
219
258
  private
@@ -224,13 +263,14 @@ module Pastel
224
263
  #
225
264
  # @api private
226
265
  def blank?(value)
227
- value.nil? || !value.respond_to?(:to_str) || value.to_s == ''
266
+ value.nil? || !value.respond_to?(:to_str) || value.to_s == ""
228
267
  end
229
268
 
230
269
  # @api private
231
270
  def validate(*colors)
232
271
  return if valid?(*colors)
233
- fail InvalidAttributeNameError, 'Bad style or unintialized constant, ' \
272
+
273
+ raise InvalidAttributeNameError, "Bad style or unintialized constant, " \
234
274
  " valid styles are: #{style_names.join(', ')}."
235
275
  end
236
276
  end # Color