paint 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -3
- data/CHANGELOG.md +84 -0
- data/README.md +194 -0
- data/Rakefile +9 -0
- data/data/rgb_colors.marshal.gz +0 -0
- data/lib/paint.rb +89 -114
- data/lib/paint/constants.rb +102 -0
- data/lib/paint/rgb_colors.rb +8 -5
- data/lib/paint/util.rb +4 -28
- data/lib/paint/version.rb +1 -1
- data/paint.gemspec +10 -9
- metadata +21 -20
- data/CHANGELOG.rdoc +0 -45
- data/README.rdoc +0 -132
- data/lib/paint/rgb_colors_ansi.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a770bcb2ba94afcf2b0893440ce37df5a0faa835
|
4
|
+
data.tar.gz: 69e81b4d1cab420f02f8ffc4a42b0ecc9e9069c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35e06b35ea02ac6e8b04e3090ed1cad3e299fd5d8482c76afc3ad26440ccb8526586e90c2f713a588e9ba3a6a313c54cfd06be2490afb54289015f239e87158d
|
7
|
+
data.tar.gz: d25fe01cabb5d0ea4bc57d01dbd7ed9925d0522fdee2a60869365f74fb00ac93af1884443983171009cadaac98fef9db094cf6918d59ef10d5e656026a85ab45
|
data/.travis.yml
CHANGED
@@ -2,11 +2,17 @@ sudo: false
|
|
2
2
|
language: ruby
|
3
3
|
|
4
4
|
rvm:
|
5
|
-
- 2.3.
|
5
|
+
- 2.3.3
|
6
6
|
- 2.2
|
7
7
|
- 2.1
|
8
8
|
- 2.0
|
9
|
+
- 1.9.3
|
9
10
|
- ruby-head
|
10
|
-
- rbx-2
|
11
11
|
- jruby-head
|
12
|
-
- jruby-
|
12
|
+
- jruby-9.1.5.0
|
13
|
+
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: jruby-head
|
17
|
+
- rvm: 2.0
|
18
|
+
- rvm: 1.9.3
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
### 2.0.0
|
4
|
+
#### Major Changes
|
5
|
+
|
6
|
+
* New default color mode `0xFFFFFF`: 24bit - true color. If this breaks your code, add `Paint.mode = 256` to the beginning of your code
|
7
|
+
* New `Paint%[]` API: Substitution mechanism for nested color strings
|
8
|
+
|
9
|
+
#### Minor Changes
|
10
|
+
|
11
|
+
* Smaller gem size (compress RGB color name data)
|
12
|
+
* Remove `Paint.update_rgb_colors` and `Paint.rainbow`
|
13
|
+
* Internal method `.hex` renamed to `.rgb_hex` and does not take "#" prefixed strings anymore
|
14
|
+
* Minor refactorings and documentation updates
|
15
|
+
|
16
|
+
### 1.0.1
|
17
|
+
|
18
|
+
* Fix case of string arguments getting mutated (see gh#14)
|
19
|
+
|
20
|
+
|
21
|
+
### 1.0.0
|
22
|
+
|
23
|
+
* Improved performance
|
24
|
+
* Option for :random colors removed (see readme)
|
25
|
+
* Seperate Paint::SHORTCUTS into extra gem
|
26
|
+
* Drop support for Ruby 1 (inoffically still support 1.9.3)
|
27
|
+
|
28
|
+
|
29
|
+
### 0.9.0
|
30
|
+
|
31
|
+
* Don't colorize strings via shortcuts when Paint.mode == 0
|
32
|
+
* Freeze bundled ascii color data
|
33
|
+
|
34
|
+
|
35
|
+
### 0.8.7
|
36
|
+
|
37
|
+
* Fix caching bug for random ansi color
|
38
|
+
|
39
|
+
|
40
|
+
### 0.8.6
|
41
|
+
|
42
|
+
* Add missing require 'rbconfig' and travis test everything
|
43
|
+
|
44
|
+
|
45
|
+
### 0.8.5
|
46
|
+
|
47
|
+
* Support 256 color on windows' ConEmu
|
48
|
+
|
49
|
+
|
50
|
+
### 0.8.4
|
51
|
+
|
52
|
+
* Fix post-install message unicode
|
53
|
+
|
54
|
+
|
55
|
+
### 0.8.3
|
56
|
+
|
57
|
+
* Paint.[] also accepts uppercased hex strings (gh#2)
|
58
|
+
* Performance tweaks (thanks to murphy) (gh#4, #5)
|
59
|
+
* API change: deactivate colorizing with Paint.mode = 0
|
60
|
+
|
61
|
+
|
62
|
+
### 0.8.2
|
63
|
+
|
64
|
+
* Paint.[] with only a single string argument does not colorize the string
|
65
|
+
anymore, but returns the plain string
|
66
|
+
* New pseudo color :random - returns a random ansi color
|
67
|
+
|
68
|
+
|
69
|
+
### 0.8.1
|
70
|
+
|
71
|
+
* Improve rgb function with better gray scale values
|
72
|
+
* Add Paint.mode:
|
73
|
+
* Set to 0 to deactivate colorizing
|
74
|
+
* Set to 16 or 8 and all color generation methods will generate simple
|
75
|
+
ansi colors
|
76
|
+
* Set to 256 for 256 color support
|
77
|
+
* Tries to automatically detect your terminal's features
|
78
|
+
* Minor changes
|
79
|
+
|
80
|
+
|
81
|
+
### 0.8.0
|
82
|
+
|
83
|
+
* Initial release
|
84
|
+
|
data/README.md
ADDED
@@ -0,0 +1,194 @@
|
|
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.svg" />](https://travis-ci.org/janlelis/paint)
|
2
|
+
|
3
|
+
Paint creates terminal colors and effects for you. It combines the strengths of **term-ansicolor**, **rainbow**, and similar projects into a simple to use, however still flexible terminal colors gem with no core extensions by default.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
* No string extensions (suitable for library development)
|
8
|
+
* Simple API
|
9
|
+
* Faster than other terminal color gems ([as of December 2016](https://gist.github.com/janlelis/91413b9295c81ee873dc))
|
10
|
+
* Supports *true color* or 256 colors (for capable terminals)
|
11
|
+
* Allows you to set any terminal effects
|
12
|
+
* `Paint.mode`: Fall-back modes for terminals with less colors, supported modes:
|
13
|
+
* 0xFFFFFF (= 16777215) colors (*true color*)
|
14
|
+
* 256 colors (palette)
|
15
|
+
* 16 colors (only ANSI colors, combined with bright effect)
|
16
|
+
* 8 colors (only ANSI colors)
|
17
|
+
* 0 colors (no colors / deactivate)
|
18
|
+
|
19
|
+
## Paint 2.0 | True Color Support
|
20
|
+
|
21
|
+
Starting with **Paint 2.0**, *true color* mode is the new default mode, since most major terminals now support 24bit colors. If it happens to not work in your setup:
|
22
|
+
|
23
|
+
- Manually set `Paint.mode = 256` at the beginning of your code
|
24
|
+
- Please [open a new issue](https://github.com/janlelis/paint/issues/new) so we can figure out how to blacklist the terminal used
|
25
|
+
|
26
|
+
## Supported Rubies
|
27
|
+
|
28
|
+
* **2.4**, **2.3**, **2.2**, **2.1**
|
29
|
+
|
30
|
+
Unsupported, but might still work:
|
31
|
+
|
32
|
+
* **2.0**, **1.9**
|
33
|
+
|
34
|
+
## Setup
|
35
|
+
|
36
|
+
Add to `Gemfile`:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'paint'
|
40
|
+
```
|
41
|
+
|
42
|
+
and run `bundle install`.
|
43
|
+
|
44
|
+
In Ruby do:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
require 'paint'
|
48
|
+
```
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
The only method you need is: `Paint.[]`
|
53
|
+
|
54
|
+
The first argument given to `Paint.[]` is the string to colorize (if the object is not a string, `to_s` will be called on it). The other arguments describe how to modify/colorize the string. Let's learn by example:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
Paint['Ruby', :red] # Sets ANSI color red
|
58
|
+
Paint['Ruby', :red, :bright] # Also applies bright/bold effect
|
59
|
+
Paint['Ruby', :bright, :red] # Does the same as above
|
60
|
+
Paint['Ruby', :red, :bright, :underline] # Effects can often be combined
|
61
|
+
Paint['Ruby', :red, :blue] # The second color you define is for background
|
62
|
+
Paint['Ruby', nil, :blue] # Pass a nil before a color to ignore foreground and only set background color
|
63
|
+
Paint['Ruby', [100, 255, 5]] # You can define RGB colors. Depending on your terminal, this will create
|
64
|
+
# a "true color" or map to 256/16/8 colors.
|
65
|
+
Paint['Ruby', "gold", "snow"] # Paint supports rgb.txt color names, note that the arguments are strings
|
66
|
+
# (:yellow != "yellow")!
|
67
|
+
Paint['Ruby', "#123456"] # HTML like definitions are possible
|
68
|
+
Paint['Ruby', "fff"] # Another HTML hex definition
|
69
|
+
Paint['Ruby', :inverse] # Swaps fore- and background
|
70
|
+
Paint['Ruby', :italic, :encircle, :rapid_blink, :overline] # Probably not supported effects
|
71
|
+
Paint['Ruby'] # Don't pass any argument and the string will not be changed
|
72
|
+
```
|
73
|
+
|
74
|
+
When you pass multiple colors, the first one is taken as foreground color and the second one defines the background color, every following color will be ignored. To only change the background color, you have to pass a `nil` first. Effects can be passed in any order.
|
75
|
+
|
76
|
+
[You can find more examples in the specs.](https://github.com/janlelis/paint/blob/master/spec/paint_spec.rb)
|
77
|
+
|
78
|
+
[List of rgb.txt colors.](https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart)
|
79
|
+
|
80
|
+
## Windows Support
|
81
|
+
|
82
|
+
For ANSI support in Windows OS, you can use [ansicon](https://github.com/adoxa/ansicon) or [ConEmu](http://code.google.com/p/conemu-maximus5/).
|
83
|
+
|
84
|
+
## `Paint.mode`
|
85
|
+
|
86
|
+
You can choose between five ways to use `Paint.[]` by setting `Paint.mode` to one of the following:
|
87
|
+
|
88
|
+
* **0xFFFFFF**: Use 16777215 *true colors*
|
89
|
+
* **256**: Use the 256 colors palette
|
90
|
+
* **16**: Use the eight ANSI colors (combined with bright effect)
|
91
|
+
* **8**: Use the eight ANSI colors
|
92
|
+
* **0**: Don't colorize at all
|
93
|
+
|
94
|
+
Paint tries to automatically detect the proper value your terminal is capable of, please [open an issue](https://github.com/janlelis/paint/issues/new) if `Paint.detect_mode` yields a wrong value for you.
|
95
|
+
|
96
|
+
## More Details About Terminal Colors and Effects
|
97
|
+
|
98
|
+
Terminal colors/effects get created by [ANSI escape sequences](http://en.wikipedia.org/wiki/ANSI_escape_code). These are strings that look like this: `\e[X;X;X;X;X]m` where X are integers with some meaning. For example, `0` means *reset*, `31` means *red foreground* and `41` stands for 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` into the sequence. The following colors are available:
|
99
|
+
|
100
|
+
* `:black`
|
101
|
+
* `:red`
|
102
|
+
* `:green`
|
103
|
+
* `:yellow`
|
104
|
+
* `:blue`
|
105
|
+
* `:magenta`
|
106
|
+
* `:cyan`
|
107
|
+
* `:white`
|
108
|
+
* (`:default`)
|
109
|
+
|
110
|
+
When combined with the `:bright` (= `:bold`) effect, the color in the terminal emulator often differs a little bit, thus it is possible to represent 16 colors.
|
111
|
+
|
112
|
+
Through special sequences it's also possible to set 256-colors, or even 16777215 colors, instead of only the 8 ANSI ones. However, this is not supported by all terminals. Paint automatically translates given RGB colors to a suitable color of the supported color spectrum.
|
113
|
+
|
114
|
+
When using the `Paint.[]` method, Paint wraps the given string between the calculated escape sequence and an reset sequence (`"\e[0m"`). You can get the raw escape sequence by using the `Paint.color` method.
|
115
|
+
|
116
|
+
### Effects
|
117
|
+
|
118
|
+
See [en.wikipedia.org/wiki/ANSI_escape_code](http://en.wikipedia.org/wiki/ANSI_escape_code) for a more detailed discussion:
|
119
|
+
|
120
|
+
#### Often supported
|
121
|
+
|
122
|
+
0) :reset, :nothing
|
123
|
+
1) :bright, :bold
|
124
|
+
4) :underline
|
125
|
+
7) :inverse, :negative
|
126
|
+
8) :conceal, :hide
|
127
|
+
22) :clean
|
128
|
+
24) :underline_off
|
129
|
+
26) :inverse_off, :positive
|
130
|
+
27) :conceal_off, :show, :reveal
|
131
|
+
|
132
|
+
#### Not widely supported
|
133
|
+
|
134
|
+
2) :faint
|
135
|
+
3) :italic
|
136
|
+
5) :blink, :slow_blink
|
137
|
+
6) :rapid_blink
|
138
|
+
9) :crossed, :crossed_out
|
139
|
+
10) :default_font, :font0
|
140
|
+
11-19) :font1, :font2, :font3, :font4, :font5, :font6, :font7, :font8, :font9
|
141
|
+
20) :fraktur
|
142
|
+
21) :bright_off, :bold_off, :double_underline
|
143
|
+
23) :italic_off, :fraktur_off
|
144
|
+
25) :blink_off
|
145
|
+
29) :crossed_off, :crossed_out_off
|
146
|
+
51) :frame
|
147
|
+
52) :encircle
|
148
|
+
53) :overline
|
149
|
+
54) :frame_off, :encircle_off
|
150
|
+
55) :overline_off
|
151
|
+
|
152
|
+
## Substitution & Nesting
|
153
|
+
|
154
|
+
From time to time, you might find yourself in a situation where you want to colorize a substring differently from the rest of the string. Paint supports this via a simple templating approach using the `%` method with an array argument. Use the `%{var}` notation within a string, and pass the template variables as a hash:
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
Paint%['Yellow string with a %{blue_text} in it', :yellow,
|
158
|
+
blue_text: ["blue text", :blue]
|
159
|
+
]
|
160
|
+
# => "\e[33mYellow string with a \e[34mblue text\e[33m in it\e[0m"
|
161
|
+
```
|
162
|
+
|
163
|
+
## Utilities
|
164
|
+
|
165
|
+
The `Paint.random` method generates a random ANSI color you can pass into `Paint.[]`:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
Paint['Ruby', Paint.random] # Get one of eight random ANSI foreground colors
|
169
|
+
Paint['Ruby', Paint.random(true)] # Get one of eight random ANSI background colors
|
170
|
+
```
|
171
|
+
|
172
|
+
Another helper method is `Paint.unpaint`, which removes any ANSI colors:
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
Paint.unpaint( Paint['Ruby', :red, :bright] ).should == 'Ruby'
|
176
|
+
```
|
177
|
+
|
178
|
+
You can get a `p` like alternative for calling `puts Paint.[]`:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
require 'paint/pa'
|
182
|
+
pa "Ruby", :red, :underline # same as puts Paint["Ruby", :red, :underline]
|
183
|
+
```
|
184
|
+
|
185
|
+
## Advanced Usage: Shortcuts
|
186
|
+
|
187
|
+
There is an extension gem available which allows you to define custom color definitions, which you can reuse later. See [SHORTCUTS.md](https://github.com/janlelis/paint/blob/master/SHORTCUTS.md) for documentation. This is completely optional.
|
188
|
+
|
189
|
+
## J-_-L
|
190
|
+
|
191
|
+
Copyright (c) 2011-2016 Jan Lelis <http://janlelis.com>, released under the
|
192
|
+
MIT license.
|
193
|
+
|
194
|
+
Thank you to [rainbow](https://github.com/sickill/rainbow) and [term-ansicolor](https://github.com/flori/term-ansicolor) for ideas and inspiration. Also, a lot of thanks to all the [contributors](https://github.com/janlelis/paint/contributors)!
|
data/Rakefile
CHANGED
@@ -43,3 +43,12 @@ desc "Run a Benchmark"
|
|
43
43
|
task :benchmark do
|
44
44
|
ruby 'benchmark.rb'
|
45
45
|
end
|
46
|
+
|
47
|
+
desc "Print 256 colors rainbow"
|
48
|
+
task :rainbow256 do
|
49
|
+
require_relative 'lib/paint'
|
50
|
+
(0...256).each{ |color|
|
51
|
+
print Paint[' ', 48, 5, color] # print empty bg color field
|
52
|
+
}
|
53
|
+
puts
|
54
|
+
end
|
Binary file
|
data/lib/paint.rb
CHANGED
@@ -1,91 +1,45 @@
|
|
1
1
|
require_relative 'paint/version'
|
2
|
+
require_relative 'paint/constants'
|
2
3
|
require_relative 'paint/util'
|
3
4
|
|
4
|
-
|
5
5
|
module Paint
|
6
6
|
autoload :RGB_COLORS, 'paint/rgb_colors'
|
7
|
-
autoload :RGB_COLORS_ANSI, 'paint/rgb_colors_ansi'
|
8
|
-
|
9
|
-
NOTHING = "\033[0m".freeze
|
10
|
-
|
11
|
-
# Basic colors (often, the color differs when using the bright effect)
|
12
|
-
# Final color will be 30 + value for foreground and 40 + value for background
|
13
|
-
ANSI_COLORS = {
|
14
|
-
:black => 0,
|
15
|
-
:red => 1,
|
16
|
-
:green => 2,
|
17
|
-
:yellow => 3,
|
18
|
-
:blue => 4,
|
19
|
-
:magenta => 5,
|
20
|
-
:cyan => 6,
|
21
|
-
:white => 7,
|
22
|
-
:default => 9,
|
23
|
-
}.freeze
|
24
|
-
|
25
|
-
# Terminal effects - most of them are not supported ;)
|
26
|
-
# See http://en.wikipedia.org/wiki/ANSI_escape_code
|
27
|
-
ANSI_EFFECTS = {
|
28
|
-
:reset => 0, :nothing => 0, # usually supported
|
29
|
-
:bright => 1, :bold => 1, # usually supported
|
30
|
-
:faint => 2,
|
31
|
-
:italic => 3,
|
32
|
-
:underline => 4, # usually supported
|
33
|
-
:blink => 5, :slow_blink => 5,
|
34
|
-
:rapid_blink => 6,
|
35
|
-
:inverse => 7, :swap => 7, # usually supported
|
36
|
-
:conceal => 8, :hide => 9,
|
37
|
-
:default_font => 10,
|
38
|
-
:font0 => 10, :font1 => 11, :font2 => 12, :font3 => 13, :font4 => 14,
|
39
|
-
:font5 => 15, :font6 => 16, :font7 => 17, :font8 => 18, :font9 => 19,
|
40
|
-
:fraktur => 20,
|
41
|
-
:bright_off => 21, :bold_off => 21, :double_underline => 21,
|
42
|
-
:clean => 22,
|
43
|
-
:italic_off => 23, :fraktur_off => 23,
|
44
|
-
:underline_off => 24,
|
45
|
-
:blink_off => 25,
|
46
|
-
:inverse_off => 26, :positive => 26,
|
47
|
-
:conceal_off => 27, :show => 27, :reveal => 27,
|
48
|
-
:crossed_off => 29, :crossed_out_off => 29,
|
49
|
-
:frame => 51,
|
50
|
-
:encircle => 52,
|
51
|
-
:overline => 53,
|
52
|
-
:frame_off => 54, :encircle_off => 54,
|
53
|
-
:overline_off => 55,
|
54
|
-
}.freeze
|
55
|
-
|
56
|
-
ANSI_COLORS_FOREGROUND = {
|
57
|
-
:black => 30,
|
58
|
-
:red => 31,
|
59
|
-
:green => 32,
|
60
|
-
:yellow => 33,
|
61
|
-
:blue => 34,
|
62
|
-
:magenta => 35,
|
63
|
-
:cyan => 36,
|
64
|
-
:white => 37,
|
65
|
-
:default => 39,
|
66
|
-
}.freeze
|
67
|
-
|
68
|
-
ANSI_COLORS_BACKGROUND = {
|
69
|
-
:black => 40,
|
70
|
-
:red => 41,
|
71
|
-
:green => 42,
|
72
|
-
:yellow => 43,
|
73
|
-
:blue => 44,
|
74
|
-
:magenta => 45,
|
75
|
-
:cyan => 46,
|
76
|
-
:white => 47,
|
77
|
-
:default => 49,
|
78
|
-
}.freeze
|
79
7
|
|
80
8
|
class << self
|
81
|
-
# Takes a string and color options and colorizes the string
|
82
|
-
# See README.rdoc for details
|
9
|
+
# Takes a string and color options and colorizes the string, fast version without nesting
|
83
10
|
def [](string, *options)
|
84
11
|
return string.to_s if @mode.zero? || options.empty?
|
85
|
-
options = options
|
12
|
+
options = options[0] if options.size == 1 && !options[0].respond_to?(:to_ary)
|
86
13
|
@cache[options] + string.to_s + NOTHING
|
87
14
|
end
|
88
15
|
|
16
|
+
# Takes an array with string and color options and colorizes the string,
|
17
|
+
# extended version with nesting and substitution support
|
18
|
+
def %(paint_arguments, clear_color = NOTHING)
|
19
|
+
string, *options = paint_arguments
|
20
|
+
return string.to_s if options.empty?
|
21
|
+
substitutions = options.pop if options[-1].is_a?(Hash)
|
22
|
+
options = options[0] if options.size == 1 && !options[0].respond_to?(:to_ary)
|
23
|
+
current_color = @cache[options]
|
24
|
+
|
25
|
+
# Substitutions & Nesting
|
26
|
+
if substitutions
|
27
|
+
substitutions.each{ |key, value|
|
28
|
+
string.gsub!(
|
29
|
+
"%{#{key}}",
|
30
|
+
(value.is_a?(Array) ? self%[value, current_color] : value.to_s)
|
31
|
+
)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# Wrap string (if Paint.mode > 0)
|
36
|
+
if @mode.zero?
|
37
|
+
string.to_s
|
38
|
+
else
|
39
|
+
current_color + string.to_s + clear_color
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
89
43
|
# Transforms options into the desired color. Used by @cache
|
90
44
|
def color(*options)
|
91
45
|
return '' if @mode.zero? || options.empty?
|
@@ -114,8 +68,8 @@ module Paint
|
|
114
68
|
end
|
115
69
|
|
116
70
|
when ::String
|
117
|
-
if option =~
|
118
|
-
mix <<
|
71
|
+
if option =~ /\A#?(?<hex_color>[[:xdigit:]]{3}{1,2})\z/ # 3 or 6 hex chars
|
72
|
+
mix << rgb_hex($~[:hex_color], color_seen)
|
119
73
|
color_seen = :set
|
120
74
|
else
|
121
75
|
mix << rgb_name(option, color_seen)
|
@@ -146,14 +100,28 @@ module Paint
|
|
146
100
|
|
147
101
|
# This variable influences the color code generation
|
148
102
|
# Currently supported values:
|
149
|
-
# *
|
150
|
-
# *
|
151
|
-
# *
|
152
|
-
# *
|
103
|
+
# * 0xFFFFFF - 24-bit (~16 million) colors, aka truecolor
|
104
|
+
# * 256 - 256 colors
|
105
|
+
# * 16 - only ansi colors and bright effect
|
106
|
+
# * 8 - only ansi colors
|
107
|
+
# * 0 - no colorization!
|
153
108
|
attr_reader :mode
|
154
|
-
def mode=(val)
|
109
|
+
def mode=(val)
|
110
|
+
@cache.clear
|
111
|
+
|
112
|
+
case val
|
113
|
+
when 0, 8, 16, 256, TRUE_COLOR
|
114
|
+
@mode = val
|
115
|
+
when TrueClass
|
116
|
+
@mode = TRUE_COLOR
|
117
|
+
when nil
|
118
|
+
@mode = 0
|
119
|
+
else
|
120
|
+
raise ArgumentError, "Cannot set paint mode to value <#{val}>, possible values are: 0xFFFFFF (true), 256, 16, 8, 0 (nil)"
|
121
|
+
end
|
122
|
+
end
|
155
123
|
|
156
|
-
# Adds
|
124
|
+
# Adds ANSI sequence
|
157
125
|
def wrap(*ansi_codes)
|
158
126
|
"\033[" + ansi_codes*";" + "m"
|
159
127
|
end
|
@@ -163,50 +131,52 @@ module Paint
|
|
163
131
|
(background ? 40 : 30) + ANSI_COLORS[color_name]
|
164
132
|
end
|
165
133
|
|
166
|
-
#
|
134
|
+
# If not true_color, creates a 256-compatible color from rgb values,
|
135
|
+
# otherwise, an exact 24-bit color
|
167
136
|
def rgb(red, green, blue, background = false)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
137
|
+
case @mode
|
138
|
+
when 8
|
139
|
+
"#{background ? 4 : 3}#{rgb_to_ansi(red, green, blue, false)}"
|
140
|
+
when 16
|
141
|
+
"#{background ? 4 : 3}#{rgb_to_ansi(red, green, blue, true)}"
|
142
|
+
when 256
|
143
|
+
"#{background ? 48 : 38}#{rgb_to_256(red, green, blue)}"
|
144
|
+
when TRUE_COLOR
|
145
|
+
"#{background ? 48 : 38}#{rgb_true(red, green, blue)}"
|
172
146
|
end
|
173
147
|
end
|
174
148
|
|
175
|
-
# Creates
|
176
|
-
def
|
177
|
-
string
|
178
|
-
|
179
|
-
string.each_char.each_slice(2).map{ |hex_color| hex_color.join.to_i(16) }
|
180
|
-
|
181
|
-
string.each_char.map{ |hex_color_half| (hex_color_half*2).to_i(16) }
|
149
|
+
# Creates RGB color from a HTML-like color definition string
|
150
|
+
def rgb_hex(string, background = false)
|
151
|
+
case string.size
|
152
|
+
when 6
|
153
|
+
color_code = string.each_char.each_slice(2).map{ |hex_color| hex_color.join.to_i(16) }
|
154
|
+
when 3
|
155
|
+
color_code = string.each_char.map{ |hex_color_half| (hex_color_half*2).to_i(16) }
|
182
156
|
end
|
183
157
|
rgb(*[*color_code, background])
|
184
158
|
end
|
185
159
|
|
186
|
-
# Creates a
|
160
|
+
# Creates a RGB from a name found in Paint::RGB_COLORS (based on rgb.txt)
|
187
161
|
def rgb_name(color_name, background = false)
|
188
162
|
if color_code = RGB_COLORS[color_name]
|
189
163
|
rgb(*[*color_code, background])
|
190
164
|
end
|
191
165
|
end
|
192
166
|
|
193
|
-
# Creates a random ansi color
|
194
|
-
def random(background = false)
|
195
|
-
(background ? 40 : 30) + rand(8)
|
196
|
-
end
|
197
|
-
|
198
167
|
# Creates the specified effect by looking it up in Paint::ANSI_EFFECTS
|
199
168
|
def effect(effect_name)
|
200
169
|
ANSI_EFFECTS[effect_name]
|
201
170
|
end
|
202
171
|
|
203
172
|
# Determine supported colors
|
173
|
+
# Note: there's no reliable test for 24-bit color support
|
204
174
|
def detect_mode
|
205
175
|
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ # windows
|
206
176
|
if ENV['ANSICON']
|
207
177
|
16
|
208
178
|
elsif ENV['ConEmuANSI'] == 'ON'
|
209
|
-
|
179
|
+
TRUE_COLOR
|
210
180
|
else
|
211
181
|
0
|
212
182
|
end
|
@@ -224,9 +194,17 @@ module Paint
|
|
224
194
|
|
225
195
|
private
|
226
196
|
|
227
|
-
# Returns
|
197
|
+
# Returns 24-bit color value (see https://gist.github.com/XVilka/8346728)
|
198
|
+
# in ANSI escape sequnce format, without fore-/background information
|
199
|
+
def rgb_true(red, green, blue)
|
200
|
+
";2;#{red};#{green};#{blue}"
|
201
|
+
end
|
202
|
+
|
203
|
+
# Returns closest supported 256-color an RGB value, without fore-/background information
|
228
204
|
# Inspired by the rainbow gem
|
229
|
-
def
|
205
|
+
def rgb_to_256(red, green, blue, approx = true)
|
206
|
+
return ";2;#{red};#{green};#{blue}" unless approx
|
207
|
+
|
230
208
|
gray_possible = true
|
231
209
|
sep = 42.5
|
232
210
|
|
@@ -247,23 +225,22 @@ module Paint
|
|
247
225
|
end
|
248
226
|
end
|
249
227
|
|
250
|
-
# Returns
|
228
|
+
# Returns best ANSI color matching an RGB value, without fore-/background information
|
251
229
|
# See http://mail.python.org/pipermail/python-list/2008-December/1150496.html
|
252
|
-
def
|
230
|
+
def rgb_to_ansi(red, green, blue, use_bright = false)
|
253
231
|
color_pool = RGB_COLORS_ANSI.values
|
254
232
|
color_pool += RGB_COLORS_ANSI_BRIGHT.values if use_bright
|
255
233
|
|
256
|
-
ansi_color_rgb = color_pool.min_by{ |col|
|
257
|
-
|
258
|
-
if ansi_color = RGB_COLORS_ANSI.send(key_method, ansi_color_rgb)
|
234
|
+
ansi_color_rgb = color_pool.min_by{ |col| rgb_color_distance([red, green, blue],col) }
|
235
|
+
if ansi_color = RGB_COLORS_ANSI.key(ansi_color_rgb)
|
259
236
|
ANSI_COLORS[ansi_color]
|
260
237
|
else
|
261
|
-
ansi_color = RGB_COLORS_ANSI_BRIGHT.
|
238
|
+
ansi_color = RGB_COLORS_ANSI_BRIGHT.key(ansi_color_rgb)
|
262
239
|
"#{ANSI_COLORS[ansi_color]};1"
|
263
240
|
end
|
264
241
|
end
|
265
242
|
|
266
|
-
def
|
243
|
+
def rgb_color_distance(rgb1, rgb2)
|
267
244
|
rgb1.zip(rgb2).inject(0){ |acc, (cur1, cur2)|
|
268
245
|
acc + (cur1 - cur2)**2
|
269
246
|
}
|
@@ -274,5 +251,3 @@ module Paint
|
|
274
251
|
@mode = detect_mode
|
275
252
|
@cache = Hash.new{ |h, k| h[k] = color(*k) }
|
276
253
|
end
|
277
|
-
|
278
|
-
# J-_-L
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Paint
|
2
|
+
# Clears all colors
|
3
|
+
NOTHING = "\033[0m".freeze
|
4
|
+
|
5
|
+
# Number of possible colors in TRUE COLOR mode
|
6
|
+
TRUE_COLOR = 0xFFFFFF
|
7
|
+
|
8
|
+
# Basic colors (often, the color differs when using the bright effect)
|
9
|
+
# Final color will be 30 + value for foreground and 40 + value for background
|
10
|
+
ANSI_COLORS = {
|
11
|
+
:black => 0,
|
12
|
+
:red => 1,
|
13
|
+
:green => 2,
|
14
|
+
:yellow => 3,
|
15
|
+
:blue => 4,
|
16
|
+
:magenta => 5,
|
17
|
+
:cyan => 6,
|
18
|
+
:white => 7,
|
19
|
+
:default => 9,
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
ANSI_COLORS_FOREGROUND = {
|
23
|
+
:black => 30,
|
24
|
+
:red => 31,
|
25
|
+
:green => 32,
|
26
|
+
:yellow => 33,
|
27
|
+
:blue => 34,
|
28
|
+
:magenta => 35,
|
29
|
+
:cyan => 36,
|
30
|
+
:white => 37,
|
31
|
+
:default => 39,
|
32
|
+
}.freeze
|
33
|
+
|
34
|
+
ANSI_COLORS_BACKGROUND = {
|
35
|
+
:black => 40,
|
36
|
+
:red => 41,
|
37
|
+
:green => 42,
|
38
|
+
:yellow => 43,
|
39
|
+
:blue => 44,
|
40
|
+
:magenta => 45,
|
41
|
+
:cyan => 46,
|
42
|
+
:white => 47,
|
43
|
+
:default => 49,
|
44
|
+
}.freeze
|
45
|
+
|
46
|
+
# Terminal effects - most of them are not supported ;)
|
47
|
+
# See http://en.wikipedia.org/wiki/ANSI_escape_code
|
48
|
+
ANSI_EFFECTS = {
|
49
|
+
:reset => 0, :nothing => 0, # usually supported
|
50
|
+
:bright => 1, :bold => 1, # usually supported
|
51
|
+
:faint => 2,
|
52
|
+
:italic => 3,
|
53
|
+
:underline => 4, # usually supported
|
54
|
+
:blink => 5, :slow_blink => 5,
|
55
|
+
:rapid_blink => 6,
|
56
|
+
:inverse => 7, :swap => 7, # usually supported
|
57
|
+
:conceal => 8, :hide => 9,
|
58
|
+
:default_font => 10,
|
59
|
+
:font0 => 10, :font1 => 11, :font2 => 12, :font3 => 13, :font4 => 14,
|
60
|
+
:font5 => 15, :font6 => 16, :font7 => 17, :font8 => 18, :font9 => 19,
|
61
|
+
:fraktur => 20,
|
62
|
+
:bright_off => 21, :bold_off => 21, :double_underline => 21,
|
63
|
+
:clean => 22,
|
64
|
+
:italic_off => 23, :fraktur_off => 23,
|
65
|
+
:underline_off => 24,
|
66
|
+
:blink_off => 25,
|
67
|
+
:inverse_off => 26, :positive => 26,
|
68
|
+
:conceal_off => 27, :show => 27, :reveal => 27,
|
69
|
+
:crossed_off => 29, :crossed_out_off => 29,
|
70
|
+
:frame => 51,
|
71
|
+
:encircle => 52,
|
72
|
+
:overline => 53,
|
73
|
+
:frame_off => 54, :encircle_off => 54,
|
74
|
+
:overline_off => 55,
|
75
|
+
}.freeze
|
76
|
+
|
77
|
+
# A list of color names for standard ansi colors, needed for 16/8 color fallback mode
|
78
|
+
# See http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
79
|
+
RGB_COLORS_ANSI = {
|
80
|
+
:black => [ 0, 0, 0],
|
81
|
+
:red => [205, 0, 0],
|
82
|
+
:green => [ 0, 205, 0],
|
83
|
+
:yellow => [205, 205, 0],
|
84
|
+
:blue => [ 0, 0, 238],
|
85
|
+
:magenta => [205, 0, 205],
|
86
|
+
:cyan => [ 0, 205, 205],
|
87
|
+
:white => [229, 229, 229],
|
88
|
+
}.each { |k, v| v.freeze }.freeze
|
89
|
+
|
90
|
+
# A list of color names for standard bright ansi colors, needed for 16 color fallback mode
|
91
|
+
# See http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
92
|
+
RGB_COLORS_ANSI_BRIGHT = {
|
93
|
+
:black => [127, 127, 127],
|
94
|
+
:red => [255, 0, 0],
|
95
|
+
:green => [ 0, 255, 0],
|
96
|
+
:yellow => [255, 255, 0],
|
97
|
+
:blue => [ 92, 92, 255],
|
98
|
+
:magenta => [255, 0, 255],
|
99
|
+
:cyan => [ 0, 255, 255],
|
100
|
+
:white => [255, 255, 255],
|
101
|
+
}.each { |k, v| v.freeze }.freeze
|
102
|
+
end
|
data/lib/paint/rgb_colors.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
module Paint
|
2
2
|
# A list of color names, based on X11's rgb.txt
|
3
|
-
|
4
|
-
|
5
|
-
RGB_COLORS = {"snow"=>[255, 250, 250], "ghost white"=>[248, 248, 255], "GhostWhite"=>[248, 248, 255], "white smoke"=>[245, 245, 245], "WhiteSmoke"=>[245, 245, 245], "gainsboro"=>[220, 220, 220], "floral white"=>[255, 250, 240], "FloralWhite"=>[255, 250, 240], "old lace"=>[253, 245, 230], "OldLace"=>[253, 245, 230], "linen"=>[250, 240, 230], "antique white"=>[250, 235, 215], "AntiqueWhite"=>[250, 235, 215], "papaya whip"=>[255, 239, 213], "PapayaWhip"=>[255, 239, 213], "blanched almond"=>[255, 235, 205], "BlanchedAlmond"=>[255, 235, 205], "bisque"=>[255, 228, 196], "peach puff"=>[255, 218, 185], "PeachPuff"=>[255, 218, 185], "navajo white"=>[255, 222, 173], "NavajoWhite"=>[255, 222, 173], "moccasin"=>[255, 228, 181], "cornsilk"=>[255, 248, 220], "ivory"=>[255, 255, 240], "lemon chiffon"=>[255, 250, 205], "LemonChiffon"=>[255, 250, 205], "seashell"=>[255, 245, 238], "honeydew"=>[240, 255, 240], "mint cream"=>[245, 255, 250], "MintCream"=>[245, 255, 250], "azure"=>[240, 255, 255], "alice blue"=>[240, 248, 255], "AliceBlue"=>[240, 248, 255], "lavender"=>[230, 230, 250], "lavender blush"=>[255, 240, 245], "LavenderBlush"=>[255, 240, 245], "misty rose"=>[255, 228, 225], "MistyRose"=>[255, 228, 225], "white"=>[255, 255, 255], "black"=>[0, 0, 0], "dark slate gray"=>[47, 79, 79], "DarkSlateGray"=>[47, 79, 79], "dark slate grey"=>[47, 79, 79], "DarkSlateGrey"=>[47, 79, 79], "dim gray"=>[105, 105, 105], "DimGray"=>[105, 105, 105], "dim grey"=>[105, 105, 105], "DimGrey"=>[105, 105, 105], "slate gray"=>[112, 128, 144], "SlateGray"=>[112, 128, 144], "slate grey"=>[112, 128, 144], "SlateGrey"=>[112, 128, 144], "light slate gray"=>[119, 136, 153], "LightSlateGray"=>[119, 136, 153], "light slate grey"=>[119, 136, 153], "LightSlateGrey"=>[119, 136, 153], "gray"=>[190, 190, 190], "grey"=>[190, 190, 190], "light grey"=>[211, 211, 211], "LightGrey"=>[211, 211, 211], "light gray"=>[211, 211, 211], "LightGray"=>[211, 211, 211], "midnight blue"=>[25, 25, 112], "MidnightBlue"=>[25, 25, 112], "navy"=>[0, 0, 128], "navy blue"=>[0, 0, 128], "NavyBlue"=>[0, 0, 128], "cornflower blue"=>[100, 149, 237], "CornflowerBlue"=>[100, 149, 237], "dark slate blue"=>[72, 61, 139], "DarkSlateBlue"=>[72, 61, 139], "slate blue"=>[106, 90, 205], "SlateBlue"=>[106, 90, 205], "medium slate blue"=>[123, 104, 238], "MediumSlateBlue"=>[123, 104, 238], "light slate blue"=>[132, 112, 255], "LightSlateBlue"=>[132, 112, 255], "medium blue"=>[0, 0, 205], "MediumBlue"=>[0, 0, 205], "royal blue"=>[65, 105, 225], "RoyalBlue"=>[65, 105, 225], "blue"=>[0, 0, 255], "dodger blue"=>[30, 144, 255], "DodgerBlue"=>[30, 144, 255], "deep sky blue"=>[0, 191, 255], "DeepSkyBlue"=>[0, 191, 255], "sky blue"=>[135, 206, 235], "SkyBlue"=>[135, 206, 235], "light sky blue"=>[135, 206, 250], "LightSkyBlue"=>[135, 206, 250], "steel blue"=>[70, 130, 180], "SteelBlue"=>[70, 130, 180], "light steel blue"=>[176, 196, 222], "LightSteelBlue"=>[176, 196, 222], "light blue"=>[173, 216, 230], "LightBlue"=>[173, 216, 230], "powder blue"=>[176, 224, 230], "PowderBlue"=>[176, 224, 230], "pale turquoise"=>[175, 238, 238], "PaleTurquoise"=>[175, 238, 238], "dark turquoise"=>[0, 206, 209], "DarkTurquoise"=>[0, 206, 209], "medium turquoise"=>[72, 209, 204], "MediumTurquoise"=>[72, 209, 204], "turquoise"=>[64, 224, 208], "cyan"=>[0, 255, 255], "light cyan"=>[224, 255, 255], "LightCyan"=>[224, 255, 255], "cadet blue"=>[95, 158, 160], "CadetBlue"=>[95, 158, 160], "medium aquamarine"=>[102, 205, 170], "MediumAquamarine"=>[102, 205, 170], "aquamarine"=>[127, 255, 212], "dark green"=>[0, 100, 0], "DarkGreen"=>[0, 100, 0], "dark olive green"=>[85, 107, 47], "DarkOliveGreen"=>[85, 107, 47], "dark sea green"=>[143, 188, 143], "DarkSeaGreen"=>[143, 188, 143], "sea green"=>[46, 139, 87], "SeaGreen"=>[46, 139, 87], "medium sea green"=>[60, 179, 113], "MediumSeaGreen"=>[60, 179, 113], "light sea green"=>[32, 178, 170], "LightSeaGreen"=>[32, 178, 170], "pale green"=>[152, 251, 152], "PaleGreen"=>[152, 251, 152], "spring green"=>[0, 255, 127], "SpringGreen"=>[0, 255, 127], "lawn green"=>[124, 252, 0], "LawnGreen"=>[124, 252, 0], "green"=>[0, 255, 0], "chartreuse"=>[127, 255, 0], "medium spring green"=>[0, 250, 154], "MediumSpringGreen"=>[0, 250, 154], "green yellow"=>[173, 255, 47], "GreenYellow"=>[173, 255, 47], "lime green"=>[50, 205, 50], "LimeGreen"=>[50, 205, 50], "yellow green"=>[154, 205, 50], "YellowGreen"=>[154, 205, 50], "forest green"=>[34, 139, 34], "ForestGreen"=>[34, 139, 34], "olive drab"=>[107, 142, 35], "OliveDrab"=>[107, 142, 35], "dark khaki"=>[189, 183, 107], "DarkKhaki"=>[189, 183, 107], "khaki"=>[240, 230, 140], "pale goldenrod"=>[238, 232, 170], "PaleGoldenrod"=>[238, 232, 170], "light goldenrod yellow"=>[250, 250, 210], "LightGoldenrodYellow"=>[250, 250, 210], "light yellow"=>[255, 255, 224], "LightYellow"=>[255, 255, 224], "yellow"=>[255, 255, 0], "gold"=>[255, 215, 0], "light goldenrod"=>[238, 221, 130], "LightGoldenrod"=>[238, 221, 130], "goldenrod"=>[218, 165, 32], "dark goldenrod"=>[184, 134, 11], "DarkGoldenrod"=>[184, 134, 11], "rosy brown"=>[188, 143, 143], "RosyBrown"=>[188, 143, 143], "indian red"=>[205, 92, 92], "IndianRed"=>[205, 92, 92], "saddle brown"=>[139, 69, 19], "SaddleBrown"=>[139, 69, 19], "sienna"=>[160, 82, 45], "peru"=>[205, 133, 63], "burlywood"=>[222, 184, 135], "beige"=>[245, 245, 220], "wheat"=>[245, 222, 179], "sandy brown"=>[244, 164, 96], "SandyBrown"=>[244, 164, 96], "tan"=>[210, 180, 140], "chocolate"=>[210, 105, 30], "firebrick"=>[178, 34, 34], "brown"=>[165, 42, 42], "dark salmon"=>[233, 150, 122], "DarkSalmon"=>[233, 150, 122], "salmon"=>[250, 128, 114], "light salmon"=>[255, 160, 122], "LightSalmon"=>[255, 160, 122], "orange"=>[255, 165, 0], "dark orange"=>[255, 140, 0], "DarkOrange"=>[255, 140, 0], "coral"=>[255, 127, 80], "light coral"=>[240, 128, 128], "LightCoral"=>[240, 128, 128], "tomato"=>[255, 99, 71], "orange red"=>[255, 69, 0], "OrangeRed"=>[255, 69, 0], "red"=>[255, 0, 0], "hot pink"=>[255, 105, 180], "HotPink"=>[255, 105, 180], "deep pink"=>[255, 20, 147], "DeepPink"=>[255, 20, 147], "pink"=>[255, 192, 203], "light pink"=>[255, 182, 193], "LightPink"=>[255, 182, 193], "pale violet red"=>[219, 112, 147], "PaleVioletRed"=>[219, 112, 147], "maroon"=>[176, 48, 96], "medium violet red"=>[199, 21, 133], "MediumVioletRed"=>[199, 21, 133], "violet red"=>[208, 32, 144], "VioletRed"=>[208, 32, 144], "magenta"=>[255, 0, 255], "violet"=>[238, 130, 238], "plum"=>[221, 160, 221], "orchid"=>[218, 112, 214], "medium orchid"=>[186, 85, 211], "MediumOrchid"=>[186, 85, 211], "dark orchid"=>[153, 50, 204], "DarkOrchid"=>[153, 50, 204], "dark violet"=>[148, 0, 211], "DarkViolet"=>[148, 0, 211], "blue violet"=>[138, 43, 226], "BlueViolet"=>[138, 43, 226], "purple"=>[160, 32, 240], "medium purple"=>[147, 112, 219], "MediumPurple"=>[147, 112, 219], "thistle"=>[216, 191, 216], "snow1"=>[255, 250, 250], "snow2"=>[238, 233, 233], "snow3"=>[205, 201, 201], "snow4"=>[139, 137, 137], "seashell1"=>[255, 245, 238], "seashell2"=>[238, 229, 222], "seashell3"=>[205, 197, 191], "seashell4"=>[139, 134, 130], "AntiqueWhite1"=>[255, 239, 219], "AntiqueWhite2"=>[238, 223, 204], "AntiqueWhite3"=>[205, 192, 176], "AntiqueWhite4"=>[139, 131, 120], "bisque1"=>[255, 228, 196], "bisque2"=>[238, 213, 183], "bisque3"=>[205, 183, 158], "bisque4"=>[139, 125, 107], "PeachPuff1"=>[255, 218, 185], "PeachPuff2"=>[238, 203, 173], "PeachPuff3"=>[205, 175, 149], "PeachPuff4"=>[139, 119, 101], "NavajoWhite1"=>[255, 222, 173], "NavajoWhite2"=>[238, 207, 161], "NavajoWhite3"=>[205, 179, 139], "NavajoWhite4"=>[139, 121, 94], "LemonChiffon1"=>[255, 250, 205], "LemonChiffon2"=>[238, 233, 191], "LemonChiffon3"=>[205, 201, 165], "LemonChiffon4"=>[139, 137, 112], "cornsilk1"=>[255, 248, 220], "cornsilk2"=>[238, 232, 205], "cornsilk3"=>[205, 200, 177], "cornsilk4"=>[139, 136, 120], "ivory1"=>[255, 255, 240], "ivory2"=>[238, 238, 224], "ivory3"=>[205, 205, 193], "ivory4"=>[139, 139, 131], "honeydew1"=>[240, 255, 240], "honeydew2"=>[224, 238, 224], "honeydew3"=>[193, 205, 193], "honeydew4"=>[131, 139, 131], "LavenderBlush1"=>[255, 240, 245], "LavenderBlush2"=>[238, 224, 229], "LavenderBlush3"=>[205, 193, 197], "LavenderBlush4"=>[139, 131, 134], "MistyRose1"=>[255, 228, 225], "MistyRose2"=>[238, 213, 210], "MistyRose3"=>[205, 183, 181], "MistyRose4"=>[139, 125, 123], "azure1"=>[240, 255, 255], "azure2"=>[224, 238, 238], "azure3"=>[193, 205, 205], "azure4"=>[131, 139, 139], "SlateBlue1"=>[131, 111, 255], "SlateBlue2"=>[122, 103, 238], "SlateBlue3"=>[105, 89, 205], "SlateBlue4"=>[71, 60, 139], "RoyalBlue1"=>[72, 118, 255], "RoyalBlue2"=>[67, 110, 238], "RoyalBlue3"=>[58, 95, 205], "RoyalBlue4"=>[39, 64, 139], "blue1"=>[0, 0, 255], "blue2"=>[0, 0, 238], "blue3"=>[0, 0, 205], "blue4"=>[0, 0, 139], "DodgerBlue1"=>[30, 144, 255], "DodgerBlue2"=>[28, 134, 238], "DodgerBlue3"=>[24, 116, 205], "DodgerBlue4"=>[16, 78, 139], "SteelBlue1"=>[99, 184, 255], "SteelBlue2"=>[92, 172, 238], "SteelBlue3"=>[79, 148, 205], "SteelBlue4"=>[54, 100, 139], "DeepSkyBlue1"=>[0, 191, 255], "DeepSkyBlue2"=>[0, 178, 238], "DeepSkyBlue3"=>[0, 154, 205], "DeepSkyBlue4"=>[0, 104, 139], "SkyBlue1"=>[135, 206, 255], "SkyBlue2"=>[126, 192, 238], "SkyBlue3"=>[108, 166, 205], "SkyBlue4"=>[74, 112, 139], "LightSkyBlue1"=>[176, 226, 255], "LightSkyBlue2"=>[164, 211, 238], "LightSkyBlue3"=>[141, 182, 205], "LightSkyBlue4"=>[96, 123, 139], "SlateGray1"=>[198, 226, 255], "SlateGray2"=>[185, 211, 238], "SlateGray3"=>[159, 182, 205], "SlateGray4"=>[108, 123, 139], "LightSteelBlue1"=>[202, 225, 255], "LightSteelBlue2"=>[188, 210, 238], "LightSteelBlue3"=>[162, 181, 205], "LightSteelBlue4"=>[110, 123, 139], "LightBlue1"=>[191, 239, 255], "LightBlue2"=>[178, 223, 238], "LightBlue3"=>[154, 192, 205], "LightBlue4"=>[104, 131, 139], "LightCyan1"=>[224, 255, 255], "LightCyan2"=>[209, 238, 238], "LightCyan3"=>[180, 205, 205], "LightCyan4"=>[122, 139, 139], "PaleTurquoise1"=>[187, 255, 255], "PaleTurquoise2"=>[174, 238, 238], "PaleTurquoise3"=>[150, 205, 205], "PaleTurquoise4"=>[102, 139, 139], "CadetBlue1"=>[152, 245, 255], "CadetBlue2"=>[142, 229, 238], "CadetBlue3"=>[122, 197, 205], "CadetBlue4"=>[83, 134, 139], "turquoise1"=>[0, 245, 255], "turquoise2"=>[0, 229, 238], "turquoise3"=>[0, 197, 205], "turquoise4"=>[0, 134, 139], "cyan1"=>[0, 255, 255], "cyan2"=>[0, 238, 238], "cyan3"=>[0, 205, 205], "cyan4"=>[0, 139, 139], "DarkSlateGray1"=>[151, 255, 255], "DarkSlateGray2"=>[141, 238, 238], "DarkSlateGray3"=>[121, 205, 205], "DarkSlateGray4"=>[82, 139, 139], "aquamarine1"=>[127, 255, 212], "aquamarine2"=>[118, 238, 198], "aquamarine3"=>[102, 205, 170], "aquamarine4"=>[69, 139, 116], "DarkSeaGreen1"=>[193, 255, 193], "DarkSeaGreen2"=>[180, 238, 180], "DarkSeaGreen3"=>[155, 205, 155], "DarkSeaGreen4"=>[105, 139, 105], "SeaGreen1"=>[84, 255, 159], "SeaGreen2"=>[78, 238, 148], "SeaGreen3"=>[67, 205, 128], "SeaGreen4"=>[46, 139, 87], "PaleGreen1"=>[154, 255, 154], "PaleGreen2"=>[144, 238, 144], "PaleGreen3"=>[124, 205, 124], "PaleGreen4"=>[84, 139, 84], "SpringGreen1"=>[0, 255, 127], "SpringGreen2"=>[0, 238, 118], "SpringGreen3"=>[0, 205, 102], "SpringGreen4"=>[0, 139, 69], "green1"=>[0, 255, 0], "green2"=>[0, 238, 0], "green3"=>[0, 205, 0], "green4"=>[0, 139, 0], "chartreuse1"=>[127, 255, 0], "chartreuse2"=>[118, 238, 0], "chartreuse3"=>[102, 205, 0], "chartreuse4"=>[69, 139, 0], "OliveDrab1"=>[192, 255, 62], "OliveDrab2"=>[179, 238, 58], "OliveDrab3"=>[154, 205, 50], "OliveDrab4"=>[105, 139, 34], "DarkOliveGreen1"=>[202, 255, 112], "DarkOliveGreen2"=>[188, 238, 104], "DarkOliveGreen3"=>[162, 205, 90], "DarkOliveGreen4"=>[110, 139, 61], "khaki1"=>[255, 246, 143], "khaki2"=>[238, 230, 133], "khaki3"=>[205, 198, 115], "khaki4"=>[139, 134, 78], "LightGoldenrod1"=>[255, 236, 139], "LightGoldenrod2"=>[238, 220, 130], "LightGoldenrod3"=>[205, 190, 112], "LightGoldenrod4"=>[139, 129, 76], "LightYellow1"=>[255, 255, 224], "LightYellow2"=>[238, 238, 209], "LightYellow3"=>[205, 205, 180], "LightYellow4"=>[139, 139, 122], "yellow1"=>[255, 255, 0], "yellow2"=>[238, 238, 0], "yellow3"=>[205, 205, 0], "yellow4"=>[139, 139, 0], "gold1"=>[255, 215, 0], "gold2"=>[238, 201, 0], "gold3"=>[205, 173, 0], "gold4"=>[139, 117, 0], "goldenrod1"=>[255, 193, 37], "goldenrod2"=>[238, 180, 34], "goldenrod3"=>[205, 155, 29], "goldenrod4"=>[139, 105, 20], "DarkGoldenrod1"=>[255, 185, 15], "DarkGoldenrod2"=>[238, 173, 14], "DarkGoldenrod3"=>[205, 149, 12], "DarkGoldenrod4"=>[139, 101, 8], "RosyBrown1"=>[255, 193, 193], "RosyBrown2"=>[238, 180, 180], "RosyBrown3"=>[205, 155, 155], "RosyBrown4"=>[139, 105, 105], "IndianRed1"=>[255, 106, 106], "IndianRed2"=>[238, 99, 99], "IndianRed3"=>[205, 85, 85], "IndianRed4"=>[139, 58, 58], "sienna1"=>[255, 130, 71], "sienna2"=>[238, 121, 66], "sienna3"=>[205, 104, 57], "sienna4"=>[139, 71, 38], "burlywood1"=>[255, 211, 155], "burlywood2"=>[238, 197, 145], "burlywood3"=>[205, 170, 125], "burlywood4"=>[139, 115, 85], "wheat1"=>[255, 231, 186], "wheat2"=>[238, 216, 174], "wheat3"=>[205, 186, 150], "wheat4"=>[139, 126, 102], "tan1"=>[255, 165, 79], "tan2"=>[238, 154, 73], "tan3"=>[205, 133, 63], "tan4"=>[139, 90, 43], "chocolate1"=>[255, 127, 36], "chocolate2"=>[238, 118, 33], "chocolate3"=>[205, 102, 29], "chocolate4"=>[139, 69, 19], "firebrick1"=>[255, 48, 48], "firebrick2"=>[238, 44, 44], "firebrick3"=>[205, 38, 38], "firebrick4"=>[139, 26, 26], "brown1"=>[255, 64, 64], "brown2"=>[238, 59, 59], "brown3"=>[205, 51, 51], "brown4"=>[139, 35, 35], "salmon1"=>[255, 140, 105], "salmon2"=>[238, 130, 98], "salmon3"=>[205, 112, 84], "salmon4"=>[139, 76, 57], "LightSalmon1"=>[255, 160, 122], "LightSalmon2"=>[238, 149, 114], "LightSalmon3"=>[205, 129, 98], "LightSalmon4"=>[139, 87, 66], "orange1"=>[255, 165, 0], "orange2"=>[238, 154, 0], "orange3"=>[205, 133, 0], "orange4"=>[139, 90, 0], "DarkOrange1"=>[255, 127, 0], "DarkOrange2"=>[238, 118, 0], "DarkOrange3"=>[205, 102, 0], "DarkOrange4"=>[139, 69, 0], "coral1"=>[255, 114, 86], "coral2"=>[238, 106, 80], "coral3"=>[205, 91, 69], "coral4"=>[139, 62, 47], "tomato1"=>[255, 99, 71], "tomato2"=>[238, 92, 66], "tomato3"=>[205, 79, 57], "tomato4"=>[139, 54, 38], "OrangeRed1"=>[255, 69, 0], "OrangeRed2"=>[238, 64, 0], "OrangeRed3"=>[205, 55, 0], "OrangeRed4"=>[139, 37, 0], "red1"=>[255, 0, 0], "red2"=>[238, 0, 0], "red3"=>[205, 0, 0], "red4"=>[139, 0, 0], "DebianRed"=>[215, 7, 81], "DeepPink1"=>[255, 20, 147], "DeepPink2"=>[238, 18, 137], "DeepPink3"=>[205, 16, 118], "DeepPink4"=>[139, 10, 80], "HotPink1"=>[255, 110, 180], "HotPink2"=>[238, 106, 167], "HotPink3"=>[205, 96, 144], "HotPink4"=>[139, 58, 98], "pink1"=>[255, 181, 197], "pink2"=>[238, 169, 184], "pink3"=>[205, 145, 158], "pink4"=>[139, 99, 108], "LightPink1"=>[255, 174, 185], "LightPink2"=>[238, 162, 173], "LightPink3"=>[205, 140, 149], "LightPink4"=>[139, 95, 101], "PaleVioletRed1"=>[255, 130, 171], "PaleVioletRed2"=>[238, 121, 159], "PaleVioletRed3"=>[205, 104, 137], "PaleVioletRed4"=>[139, 71, 93], "maroon1"=>[255, 52, 179], "maroon2"=>[238, 48, 167], "maroon3"=>[205, 41, 144], "maroon4"=>[139, 28, 98], "VioletRed1"=>[255, 62, 150], "VioletRed2"=>[238, 58, 140], "VioletRed3"=>[205, 50, 120], "VioletRed4"=>[139, 34, 82], "magenta1"=>[255, 0, 255], "magenta2"=>[238, 0, 238], "magenta3"=>[205, 0, 205], "magenta4"=>[139, 0, 139], "orchid1"=>[255, 131, 250], "orchid2"=>[238, 122, 233], "orchid3"=>[205, 105, 201], "orchid4"=>[139, 71, 137], "plum1"=>[255, 187, 255], "plum2"=>[238, 174, 238], "plum3"=>[205, 150, 205], "plum4"=>[139, 102, 139], "MediumOrchid1"=>[224, 102, 255], "MediumOrchid2"=>[209, 95, 238], "MediumOrchid3"=>[180, 82, 205], "MediumOrchid4"=>[122, 55, 139], "DarkOrchid1"=>[191, 62, 255], "DarkOrchid2"=>[178, 58, 238], "DarkOrchid3"=>[154, 50, 205], "DarkOrchid4"=>[104, 34, 139], "purple1"=>[155, 48, 255], "purple2"=>[145, 44, 238], "purple3"=>[125, 38, 205], "purple4"=>[85, 26, 139], "MediumPurple1"=>[171, 130, 255], "MediumPurple2"=>[159, 121, 238], "MediumPurple3"=>[137, 104, 205], "MediumPurple4"=>[93, 71, 139], "thistle1"=>[255, 225, 255], "thistle2"=>[238, 210, 238], "thistle3"=>[205, 181, 205], "thistle4"=>[139, 123, 139], "gray0"=>[0, 0, 0], "grey0"=>[0, 0, 0], "gray1"=>[3, 3, 3], "grey1"=>[3, 3, 3], "gray2"=>[5, 5, 5], "grey2"=>[5, 5, 5], "gray3"=>[8, 8, 8], "grey3"=>[8, 8, 8], "gray4"=>[10, 10, 10], "grey4"=>[10, 10, 10], "gray5"=>[13, 13, 13], "grey5"=>[13, 13, 13], "gray6"=>[15, 15, 15], "grey6"=>[15, 15, 15], "gray7"=>[18, 18, 18], "grey7"=>[18, 18, 18], "gray8"=>[20, 20, 20], "grey8"=>[20, 20, 20], "gray9"=>[23, 23, 23], "grey9"=>[23, 23, 23], "gray10"=>[26, 26, 26], "grey10"=>[26, 26, 26], "gray11"=>[28, 28, 28], "grey11"=>[28, 28, 28], "gray12"=>[31, 31, 31], "grey12"=>[31, 31, 31], "gray13"=>[33, 33, 33], "grey13"=>[33, 33, 33], "gray14"=>[36, 36, 36], "grey14"=>[36, 36, 36], "gray15"=>[38, 38, 38], "grey15"=>[38, 38, 38], "gray16"=>[41, 41, 41], "grey16"=>[41, 41, 41], "gray17"=>[43, 43, 43], "grey17"=>[43, 43, 43], "gray18"=>[46, 46, 46], "grey18"=>[46, 46, 46], "gray19"=>[48, 48, 48], "grey19"=>[48, 48, 48], "gray20"=>[51, 51, 51], "grey20"=>[51, 51, 51], "gray21"=>[54, 54, 54], "grey21"=>[54, 54, 54], "gray22"=>[56, 56, 56], "grey22"=>[56, 56, 56], "gray23"=>[59, 59, 59], "grey23"=>[59, 59, 59], "gray24"=>[61, 61, 61], "grey24"=>[61, 61, 61], "gray25"=>[64, 64, 64], "grey25"=>[64, 64, 64], "gray26"=>[66, 66, 66], "grey26"=>[66, 66, 66], "gray27"=>[69, 69, 69], "grey27"=>[69, 69, 69], "gray28"=>[71, 71, 71], "grey28"=>[71, 71, 71], "gray29"=>[74, 74, 74], "grey29"=>[74, 74, 74], "gray30"=>[77, 77, 77], "grey30"=>[77, 77, 77], "gray31"=>[79, 79, 79], "grey31"=>[79, 79, 79], "gray32"=>[82, 82, 82], "grey32"=>[82, 82, 82], "gray33"=>[84, 84, 84], "grey33"=>[84, 84, 84], "gray34"=>[87, 87, 87], "grey34"=>[87, 87, 87], "gray35"=>[89, 89, 89], "grey35"=>[89, 89, 89], "gray36"=>[92, 92, 92], "grey36"=>[92, 92, 92], "gray37"=>[94, 94, 94], "grey37"=>[94, 94, 94], "gray38"=>[97, 97, 97], "grey38"=>[97, 97, 97], "gray39"=>[99, 99, 99], "grey39"=>[99, 99, 99], "gray40"=>[102, 102, 102], "grey40"=>[102, 102, 102], "gray41"=>[105, 105, 105], "grey41"=>[105, 105, 105], "gray42"=>[107, 107, 107], "grey42"=>[107, 107, 107], "gray43"=>[110, 110, 110], "grey43"=>[110, 110, 110], "gray44"=>[112, 112, 112], "grey44"=>[112, 112, 112], "gray45"=>[115, 115, 115], "grey45"=>[115, 115, 115], "gray46"=>[117, 117, 117], "grey46"=>[117, 117, 117], "gray47"=>[120, 120, 120], "grey47"=>[120, 120, 120], "gray48"=>[122, 122, 122], "grey48"=>[122, 122, 122], "gray49"=>[125, 125, 125], "grey49"=>[125, 125, 125], "gray50"=>[127, 127, 127], "grey50"=>[127, 127, 127], "gray51"=>[130, 130, 130], "grey51"=>[130, 130, 130], "gray52"=>[133, 133, 133], "grey52"=>[133, 133, 133], "gray53"=>[135, 135, 135], "grey53"=>[135, 135, 135], "gray54"=>[138, 138, 138], "grey54"=>[138, 138, 138], "gray55"=>[140, 140, 140], "grey55"=>[140, 140, 140], "gray56"=>[143, 143, 143], "grey56"=>[143, 143, 143], "gray57"=>[145, 145, 145], "grey57"=>[145, 145, 145], "gray58"=>[148, 148, 148], "grey58"=>[148, 148, 148], "gray59"=>[150, 150, 150], "grey59"=>[150, 150, 150], "gray60"=>[153, 153, 153], "grey60"=>[153, 153, 153], "gray61"=>[156, 156, 156], "grey61"=>[156, 156, 156], "gray62"=>[158, 158, 158], "grey62"=>[158, 158, 158], "gray63"=>[161, 161, 161], "grey63"=>[161, 161, 161], "gray64"=>[163, 163, 163], "grey64"=>[163, 163, 163], "gray65"=>[166, 166, 166], "grey65"=>[166, 166, 166], "gray66"=>[168, 168, 168], "grey66"=>[168, 168, 168], "gray67"=>[171, 171, 171], "grey67"=>[171, 171, 171], "gray68"=>[173, 173, 173], "grey68"=>[173, 173, 173], "gray69"=>[176, 176, 176], "grey69"=>[176, 176, 176], "gray70"=>[179, 179, 179], "grey70"=>[179, 179, 179], "gray71"=>[181, 181, 181], "grey71"=>[181, 181, 181], "gray72"=>[184, 184, 184], "grey72"=>[184, 184, 184], "gray73"=>[186, 186, 186], "grey73"=>[186, 186, 186], "gray74"=>[189, 189, 189], "grey74"=>[189, 189, 189], "gray75"=>[191, 191, 191], "grey75"=>[191, 191, 191], "gray76"=>[194, 194, 194], "grey76"=>[194, 194, 194], "gray77"=>[196, 196, 196], "grey77"=>[196, 196, 196], "gray78"=>[199, 199, 199], "grey78"=>[199, 199, 199], "gray79"=>[201, 201, 201], "grey79"=>[201, 201, 201], "gray80"=>[204, 204, 204], "grey80"=>[204, 204, 204], "gray81"=>[207, 207, 207], "grey81"=>[207, 207, 207], "gray82"=>[209, 209, 209], "grey82"=>[209, 209, 209], "gray83"=>[212, 212, 212], "grey83"=>[212, 212, 212], "gray84"=>[214, 214, 214], "grey84"=>[214, 214, 214], "gray85"=>[217, 217, 217], "grey85"=>[217, 217, 217], "gray86"=>[219, 219, 219], "grey86"=>[219, 219, 219], "gray87"=>[222, 222, 222], "grey87"=>[222, 222, 222], "gray88"=>[224, 224, 224], "grey88"=>[224, 224, 224], "gray89"=>[227, 227, 227], "grey89"=>[227, 227, 227], "gray90"=>[229, 229, 229], "grey90"=>[229, 229, 229], "gray91"=>[232, 232, 232], "grey91"=>[232, 232, 232], "gray92"=>[235, 235, 235], "grey92"=>[235, 235, 235], "gray93"=>[237, 237, 237], "grey93"=>[237, 237, 237], "gray94"=>[240, 240, 240], "grey94"=>[240, 240, 240], "gray95"=>[242, 242, 242], "grey95"=>[242, 242, 242], "gray96"=>[245, 245, 245], "grey96"=>[245, 245, 245], "gray97"=>[247, 247, 247], "grey97"=>[247, 247, 247], "gray98"=>[250, 250, 250], "grey98"=>[250, 250, 250], "gray99"=>[252, 252, 252], "grey99"=>[252, 252, 252], "gray100"=>[255, 255, 255], "grey100"=>[255, 255, 255], "dark grey"=>[169, 169, 169], "DarkGrey"=>[169, 169, 169], "dark gray"=>[169, 169, 169], "DarkGray"=>[169, 169, 169], "dark blue"=>[0, 0, 139], "DarkBlue"=>[0, 0, 139], "dark cyan"=>[0, 139, 139], "DarkCyan"=>[0, 139, 139], "dark magenta"=>[139, 0, 139], "DarkMagenta"=>[139, 0, 139], "dark red"=>[139, 0, 0], "DarkRed"=>[139, 0, 0], "light green"=>[144, 238, 144], "LightGreen"=>[144, 238, 144]}
|
3
|
+
RGB_COLORS =
|
4
|
+
Marshal.load(
|
5
|
+
Gem.gunzip(
|
6
|
+
File.binread(
|
7
|
+
File.dirname(__FILE__) + '/../../data/rgb_colors.marshal.gz'
|
8
|
+
)
|
9
|
+
)
|
10
|
+
)
|
6
11
|
end
|
7
|
-
|
8
|
-
# J-_-L
|
data/lib/paint/util.rb
CHANGED
@@ -1,38 +1,14 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
|
3
1
|
module Paint
|
4
|
-
#
|
2
|
+
# Standalone helpers which add functionality you sometimes need when working with terminal colors
|
5
3
|
class << self
|
6
4
|
# Removes any color and effect strings
|
7
5
|
def unpaint(string)
|
8
6
|
string.gsub(/\e\[(?:[0-9];?)+m/, '')
|
9
7
|
end
|
10
8
|
|
11
|
-
#
|
12
|
-
def
|
13
|
-
(
|
14
|
-
print Paint[' ', 48, 5, color] # print empty bg color field
|
15
|
-
}
|
16
|
-
puts
|
17
|
-
end
|
18
|
-
|
19
|
-
# Updates color names
|
20
|
-
def update_rgb_colors(path = '/etc/X11/rgb.txt')
|
21
|
-
if File.file?(path)
|
22
|
-
Paint::RGB_COLORS.clear
|
23
|
-
|
24
|
-
File.open(path, 'r') do |file|
|
25
|
-
file.each_line{ |line|
|
26
|
-
line.chomp =~ /(\d+)\s+(\d+)\s+(\d+)\s+(.*)$/
|
27
|
-
Paint::RGB_COLORS[$4] = [$1.to_i, $2.to_i, $3.to_i] if $4
|
28
|
-
}
|
29
|
-
end
|
30
|
-
else
|
31
|
-
raise ArgumentError, "Not a valid file: #{path}"
|
32
|
-
end
|
9
|
+
# Creates a random ANSI color
|
10
|
+
def random(background = false)
|
11
|
+
(background ? 40 : 30) + rand(8)
|
33
12
|
end
|
34
|
-
|
35
13
|
end
|
36
14
|
end
|
37
|
-
|
38
|
-
# J-_-L
|
data/lib/paint/version.rb
CHANGED
data/paint.gemspec
CHANGED
@@ -9,7 +9,7 @@ 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: No string extensions / 256 color support / effect support. Usage: Paint['string', :red, :bright]"
|
12
|
+
s.description = "Terminal painter: No string extensions / RGB and 256 color support / effect support. Usage: Paint['string', :red, :bright]"
|
13
13
|
s.license = 'MIT'
|
14
14
|
|
15
15
|
s.files = %w[
|
@@ -20,13 +20,14 @@ Gem::Specification.new do |s|
|
|
20
20
|
lib/paint.rb
|
21
21
|
lib/paint/pa.rb
|
22
22
|
lib/paint/rgb_colors.rb
|
23
|
-
lib/paint/
|
23
|
+
lib/paint/constants.rb
|
24
24
|
lib/paint/util.rb
|
25
25
|
lib/paint/version.rb
|
26
|
+
data/rgb_colors.marshal.gz
|
26
27
|
]
|
27
28
|
s.extra_rdoc_files = %w[
|
28
|
-
README.
|
29
|
-
CHANGELOG.
|
29
|
+
README.md
|
30
|
+
CHANGELOG.md
|
30
31
|
MIT-LICENSE.txt
|
31
32
|
]
|
32
33
|
|
@@ -34,10 +35,10 @@ Gem::Specification.new do |s|
|
|
34
35
|
s.requirements = ['Windows: ansicon (https://github.com/adoxa/ansicon) or ConEmu (http://code.google.com/p/conemu-maximus5)']
|
35
36
|
s.add_development_dependency 'rspec', '~> 3.2'
|
36
37
|
s.add_development_dependency 'rake', '~> 10.4'
|
37
|
-
s.add_development_dependency 'benchmark-ips', '~> 2.
|
38
|
-
s.add_development_dependency 'rainbow', '~> 2.
|
39
|
-
s.add_development_dependency 'term-ansicolor', '~> 1.
|
38
|
+
s.add_development_dependency 'benchmark-ips', '~> 2.7'
|
39
|
+
s.add_development_dependency 'rainbow', '~> 2.1'
|
40
|
+
s.add_development_dependency 'term-ansicolor', '~> 1.4'
|
40
41
|
s.add_development_dependency 'ansi', '~> 1.5'
|
41
|
-
s.add_development_dependency 'hansi', '~> 0.
|
42
|
-
s.add_development_dependency 'pastel', '~> 0.
|
42
|
+
s.add_development_dependency 'hansi', '~> 0.2'
|
43
|
+
s.add_development_dependency 'pastel', '~> 0.6'
|
43
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.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: 2016-
|
11
|
+
date: 2016-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -44,42 +44,42 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
47
|
+
version: '2.7'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
54
|
+
version: '2.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rainbow
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2.
|
61
|
+
version: '2.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2.
|
68
|
+
version: '2.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: term-ansicolor
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
75
|
+
version: '1.4'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
82
|
+
version: '1.4'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: ansi
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,48 +100,49 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
103
|
+
version: '0.2'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
110
|
+
version: '0.2'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: pastel
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0.
|
117
|
+
version: '0.6'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0.
|
125
|
-
description: 'Terminal painter: No string extensions / 256 color support /
|
126
|
-
support. Usage: Paint[''string'', :red, :bright]'
|
124
|
+
version: '0.6'
|
125
|
+
description: 'Terminal painter: No string extensions / RGB and 256 color support /
|
126
|
+
effect support. Usage: Paint[''string'', :red, :bright]'
|
127
127
|
email: mail@janlelis.de
|
128
128
|
executables: []
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files:
|
131
|
-
- README.
|
132
|
-
- CHANGELOG.
|
131
|
+
- README.md
|
132
|
+
- CHANGELOG.md
|
133
133
|
- MIT-LICENSE.txt
|
134
134
|
files:
|
135
135
|
- ".rspec"
|
136
136
|
- ".travis.yml"
|
137
|
-
- CHANGELOG.
|
137
|
+
- CHANGELOG.md
|
138
138
|
- MIT-LICENSE.txt
|
139
|
-
- README.
|
139
|
+
- README.md
|
140
140
|
- Rakefile
|
141
|
+
- data/rgb_colors.marshal.gz
|
141
142
|
- lib/paint.rb
|
143
|
+
- lib/paint/constants.rb
|
142
144
|
- lib/paint/pa.rb
|
143
145
|
- lib/paint/rgb_colors.rb
|
144
|
-
- lib/paint/rgb_colors_ansi.rb
|
145
146
|
- lib/paint/util.rb
|
146
147
|
- lib/paint/version.rb
|
147
148
|
- paint.gemspec
|
@@ -166,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
167
|
requirements:
|
167
168
|
- 'Windows: ansicon (https://github.com/adoxa/ansicon) or ConEmu (http://code.google.com/p/conemu-maximus5)'
|
168
169
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.5.
|
170
|
+
rubygems_version: 2.5.2
|
170
171
|
signing_key:
|
171
172
|
specification_version: 4
|
172
173
|
summary: Terminal painter!
|
data/CHANGELOG.rdoc
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
=== 1.0.1
|
2
|
-
* Fix case of string arguments getting mutated (see gh#14)
|
3
|
-
|
4
|
-
=== 1.0.0
|
5
|
-
* Improved performance
|
6
|
-
* Option for :random colors removed (see readme)
|
7
|
-
* Seperate Paint::SHORTCUTS into extra gem
|
8
|
-
* Drop support for Ruby 1 (inoffically still support 1.9.3)
|
9
|
-
|
10
|
-
=== 0.9.0
|
11
|
-
* Don't colorize strings via shortcuts when Paint.mode == 0
|
12
|
-
* Freeze bundled ascii color data
|
13
|
-
|
14
|
-
=== 0.8.7
|
15
|
-
* Fix caching bug for random ansi color
|
16
|
-
|
17
|
-
=== 0.8.6
|
18
|
-
* Add missing require 'rbconfig' and travis test everything
|
19
|
-
|
20
|
-
=== 0.8.5
|
21
|
-
* Support 256 color on windows' ConEmu
|
22
|
-
|
23
|
-
=== 0.8.4
|
24
|
-
* Fix post-install message unicode
|
25
|
-
|
26
|
-
=== 0.8.3
|
27
|
-
* Paint.[] also accepts uppercased hex strings (gh#2)
|
28
|
-
* Performance tweaks (thanks to murphy) (gh#4, #5)
|
29
|
-
* API change: deactivate colorizing with Paint.mode = 0
|
30
|
-
|
31
|
-
=== 0.8.2
|
32
|
-
* Paint.[] with only a single string argument does not colorize the string anymore, but returns the plain string
|
33
|
-
* New pseudo color :random - returns a random ansi color
|
34
|
-
|
35
|
-
=== 0.8.1
|
36
|
-
* Improve rgb function with better gray scale values
|
37
|
-
* Add Paint.mode:
|
38
|
-
* Set to 0 to deactivate colorizing
|
39
|
-
* Set to 16 or 8 and all color generation methods will generate simple ansi colors
|
40
|
-
* Set to 256 for 256 color support
|
41
|
-
* Tries to automatically detect your terminal's features
|
42
|
-
* Minor changes
|
43
|
-
|
44
|
-
=== 0.8.0
|
45
|
-
* Initial release
|
data/README.rdoc
DELETED
@@ -1,132 +0,0 @@
|
|
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
|
-
|
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
|
-
|
5
|
-
== Features
|
6
|
-
* No string extensions (suitable for library development)
|
7
|
-
* Simple API
|
8
|
-
* Faster than other terminal color gems ({as of October 2015}[https://gist.github.com/janlelis/91413b9295c81ee873dc])
|
9
|
-
* Supports setting 256 colors (for capable terminals)
|
10
|
-
* Supports setting any terminal effects
|
11
|
-
* Fall-back modes for non-256-color terminals (<tt>Paint.mode</tt>), supported modes:
|
12
|
-
* 256 colors
|
13
|
-
* 16 colors (only ansi colors, combined with bright effect)
|
14
|
-
* 8 colors (only ansi colors)
|
15
|
-
* 0 colors (deactivate)
|
16
|
-
|
17
|
-
== Setup
|
18
|
-
Add to Gemfile:
|
19
|
-
|
20
|
-
gem 'paint'
|
21
|
-
|
22
|
-
and run `bundle install`
|
23
|
-
|
24
|
-
In Ruby do:
|
25
|
-
|
26
|
-
require 'paint'
|
27
|
-
|
28
|
-
== Usage
|
29
|
-
The only method you need to know is: <tt>Paint.[]</tt>
|
30
|
-
|
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:
|
32
|
-
|
33
|
-
Paint['Ruby', :red] # sets ansi color red
|
34
|
-
Paint['Ruby', :red, :bright] # also applies bright/bold effect
|
35
|
-
Paint['Ruby', :bright, :red] # does the same as above
|
36
|
-
Paint['Ruby', :red, :bright, :underline] # effects can often be combined
|
37
|
-
Paint['Ruby', :red, :blue] # the second color you define is for background
|
38
|
-
Paint['Ruby', nil, :blue] # pass a nil before a color to ignore foreground and only set background color
|
39
|
-
Paint['Ruby', [100, 255, 5]] # you can define rgb colors that map to one of 256 colors. Only supported on 256-color terminals, of course
|
40
|
-
Paint['Ruby', "gold", "snow"] # Paint supports rgb.txt color names, note that the arguments are strings (:yellow != "yellow")!
|
41
|
-
Paint['Ruby', "#123456"] # html like definitions are possible.
|
42
|
-
Paint['Ruby', "fff"] # another html hex definition
|
43
|
-
Paint['Ruby', :inverse] # swaps fore- and background
|
44
|
-
Paint['Ruby', :italic, :encircle, :rapid_blink, :overline] # probably not supported effects
|
45
|
-
Paint['Ruby'] # don't pass any argument and the string will not be changed
|
46
|
-
|
47
|
-
When you pass multiple colors, the first one is taken as foreground color and the second one defines the background color, every other will be ignored. To only change the background color, you have to pass a <tt>nil</tt> first. Effects can be passed in any order.
|
48
|
-
|
49
|
-
You can find more examples in the specs.
|
50
|
-
|
51
|
-
== Windows Support
|
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/].
|
53
|
-
|
54
|
-
== More details about terminal colors and effects
|
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:
|
56
|
-
|
57
|
-
:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, (:default)
|
58
|
-
|
59
|
-
When combined with the <tt>:bright</tt> (= <tt>:bold</tt>) effect, the color in the terminal emulator often differs a little bit.
|
60
|
-
|
61
|
-
Through special sequences it's also possible to set 256-colors, instead of 8, which is also supported by many - but not all - terminals. Paint automatically translates given rgb colors to a suitable color of the 256 available colors.
|
62
|
-
|
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.
|
64
|
-
|
65
|
-
=== Effects
|
66
|
-
Also see {en.wikipedia.org/wiki/ANSI_escape_code}[http://en.wikipedia.org/wiki/ANSI_escape_code]:
|
67
|
-
|
68
|
-
==== Often supported
|
69
|
-
|
70
|
-
0) :reset, :nothing
|
71
|
-
1) :bright, :bold
|
72
|
-
4) :underline
|
73
|
-
7) :inverse, :negative
|
74
|
-
8) :conceal, :hide
|
75
|
-
22) :clean
|
76
|
-
24) :underline_off
|
77
|
-
26) :inverse_off, :positive
|
78
|
-
27) :conceal_off, :show, :reveal
|
79
|
-
|
80
|
-
==== Not widely supported
|
81
|
-
|
82
|
-
2) :faint
|
83
|
-
3) :italic
|
84
|
-
5) :blink, :slow_blink
|
85
|
-
6) :rapid_blink
|
86
|
-
9) :crossed, :crossed_out
|
87
|
-
10) :default_font, :font0
|
88
|
-
11-19) :font1, :font2, :font3, :font4, :font5, :font6, :font7, :font8, :font9
|
89
|
-
20) :fraktur
|
90
|
-
21) :bright_off, :bold_off, :double_underline
|
91
|
-
23) :italic_off, :fraktur_off
|
92
|
-
25) :blink_off
|
93
|
-
29) :crossed_off, :crossed_out_off
|
94
|
-
51) :frame
|
95
|
-
52) :encircle
|
96
|
-
53) :overline
|
97
|
-
54) :frame_off, :encircle_off
|
98
|
-
55) :overline_off
|
99
|
-
|
100
|
-
== Paint.mode
|
101
|
-
You can choose between four ways to use <tt>Paint.[]</tt> by setting <tt>Paint.mode</tt> to one of the following:
|
102
|
-
* 256: full support
|
103
|
-
* 16: don't use 256 colors, but the ansi eight ones (combined with bright effect)
|
104
|
-
* 8: don't use 256 colors, but the ansi eight ones
|
105
|
-
* 0: don't colorize at all
|
106
|
-
|
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.
|
108
|
-
|
109
|
-
== Random ANSI Colors
|
110
|
-
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:
|
111
|
-
|
112
|
-
Paint['Ruby', Paint.random] # get one of eight random ansi foreground colors
|
113
|
-
Paint['Ruby', Paint.random(true)] # get one of eight random ansi background colors
|
114
|
-
|
115
|
-
== Utilities
|
116
|
-
There are some supporting methods available. You can get a <tt>p</tt> like alternative for calling <tt>puts Paint.[]</tt>:
|
117
|
-
|
118
|
-
require 'paint/pa'
|
119
|
-
pa "Ruby", :red, :underline # same as puts Paint["Ruby", :red, :underline]
|
120
|
-
|
121
|
-
Another helper method is <tt>Paint.unpaint</tt>, which removes any ansi colors:
|
122
|
-
|
123
|
-
Paint.unpaint( Paint['Ruby', :red, :bright] ).should == 'Ruby'
|
124
|
-
|
125
|
-
== Advanced Usage: Shortcuts
|
126
|
-
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.
|
127
|
-
|
128
|
-
== J-_-L
|
129
|
-
|
130
|
-
Copyright (c) 2011-2016 Jan Lelis <http://janlelis.com>, released under the MIT license.
|
131
|
-
|
132
|
-
Mainly influenced by rainbow[https://github.com/sickill/rainbow] and {term-ansicolor}[https://github.com/flori/term-ansicolor]. Also see the list of contributors[https://github.com/janlelis/paint/contributors]
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Paint
|
2
|
-
# A list of color names for standard ansi colors, needed for 16/8 color fallback mode
|
3
|
-
# See http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
4
|
-
RGB_COLORS_ANSI = {
|
5
|
-
:black => [0,0,0],
|
6
|
-
:red => [205,0,0],
|
7
|
-
:green => [0,205,0],
|
8
|
-
:yellow => [205,205,0],
|
9
|
-
:blue => [0,0,238],
|
10
|
-
:magenta => [205,0,205],
|
11
|
-
:cyan => [0,205,205],
|
12
|
-
:white => [229,229,229],
|
13
|
-
}.each { |k, v| v.freeze }.freeze
|
14
|
-
|
15
|
-
# A list of color names for standard bright ansi colors, needed for 16 color fallback mode
|
16
|
-
# See http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
17
|
-
RGB_COLORS_ANSI_BRIGHT = {
|
18
|
-
:black => [127,127,127],
|
19
|
-
:red => [255,0,0],
|
20
|
-
:green => [0,255,0],
|
21
|
-
:yellow => [255,255,0],
|
22
|
-
:blue => [92,92,255],
|
23
|
-
:magenta => [255,0,255],
|
24
|
-
:cyan => [0,255,255],
|
25
|
-
:white => [255,255,255],
|
26
|
-
}.each { |k, v| v.freeze }.freeze
|
27
|
-
end
|