paint 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.rdoc +6 -0
- data/MIT-LICENSE.txt +1 -1
- data/README.rdoc +12 -55
- data/Rakefile +22 -26
- data/lib/paint.rb +46 -40
- data/lib/paint/util.rb +1 -29
- data/lib/paint/version.rb +1 -1
- data/paint.gemspec +24 -7
- metadata +19 -21
- data/lib/paint/shortcuts.rb +0 -106
- data/spec/paint_methods_spec.rb +0 -91
- data/spec/paint_mode_spec.rb +0 -23
- data/spec/paint_shortcuts_spec.rb +0 -62
- data/spec/paint_spec.rb +0 -97
- data/spec/spec_helper.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 676c869edf2a0dd0a45112ae34b5efe40253383b
|
4
|
+
data.tar.gz: 36c67ac1e7d1a6251203b426bacd00d5827f2d64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7020dd7dec634ef466ac98c1366e413b5d1c0a728c0bc954f2c57ae47e5c69c2e365bebc13a80ed916e90e74fceb6f502c1b5d5d9bd8f1cd4508273ae9542e70
|
7
|
+
data.tar.gz: 3575d22aa3cc18df1a1877a2472f43ccdd43f87f99c0d996de0e67f2ba94f819733758206748028b63810ce0aa8c4181346960c9df48661176b3be30b6d89d7f
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 1.0.0
|
2
|
+
* Improved performance
|
3
|
+
* Option for :random colors removed (see readme)
|
4
|
+
* Seperate Paint::SHORTCUTS into extra gem
|
5
|
+
* Drop support for Ruby 1 (inoffically still support 1.9.3)
|
6
|
+
|
1
7
|
=== 0.9.0
|
2
8
|
* Don't colorize strings via shortcuts when Paint.mode == 0
|
3
9
|
* Freeze bundled ascii color data
|
data/MIT-LICENSE.txt
CHANGED
data/README.rdoc
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
= Ruby Paint {<img src="https://travis-ci.org/janlelis/paint.png" />}[https://travis-ci.org/janlelis/paint]
|
1
|
+
= Ruby Paint {<img src="https://badge.fury.io/rb/paint.svg" />}[http://badge.fury.io/rb/paint] {<img src="https://travis-ci.org/janlelis/paint.png" />}[https://travis-ci.org/janlelis/paint]
|
2
2
|
|
3
3
|
Paint manages terminal colors and effects for you. It combines the strengths of *term-ansicolor*, *rainbow* and other similar projects into a simple to use, however still flexible terminal colorization gem with no core extensions by default.
|
4
4
|
|
5
5
|
== Features
|
6
|
-
|
7
6
|
* No string extensions (suitable for library development)
|
8
7
|
* Supports setting 256 colors (for capable terminals)
|
9
8
|
* Supports setting any effects (although most terminals won't support it)
|
10
9
|
* Simple to use
|
11
|
-
*
|
10
|
+
* Faster than most similar gems due to caching
|
12
11
|
* Fall-back modes for non-256-color terminals (<tt>Paint.mode</tt>), supported modes:
|
13
12
|
* 256 colors
|
14
13
|
* 16 colors (only ansi colors, combined with bright effect)
|
@@ -16,12 +15,7 @@ Paint manages terminal colors and effects for you. It combines the strengths of
|
|
16
15
|
* 0 colors (deactivate)
|
17
16
|
|
18
17
|
== Setup
|
19
|
-
|
20
|
-
Install with:
|
21
|
-
|
22
|
-
gem install paint
|
23
|
-
|
24
|
-
Or add to Gemfile:
|
18
|
+
Add to Gemfile:
|
25
19
|
|
26
20
|
gem 'paint'
|
27
21
|
|
@@ -32,7 +26,6 @@ In Ruby do:
|
|
32
26
|
require 'paint'
|
33
27
|
|
34
28
|
== Usage
|
35
|
-
|
36
29
|
The only method you need to know to get started is: <tt>Paint.[]</tt>
|
37
30
|
|
38
31
|
The first argument given to <tt>Paint.[]</tt> is the string to colorize (if the object is not a string, <tt>to_s</tt> will be called on it). The other arguments describe how to modify/colorize the string. Let's learn by example:
|
@@ -47,7 +40,6 @@ The first argument given to <tt>Paint.[]</tt> is the string to colorize (if the
|
|
47
40
|
Paint['Ruby', "gold", "snow"] # Paint supports rgb.txt color names, note that the arguments are strings (:yellow != "yellow")!
|
48
41
|
Paint['Ruby', "#123456"] # html like definitions are possible.
|
49
42
|
Paint['Ruby', "fff"] # another html hex definition
|
50
|
-
Paint['Ruby', :random] # pass :random to get one of eight random ansi foreground colors
|
51
43
|
Paint['Ruby', :inverse] # swaps fore- and background
|
52
44
|
Paint['Ruby', :italic, :encircle, :rapid_blink, :overline] # probably not supported effects
|
53
45
|
Paint['Ruby'] # don't pass any argument and the string will not be changed
|
@@ -57,11 +49,9 @@ When you pass multiple colors, the first one is taken as foreground color and th
|
|
57
49
|
You can find more examples in the specs.
|
58
50
|
|
59
51
|
== Windows Support
|
60
|
-
|
61
52
|
For ANSI support in Windows OS, you can use {ansicon}[https://github.com/adoxa/ansicon] or {ConEmu}[http://code.google.com/p/conemu-maximus5/].
|
62
53
|
|
63
54
|
== More details about terminal colors and effects
|
64
|
-
|
65
55
|
Terminal colors/effects are set by {ansi escape sequences}[http://en.wikipedia.org/wiki/ANSI_escape_code]. These are strings that look like this: <tt>\e[X;X;X;X;X]m</tt> where X are integers with some meaning. For example, 0 means reset, 31 means red foreground and 41 red background. When you tell Paint to use one of the eight ansi base colors as foreground color, it just inserts a number between 30 and 37 in the sequence. The following colors are available:
|
66
56
|
|
67
57
|
:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, (:default)
|
@@ -73,7 +63,6 @@ Through special sequences it's also possible to set 256-colors, instead of 8, wh
|
|
73
63
|
When using the <tt>Paint.[]</tt> method, Paint wraps the given string between the calculated escape sequence and an reset sequence (<tt>"\e[0m"</tt>). You can get the raw escape sequence by using the <tt>Paint.color</tt> method.
|
74
64
|
|
75
65
|
=== Effects
|
76
|
-
|
77
66
|
Also see {en.wikipedia.org/wiki/ANSI_escape_code}[http://en.wikipedia.org/wiki/ANSI_escape_code]:
|
78
67
|
|
79
68
|
==== Often supported
|
@@ -109,7 +98,6 @@ Also see {en.wikipedia.org/wiki/ANSI_escape_code}[http://en.wikipedia.org/wiki/A
|
|
109
98
|
55) :overline_off
|
110
99
|
|
111
100
|
== Paint.mode
|
112
|
-
|
113
101
|
You can choose between four ways to use <tt>Paint.[]</tt> by setting <tt>Paint.mode</tt> to one of the following:
|
114
102
|
* 256: full support
|
115
103
|
* 16: don't use 256 colors, but the ansi eight ones (combined with bright effect)
|
@@ -118,48 +106,14 @@ You can choose between four ways to use <tt>Paint.[]</tt> by setting <tt>Paint.m
|
|
118
106
|
|
119
107
|
Paint tries to automatically detect the proper value, please open an issue if <tt>Paint.detect_mode</tt> yields a wrong value for you.
|
120
108
|
|
121
|
-
==
|
122
|
-
|
123
|
-
Now for the fancy part: You can create color shortcuts for your gems and scripts! Note: You don't have to use this feature (and only stick to <tt>Paint.[]</tt> instead) ;)
|
124
|
-
|
125
|
-
It's easy: Just setup a hash of symbol keys and escape string values at: <tt>Paint::SHORTCUTS[:your_namespace]</tt>. They are stored directly as escape sequences for performance reasons (this also means, you need different namespaces for different <tt>Paint.mode</tt>s). Example:
|
126
|
-
|
127
|
-
Paint::SHORTCUTS[:example] = {
|
128
|
-
:white => Paint.color(:black),
|
129
|
-
:red => Paint.color(:red, :bright),
|
130
|
-
:title => Paint.color(:underline),
|
131
|
-
}
|
109
|
+
== Random ANSI colors
|
132
110
|
|
133
|
-
|
111
|
+
With 1.0, the :random feature was removed, because it interfered with the caching mechanism. If you still need it, you will have to workaround by generating random colors yourself, before passing them into the Paint method:
|
134
112
|
|
135
|
-
Paint
|
136
|
-
Paint
|
137
|
-
|
138
|
-
As you can see, the helper methods look useful and can take either one (wrap string) or none (only color) arguments ...but they aren't really <em>short</em> yet.
|
139
|
-
|
140
|
-
Fortunately, you can include them:
|
141
|
-
|
142
|
-
include Paint::Example
|
143
|
-
red # => "\e[31;1m"
|
144
|
-
white 'Ruby' # => "\e[30m"
|
145
|
-
|
146
|
-
All shortcuts, defined in your shortcut namespace at this time, are now (privately) available in your current namespace (without using a method_missing implementation).
|
147
|
-
|
148
|
-
Furthermore, there are two variations of this approach:
|
149
|
-
|
150
|
-
include Paint::Example::String
|
151
|
-
"Ruby".title # => "\e[4mRuby\e[0m"
|
152
|
-
5.red # => "\e[31;1m5\e[0m"
|
153
|
-
|
154
|
-
In this case, <tt>self</tt> will be converted to a string and wrapped with the specific color code. Note, that the helper methods doesn't take any arguments when using this inclusion method.
|
155
|
-
|
156
|
-
The third way allows you to get a single color helper method to avoid cluttering namespaces:
|
157
|
-
|
158
|
-
include Paint::Example::Prefix::ExampleName
|
159
|
-
"Ruby".example_name(:red) # => "\e[31;1mRuby\e[0m"
|
160
|
-
|
161
|
-
=== Utilities
|
113
|
+
Paint['Ruby', Paint.random] # get one of eight random ansi foreground colors
|
114
|
+
Paint['Ruby', Paint.random(true)] # get one of eight random ansi background colors
|
162
115
|
|
116
|
+
== Utilities
|
163
117
|
There are some supporting methods available. You can get a <tt>p</tt> like alternative for calling <tt>puts Paint.[]</tt>:
|
164
118
|
|
165
119
|
require 'paint/pa'
|
@@ -169,9 +123,12 @@ Another helper method is <tt>Paint.unpaint</tt>, which removes any ansi colors:
|
|
169
123
|
|
170
124
|
Paint.unpaint( Paint['Ruby', :red, :bright] ).should == 'Ruby'
|
171
125
|
|
126
|
+
== Advanced Usage: Shortcuts
|
127
|
+
There is an extension gem available that allows you to define custom color shortcuts. See {SHORTCUTS.rdoc}[https://github.com/janlelis/paint/blob/master/SHORTCUTS.rdoc] for more information.
|
128
|
+
|
172
129
|
== J-_-L
|
173
130
|
|
174
|
-
Copyright (c) 2011-
|
131
|
+
Copyright (c) 2011-2015 Jan Lelis <http://janlelis.com>, released under the MIT license.
|
175
132
|
|
176
133
|
Mainly influenced by rainbow[https://github.com/sickill/rainbow] and {term-ansicolor}[https://github.com/flori/term-ansicolor]. Contributors[https://github.com/janlelis/paint/contributors]:
|
177
134
|
* {CyberShadow}[https://github.com/CyberShadow]
|
data/Rakefile
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
GEMSPEC = 'paint.gemspec'
|
2
|
-
|
3
|
-
#require 'rake'
|
4
|
-
#require 'rake/rdoctask'
|
5
1
|
require 'fileutils'
|
6
2
|
require 'rspec/core/rake_task'
|
7
3
|
|
8
|
-
|
9
|
-
|
4
|
+
gemspecs = %w[
|
5
|
+
paint.gemspec
|
6
|
+
paint-shortcuts.gemspec
|
7
|
+
]
|
10
8
|
|
11
9
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
12
10
|
t.rspec_opts = [
|
@@ -16,30 +14,29 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
16
14
|
]
|
17
15
|
end
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
task :default => :spec
|
18
|
+
task :test => :spec
|
19
|
+
|
20
|
+
def gemspec_spec_for(gemspec)
|
21
|
+
eval(File.read(gemspec), binding, gemspec)
|
21
22
|
end
|
22
23
|
|
23
|
-
desc "Build the
|
24
|
-
task :
|
25
|
-
sh "gem build #{GEMSPEC}"
|
24
|
+
desc "Build the gems"
|
25
|
+
task :gems do
|
26
26
|
FileUtils.mkdir_p 'pkg'
|
27
|
-
|
27
|
+
gemspecs.each{ |gemspec|
|
28
|
+
sh "gem build #{gemspec}"
|
29
|
+
spec = gemspec_spec_for(gemspec)
|
30
|
+
FileUtils.mv "#{spec.name}-#{spec.version}.gem", 'pkg'
|
31
|
+
}
|
28
32
|
end
|
29
33
|
|
30
34
|
desc "Install the gem locally"
|
31
|
-
task :install => :
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
task :generate do
|
37
|
-
puts gemspec.to_ruby
|
38
|
-
end
|
39
|
-
|
40
|
-
desc "Validate the gemspec"
|
41
|
-
task :gemspec do
|
42
|
-
gemspec.validate
|
35
|
+
task :install => :gems do
|
36
|
+
gemspecs.each{ |gemspec|
|
37
|
+
spec = gemspec_spec_for(gemspec)
|
38
|
+
sh %{gem install pkg/#{spec.name}-#{spec.version}.gem --no-rdoc --no-ri}
|
39
|
+
}
|
43
40
|
end
|
44
41
|
|
45
42
|
desc "Run a Benchmark"
|
@@ -51,8 +48,7 @@ task :benchmark do
|
|
51
48
|
end
|
52
49
|
|
53
50
|
require 'rainbow'
|
54
|
-
|
55
|
-
require 'paint'
|
51
|
+
require_relative 'lib/paint'
|
56
52
|
|
57
53
|
n = 100_000
|
58
54
|
colors = [:black, :red, :green, :yellow, :blue, :magenta, :cyan]
|
data/lib/paint.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative 'paint/version'
|
2
|
+
require_relative 'paint/util'
|
3
|
+
|
4
4
|
|
5
5
|
module Paint
|
6
6
|
autoload :RGB_COLORS, 'paint/rgb_colors'
|
7
7
|
autoload :RGB_COLORS_ANSI, 'paint/rgb_colors_ansi'
|
8
8
|
|
9
|
-
# Important purpose
|
10
9
|
NOTHING = "\033[0m".freeze
|
11
10
|
|
12
11
|
# Basic colors (often, the color differs when using the bright effect)
|
@@ -54,7 +53,6 @@ module Paint
|
|
54
53
|
:overline_off => 55,
|
55
54
|
}.freeze
|
56
55
|
|
57
|
-
# cache
|
58
56
|
ANSI_COLORS_FOREGROUND = {
|
59
57
|
:black => 30,
|
60
58
|
:red => 31,
|
@@ -67,7 +65,6 @@ module Paint
|
|
67
65
|
:default => 39,
|
68
66
|
}.freeze
|
69
67
|
|
70
|
-
# cache
|
71
68
|
ANSI_COLORS_BACKGROUND = {
|
72
69
|
:black => 40,
|
73
70
|
:red => 41,
|
@@ -84,19 +81,14 @@ module Paint
|
|
84
81
|
# Takes a string and color options and colorizes the string
|
85
82
|
# See README.rdoc for details
|
86
83
|
def [](string, *options)
|
87
|
-
return string.to_s if mode.zero? || options.empty?
|
88
|
-
|
89
|
-
|
90
|
-
options = options.first
|
91
|
-
end
|
92
|
-
|
93
|
-
cache[options] + string.to_s + NOTHING
|
84
|
+
return string.to_s if @mode.zero? || options.empty?
|
85
|
+
options = options.first if options.size == 1 && !options.first.respond_to?(:to_ary)
|
86
|
+
@cache[options] + string.to_s + NOTHING
|
94
87
|
end
|
95
88
|
|
96
|
-
#
|
97
|
-
# Used by []
|
89
|
+
# Transforms options into the desired color. Used by @cache
|
98
90
|
def color(*options)
|
99
|
-
return '' if mode.zero? || options.empty?
|
91
|
+
return '' if @mode.zero? || options.empty?
|
100
92
|
mix = []
|
101
93
|
color_seen = false
|
102
94
|
colors = ANSI_COLORS_FOREGROUND
|
@@ -109,16 +101,13 @@ module Paint
|
|
109
101
|
color_seen = :set
|
110
102
|
elsif ANSI_EFFECTS.key?(option)
|
111
103
|
mix << effect(option)
|
112
|
-
elsif option == :random
|
113
|
-
mix << random(color_seen)
|
114
|
-
color_seen = :set
|
115
104
|
else
|
116
105
|
raise ArgumentError, "Unknown color or effect: #{ option }"
|
117
106
|
end
|
118
107
|
|
119
108
|
when Array
|
120
109
|
if option.size == 3 && option.all?{ |n| n.is_a? Numeric }
|
121
|
-
mix << rgb(*
|
110
|
+
mix << rgb(*[*option, color_seen])
|
122
111
|
color_seen = :set
|
123
112
|
else
|
124
113
|
raise ArgumentError, "Array argument must contain 3 numerals"
|
@@ -161,8 +150,8 @@ module Paint
|
|
161
150
|
# * 16 - only ansi colors and bright effect
|
162
151
|
# * 8 - only ansi colors
|
163
152
|
# * 0 - no colorization!
|
164
|
-
|
165
|
-
def mode=(val) cache.clear; @mode = val end
|
153
|
+
attr_reader :mode
|
154
|
+
def mode=(val) @cache.clear; @mode = val end
|
166
155
|
|
167
156
|
# Adds ansi sequence
|
168
157
|
def wrap(*ansi_codes)
|
@@ -176,8 +165,8 @@ module Paint
|
|
176
165
|
|
177
166
|
# Creates a 256-compatible color from rgb values
|
178
167
|
def rgb(red, green, blue, background = false)
|
179
|
-
if mode == 8 || mode == 16
|
180
|
-
"#{background ? 4 : 3}#{rgb_like_value(red, green, blue, mode == 16)}"
|
168
|
+
if @mode == 8 || @mode == 16
|
169
|
+
"#{background ? 4 : 3}#{rgb_like_value(red, green, blue, @mode == 16)}"
|
181
170
|
else
|
182
171
|
"#{background ? 48 : 38}#{rgb_value(red, green, blue)}"
|
183
172
|
end
|
@@ -186,20 +175,18 @@ module Paint
|
|
186
175
|
# Creates 256-compatible color from a html-like color string
|
187
176
|
def hex(string, background = false)
|
188
177
|
string.tr! '#',''
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
end + [background]) # 1.8 workaround
|
196
|
-
)
|
178
|
+
color_code = if string.size == 6
|
179
|
+
string.each_char.each_slice(2).map{ |hex_color| hex_color.join.to_i(16) }
|
180
|
+
else
|
181
|
+
string.each_char.map{ |hex_color_half| (hex_color_half*2).to_i(16) }
|
182
|
+
end
|
183
|
+
rgb(*[*color_code, background])
|
197
184
|
end
|
198
185
|
|
199
186
|
# Creates a 256-color from a name found in Paint::RGB_COLORS (based on rgb.txt)
|
200
187
|
def rgb_name(color_name, background = false)
|
201
188
|
if color_code = RGB_COLORS[color_name]
|
202
|
-
rgb(*
|
189
|
+
rgb(*[*color_code, background])
|
203
190
|
end
|
204
191
|
end
|
205
192
|
|
@@ -213,15 +200,30 @@ module Paint
|
|
213
200
|
ANSI_EFFECTS[effect_name]
|
214
201
|
end
|
215
202
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
203
|
+
# Determine supported colors
|
204
|
+
def detect_mode
|
205
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ # windows
|
206
|
+
if ENV['ANSICON']
|
207
|
+
16
|
208
|
+
elsif ENV['ConEmuANSI'] == 'ON'
|
209
|
+
256
|
210
|
+
else
|
211
|
+
0
|
212
|
+
end
|
213
|
+
else
|
214
|
+
case ENV['TERM']
|
215
|
+
when /-256color$/, 'xterm'
|
216
|
+
256
|
217
|
+
when /-color$/, 'rxvt'
|
218
|
+
16
|
219
|
+
else # optimistic default
|
220
|
+
256
|
221
|
+
end
|
222
|
+
end
|
223
223
|
end
|
224
224
|
|
225
|
+
private
|
226
|
+
|
225
227
|
# Returns nearest supported 256-color an rgb value, without fore-/background information
|
226
228
|
# Inspired by the rainbow gem
|
227
229
|
def rgb_value(red, green, blue)
|
@@ -267,6 +269,10 @@ module Paint
|
|
267
269
|
}
|
268
270
|
end
|
269
271
|
end
|
272
|
+
|
273
|
+
# init instance vars
|
274
|
+
@mode = detect_mode
|
275
|
+
@cache = Hash.new{ |h, k| h[k] = color(*k) }
|
270
276
|
end
|
271
277
|
|
272
278
|
# J-_-L
|
data/lib/paint/util.rb
CHANGED
@@ -10,7 +10,7 @@ module Paint
|
|
10
10
|
|
11
11
|
# Tries to print all 256 colors
|
12
12
|
def rainbow
|
13
|
-
(0...256).each{ |color|
|
13
|
+
(0...256).each{ |color|
|
14
14
|
print Paint[' ', 48, 5, color] # print empty bg color field
|
15
15
|
}
|
16
16
|
puts
|
@@ -32,34 +32,6 @@ module Paint
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
# Determine supported colors
|
36
|
-
# This is just a naive approach, based on some things I could test
|
37
|
-
# Please open issues if it does not work correctly for you
|
38
|
-
def detect_mode
|
39
|
-
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ # windows
|
40
|
-
if ENV['ANSICON']
|
41
|
-
16
|
42
|
-
elsif ENV['ConEmuANSI'] == 'ON'
|
43
|
-
256
|
44
|
-
else
|
45
|
-
0
|
46
|
-
end
|
47
|
-
else
|
48
|
-
# case ENV['COLORTERM']
|
49
|
-
# when 'gnome-terminal'
|
50
|
-
# 256
|
51
|
-
# else
|
52
|
-
case ENV['TERM']
|
53
|
-
when /-256color$/, 'xterm'
|
54
|
-
256
|
55
|
-
when /-color$/, 'rxvt'
|
56
|
-
16
|
57
|
-
else # optimistic default
|
58
|
-
256
|
59
|
-
end
|
60
|
-
# end
|
61
|
-
end
|
62
|
-
end
|
63
35
|
end
|
64
36
|
end
|
65
37
|
|
data/lib/paint/version.rb
CHANGED
data/paint.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
|
3
3
|
require File.dirname(__FILE__) + "/lib/paint/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
@@ -9,14 +9,31 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = "mail@janlelis.de"
|
10
10
|
s.homepage = "https://github.com/janlelis/paint"
|
11
11
|
s.summary = "Terminal painter!"
|
12
|
-
s.description = "Terminal painter
|
13
|
-
s.required_ruby_version = '>= 1.8.7'
|
14
|
-
s.files = Dir.glob(%w[{lib,test,spec}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c}]) + %w{Rakefile paint.gemspec}
|
15
|
-
s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt"]
|
12
|
+
s.description = "Terminal painter: No string extensions / 256 color support / effect support. Usage: Paint['string', :red, :bright]"
|
16
13
|
s.license = 'MIT'
|
17
14
|
|
18
|
-
s.
|
19
|
-
|
15
|
+
s.files = %w[
|
16
|
+
paint.gemspec
|
17
|
+
Rakefile
|
18
|
+
.rspec
|
19
|
+
.travis.yml
|
20
|
+
lib/paint.rb
|
21
|
+
lib/paint/pa.rb
|
22
|
+
lib/paint/rgb_colors.rb
|
23
|
+
lib/paint/rgb_colors_ansi.rb
|
24
|
+
lib/paint/util.rb
|
25
|
+
lib/paint/version.rb
|
26
|
+
]
|
27
|
+
s.extra_rdoc_files = %w[
|
28
|
+
README.rdoc
|
29
|
+
CHANGELOG.rdoc
|
30
|
+
MIT-LICENSE.txt
|
31
|
+
]
|
32
|
+
|
33
|
+
s.required_ruby_version = '>= 1.9.3'
|
34
|
+
s.requirements = ['Windows: ansicon (https://github.com/adoxa/ansicon) or ConEmu (http://code.google.com/p/conemu-maximus5)']
|
35
|
+
s.add_development_dependency 'rspec', '~> 3.2'
|
36
|
+
s.add_development_dependency 'rake', '~> 10.4'
|
20
37
|
s.add_development_dependency 'rainbow', '1.1.4'
|
21
38
|
s.add_development_dependency 'term-ansicolor'
|
22
39
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Lelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3'
|
19
|
+
version: '3.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3'
|
26
|
+
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.4'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rainbow
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,15 +66,18 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: 'Terminal painter
|
70
|
-
support
|
69
|
+
description: 'Terminal painter: No string extensions / 256 color support / effect
|
70
|
+
support. Usage: Paint[''string'', :red, :bright]'
|
71
71
|
email: mail@janlelis.de
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files:
|
75
75
|
- README.rdoc
|
76
|
+
- CHANGELOG.rdoc
|
76
77
|
- MIT-LICENSE.txt
|
77
78
|
files:
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
78
81
|
- CHANGELOG.rdoc
|
79
82
|
- MIT-LICENSE.txt
|
80
83
|
- README.rdoc
|
@@ -83,15 +86,9 @@ files:
|
|
83
86
|
- lib/paint/pa.rb
|
84
87
|
- lib/paint/rgb_colors.rb
|
85
88
|
- lib/paint/rgb_colors_ansi.rb
|
86
|
-
- lib/paint/shortcuts.rb
|
87
89
|
- lib/paint/util.rb
|
88
90
|
- lib/paint/version.rb
|
89
91
|
- paint.gemspec
|
90
|
-
- spec/paint_methods_spec.rb
|
91
|
-
- spec/paint_mode_spec.rb
|
92
|
-
- spec/paint_shortcuts_spec.rb
|
93
|
-
- spec/paint_spec.rb
|
94
|
-
- spec/spec_helper.rb
|
95
92
|
homepage: https://github.com/janlelis/paint
|
96
93
|
licenses:
|
97
94
|
- MIT
|
@@ -104,15 +101,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
101
|
requirements:
|
105
102
|
- - ">="
|
106
103
|
- !ruby/object:Gem::Version
|
107
|
-
version: 1.
|
104
|
+
version: 1.9.3
|
108
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
106
|
requirements:
|
110
107
|
- - ">="
|
111
108
|
- !ruby/object:Gem::Version
|
112
109
|
version: '0'
|
113
|
-
requirements:
|
110
|
+
requirements:
|
111
|
+
- 'Windows: ansicon (https://github.com/adoxa/ansicon) or ConEmu (http://code.google.com/p/conemu-maximus5)'
|
114
112
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.4.6
|
116
114
|
signing_key:
|
117
115
|
specification_version: 4
|
118
116
|
summary: Terminal painter!
|
data/lib/paint/shortcuts.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
module Paint
|
2
|
-
# Hash for defining color/effect shortcuts
|
3
|
-
# See README for details
|
4
|
-
SHORTCUTS = {
|
5
|
-
# :example => { # would create a Paint::Example constant...
|
6
|
-
# :light_red => "\e[31;1m", # with a method .light_red
|
7
|
-
# }
|
8
|
-
}
|
9
|
-
SHORTCUTS.default = {}
|
10
|
-
|
11
|
-
class << self
|
12
|
-
# Paint::SomeModule --> Paint::SHORTCUTS[:some_module]
|
13
|
-
def const_missing(mod_name)
|
14
|
-
# get shortcuts
|
15
|
-
shortcuts = SHORTCUTS[mod_name.to_s.gsub(/[A-Z]/,'_\0').downcase[1..-1].to_sym] || []
|
16
|
-
|
17
|
-
# create module
|
18
|
-
class_eval "module #{mod_name}; end"
|
19
|
-
mod = const_get(mod_name)
|
20
|
-
eigen_mod = class << mod; self; end # 1.8
|
21
|
-
|
22
|
-
# define direct behaviour, class methods
|
23
|
-
# mod.define_singleton_method :method_missing do |color_name, *args|
|
24
|
-
eigen_mod.send:define_method, :method_missing do |color_name, *args|
|
25
|
-
if color_code = shortcuts[color_name]
|
26
|
-
string = Array(args).join
|
27
|
-
return string if Paint.mode.zero?
|
28
|
-
|
29
|
-
if args.empty?
|
30
|
-
color_code
|
31
|
-
else
|
32
|
-
color_code + string + NOTHING
|
33
|
-
end
|
34
|
-
else
|
35
|
-
nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
eigen_mod.send:define_method, :respond_to? do |color_name, *args|
|
40
|
-
shortcuts.include?(color_name) || super(color_name, *args)
|
41
|
-
end
|
42
|
-
|
43
|
-
# define include behaviour, instance methods
|
44
|
-
eigen_mod.send:define_method, :included do |_|
|
45
|
-
shortcuts.each{ |color_name, color_code|
|
46
|
-
define_method color_name do |*args|
|
47
|
-
string = Array(args).join
|
48
|
-
return string if Paint.mode.zero?
|
49
|
-
|
50
|
-
if args.empty?
|
51
|
-
color_code
|
52
|
-
else
|
53
|
-
color_code + string + NOTHING
|
54
|
-
end
|
55
|
-
end
|
56
|
-
}
|
57
|
-
private(*shortcuts.keys) unless shortcuts.empty?
|
58
|
-
end
|
59
|
-
|
60
|
-
# include variations, defined in child modules
|
61
|
-
mod.class_eval "module String; end"
|
62
|
-
string = mod.const_get(:String)
|
63
|
-
eigen_string = class << string; self; end # 1.8
|
64
|
-
eigen_string.send:define_method, :included do |_|
|
65
|
-
shortcuts.each{ |color_name, color_code|
|
66
|
-
define_method color_name do
|
67
|
-
if Paint.mode.zero?
|
68
|
-
to_s
|
69
|
-
else
|
70
|
-
color_code + to_s + NOTHING
|
71
|
-
end
|
72
|
-
end
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
# OK, let's take it one level further ;)
|
77
|
-
mod.class_eval "module Prefix; end"
|
78
|
-
prefix_prefix = mod.const_get(:Prefix)
|
79
|
-
eigen_prefix_prefix = class << prefix_prefix; self; end # 1.8
|
80
|
-
eigen_prefix_prefix.send:define_method, :const_missing do |prefix_name|
|
81
|
-
class_eval "module #{prefix_name}; end"
|
82
|
-
prefix = const_get(prefix_name)
|
83
|
-
eigen_prefix = class << prefix; self; end # 1.8
|
84
|
-
|
85
|
-
eigen_prefix.send:define_method, :included do |_|
|
86
|
-
define_method prefix_name.to_s.gsub(/[A-Z]/,'_\0').downcase[1..-1].to_sym do |color_name|
|
87
|
-
if color_code = shortcuts[color_name]
|
88
|
-
return to_s if Paint.mode.zero?
|
89
|
-
|
90
|
-
color_code + to_s + NOTHING
|
91
|
-
else
|
92
|
-
nil
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
prefix
|
98
|
-
end
|
99
|
-
|
100
|
-
# :)
|
101
|
-
mod
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# J-_-L
|
data/spec/paint_methods_spec.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe 'Paint.color' do
|
4
|
-
it 'only returns a the color escape sequnce and is directly used by Paint.[] with all paramenters except the first; see there fore specs' do end
|
5
|
-
end
|
6
|
-
|
7
|
-
describe 'Paint.simple' do
|
8
|
-
it 'returns ansi code number for one of the eight ansi base colors' do
|
9
|
-
Paint.simple(:red).should == 31
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns background ansi code number for one of the eight ansi base colors if second parameter is true' do
|
13
|
-
Paint.simple(:red, true).should == 41
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'Paint.rgb' do
|
18
|
-
before do
|
19
|
-
Paint.mode = 256
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns ansi code sequence for one of 256 colors' do
|
23
|
-
Paint.rgb(1,2,3).should == '38;5;232'
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'returns background ansi code sequence for one of 256 colors if last parameter is true' do
|
27
|
-
Paint.rgb(1, 2, 3, true).should == '48;5;232'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'Paint.hex' do
|
32
|
-
before do
|
33
|
-
Paint.mode = 256
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns ansi code sequence for one of 256 colors' do
|
37
|
-
Paint.hex("#fff").should == "38;5;255"
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'returns background ansi code sequence for one of 256 colors if second parameter is true' do
|
41
|
-
Paint.hex("123456", true).should == "48;5;24"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'Paint.rbb_name' do
|
46
|
-
before do
|
47
|
-
Paint.mode = 256
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns ansi code sequence for one of 256 colors' do
|
51
|
-
Paint.rgb_name("gold").should == "38;5;226"
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'returns background ansi code sequence for one of 256 colors if second parameter is true' do
|
55
|
-
Paint.rgb_name("gold", true).should == "48;5;226"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe 'Paint.random' do
|
60
|
-
it 'returns ansi code for one of the eight ansi base colors' do
|
61
|
-
(30...38) === Paint.random.should
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'Paint.effect' do
|
66
|
-
it 'returns ansi code for effect using EFFECTS hash' do
|
67
|
-
Paint.effect(:bright).should == 1
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe 'Paint.wrap' do
|
72
|
-
it 'wraps an ansi color code (array of integers) into an ansi escape sequence' do
|
73
|
-
Paint.wrap(31, 1).should == "\e[31;1m"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# util.rb
|
78
|
-
|
79
|
-
describe 'Paint.unpaint' do
|
80
|
-
it 'removes any ansi color escape sequences in the string' do
|
81
|
-
Paint.unpaint( Paint['J-_-L', :red, :bright] ).should == 'J-_-L'
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe 'Paint.rainbow' do
|
86
|
-
it 'prints all available 256 colors' do end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe 'Paint.update_rgb_colors' do
|
90
|
-
it 'updates the Paint::RGB_COLORS hash using rgb.txt (takes path to it as argument)' do end
|
91
|
-
end
|
data/spec/paint_mode_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe 'Paint.mode' do
|
4
|
-
it "works normally if mode is 256 or another unknown true value" do
|
5
|
-
Paint.mode = 256
|
6
|
-
Paint['J-_-L', 'gold'].should == "\e[38;5;226mJ-_-L\e[0m"
|
7
|
-
end
|
8
|
-
|
9
|
-
it "doesn't colorize anything if mode is 0" do
|
10
|
-
Paint.mode = 0
|
11
|
-
Paint['J-_-L', 'gold'].should == "J-_-L"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "only uses the 8 ansi colors if mode is 8" do
|
15
|
-
Paint.mode = 8
|
16
|
-
Paint['J-_-L', 'gold'].should == "\e[33mJ-_-L\e[0m"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "only uses the 8 ansi colors with bright effect if mode is 16" do
|
20
|
-
Paint.mode = 16
|
21
|
-
Paint['J-_-L', 'gold'].should == "\e[33;1mJ-_-L\e[0m"
|
22
|
-
end
|
23
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe 'Paint::SHORTCUTS' do
|
4
|
-
before do
|
5
|
-
Paint::SHORTCUTS[:example] = {
|
6
|
-
:white => Paint.color(:black),
|
7
|
-
:red => Paint.color(:red, :bright),
|
8
|
-
:title => Paint.color(:underline),
|
9
|
-
}
|
10
|
-
|
11
|
-
Paint.mode = 256
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'Paint::Example.method_missing' do
|
15
|
-
it 'returns a color defined in the SHORTCUTS hash under the :example key' do
|
16
|
-
Paint::Example.red.should == "\e[31;1m"
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns a color defined in the SHORTCUTS hash under the :some_module key; method takes string to colorize' do
|
20
|
-
Paint::Example.red('J-_-L').should == "\e[31;1mJ-_-L\e[0m"
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'Paint.mode is 0' do
|
24
|
-
before do
|
25
|
-
Paint.mode = 0
|
26
|
-
end
|
27
|
-
|
28
|
-
it "doesn't colorize a string passed into a color defined in the SHORTCUTS hash under the :some_module key" do
|
29
|
-
Paint::Example.red('J-_-L').should == 'J-_-L'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'include Paint::Example::String' do
|
35
|
-
it 'adds shortcuts methods that colorize self' do
|
36
|
-
class MyString < String
|
37
|
-
include Paint::Example::String
|
38
|
-
end
|
39
|
-
|
40
|
-
MyString.new("J-_-L").red.should == "\e[31;1mJ-_-L\e[0m"
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'adds shortcuts methods that colorize self (also works for non-String classes by calling to_s)' do
|
44
|
-
Paint::SHORTCUTS[:example][:gold] = Paint.color "gold"
|
45
|
-
class Integer
|
46
|
-
include Paint::Example::String
|
47
|
-
end
|
48
|
-
|
49
|
-
123.red.should == "\e[31;1m123\e[0m"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'include Paint::Example::Prefix::ExampleName' do
|
54
|
-
it 'sets a single color helper method to avoid cluttering namespaces' do
|
55
|
-
class Object
|
56
|
-
include Paint::Example::Prefix::ExampleName
|
57
|
-
end
|
58
|
-
|
59
|
-
"Ruby".example_name(:red).should == "\e[31;1mRuby\e[0m"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/spec/paint_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe 'Paint.[]' do
|
4
|
-
before do
|
5
|
-
Paint.mode = 256
|
6
|
-
end
|
7
|
-
|
8
|
-
context '(with no options)' do
|
9
|
-
it "doesn't colorize at all" do
|
10
|
-
Paint['J-_-L'].should == "J-_-L"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context '(with one color)' do
|
15
|
-
it 'understands a simple symbol color and use it as foreground color' do
|
16
|
-
Paint['J-_-L', :yellow].should == "\e[33mJ-_-L\e[0m"
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'understands an array as rgb color definition and use it as foreground color' do
|
20
|
-
Paint['J-_-L', [255, 200, 0]].should == "\e[38;5;220mJ-_-L\e[0m"
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'understands a hex string (with #, 6 digits) as rgb color definition and use it as foreground color' do
|
24
|
-
Paint['J-_-L', "#123456"].should == "\e[38;5;24mJ-_-L\e[0m"
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'understands a hex string (no #, 6 digits) as rgb color definition and use it as foreground color' do
|
28
|
-
Paint['J-_-L', "123456"].should == "\e[38;5;24mJ-_-L\e[0m"
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'understands a hex string (with #, 3 digits) as rgb color definition and use it as foreground color' do
|
32
|
-
Paint['J-_-L', "#fff"].should == "\e[38;5;255mJ-_-L\e[0m"
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'understands a hex string (no #, 3 digits) as rgb color definition and use it as foreground color' do
|
36
|
-
Paint['J-_-L', "fff"].should == "\e[38;5;255mJ-_-L\e[0m"
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'understands a hex string (with uppercased letters) as rgb color definition and use it as foreground color' do
|
40
|
-
Paint['J-_-L', "#4183C4"].should == "\e[38;5;74mJ-_-L\e[0m"
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'understands a non-hex string as rgb color name (rgb.txt) and use it as foreground color' do
|
44
|
-
Paint['J-_-L', "medium purple"].should == "\e[38;5;141mJ-_-L\e[0m"
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'colorizes using a random ansi foreground color' do
|
48
|
-
Paint['J-_-L', :random].should =~ /\e\[3\dmJ-_-L\e\[0m/
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'does not cache randomness' do
|
52
|
-
(0..99).map{ Paint['J-_-L', :random] }.uniq.size.should > 1
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context '(with two colors)' do
|
57
|
-
it 'interprets the first color as foreground color and the second one as background color' do
|
58
|
-
Paint['J-_-L', :yellow, :red].should == "\e[33;41mJ-_-L\e[0m"
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'interprets the first color as foreground color and the second one as background color (rgb)' do
|
62
|
-
Paint['J-_-L', '#424242', [42, 142, 242]].should == "\e[38;5;238;48;5;39mJ-_-L\e[0m"
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'sets only a background color, if first color is nil' do
|
66
|
-
Paint['J-_-L', nil, [42, 142, 242]].should == "\e[48;5;39mJ-_-L\e[0m"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context '(with effects)' do
|
71
|
-
it 'passes effects' do
|
72
|
-
Paint['J-_-L', :bright].should == "\e[1mJ-_-L\e[0m"
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'passes effects, mixed with colors' do
|
76
|
-
Paint['J-_-L', :yellow, :bright].should == "\e[33;1mJ-_-L\e[0m"
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'passes effects, mixed with colors, order does not matter' do
|
80
|
-
Paint['J-_-L', :bright, :yellow].should == "\e[1;33mJ-_-L\e[0m"
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'passes multiple effects' do
|
84
|
-
Paint['J-_-L', :yellow, :red, :bright, :underline, :inverse].should == "\e[33;41;1;4;7mJ-_-L\e[0m"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context '(with plain integers)' do
|
89
|
-
it 'passes integers to final escape sequence' do
|
90
|
-
Paint['J-_-L', 31, 1, 42].should == "\e[31;1;42mJ-_-L\e[0m"
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'passes integers to final escape sequence (mixed with normal arguments)' do
|
94
|
-
Paint['J-_-L', :red, :bright, 42, :underline].should == "\e[31;1;42;4mJ-_-L\e[0m"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|