paint-shortcuts 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d57c0fd9ddd3a842fc19ac0ac3d942e70c518c60
4
- data.tar.gz: ad2e60a6053be8eee6f7b2f08de0653817b35b32
3
+ metadata.gz: b53c09f4c5e55c813cc33d28fcc35f056a0ff383
4
+ data.tar.gz: 35d69459f006be32abfff086afb5977b56b7ebb7
5
5
  SHA512:
6
- metadata.gz: cd9e902ae80a6968b72caa163a8ae91957342485be45d2f90f9a8c05ca28c72cacd2c204225808a24c228a914e56460475450bb7f7650f007eebb69f86809159
7
- data.tar.gz: daa6eaeb4829e3b0de16535e06056c1dd7aef02401af9aa1f3ff5081dda03d449c6f0e26b0b5a3802d090ef7201f44831f5d4da01ca8fae2619f076ecdfb2509
6
+ metadata.gz: 87c8a5ba0ea8aa71b6eb294e50f514c6bce69b190275d4b426f2b00718c6930886a669bf0469364ced15edc0579ff4eebbe9905140b1bde4a30963c88b8ab589
7
+ data.tar.gz: a58355d1a5c981af51eef33b179e45b3ac84315d39c4aa1f1b46db3eaeb460a55a3b8135465ab48ebce832042e8281cce6af2a3bf0b20eaa978b15be5084ef61
@@ -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
+
@@ -1,6 +1,6 @@
1
1
  The MIT LICENSE
2
2
 
3
- Copyright (c) 2011-2015 Jan Lelis
3
+ Copyright (c) 2011-2016 Jan Lelis
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -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)!
@@ -0,0 +1,64 @@
1
+ # Paint::SHORTCUTS [<img src="https://badge.fury.io/rb/paint-shortcuts.svg" />](http://badge.fury.io/rb/paint-shortcuts)
2
+
3
+ This is an optional extension gem for [Paint](https://github.com/janlelis/paint)
4
+
5
+ ## Setup
6
+
7
+ Add to `Gemfile`:
8
+
9
+ gem 'paint-shortcuts'
10
+
11
+ and run `bundle install`.
12
+
13
+ In Ruby do:
14
+
15
+ require 'paint/shortcuts'
16
+
17
+ ## Description
18
+
19
+ You can create color shortcuts for your gems and scripts! Please note: You don't have to use this feature (and only stick to `Paint.[]` instead)
20
+
21
+ All you need to do is to setup a hash of symbol keys and escaped color sequences at:
22
+ `Paint::SHORTCUTS[:your_namespace]`:
23
+
24
+ ```ruby
25
+ Paint::SHORTCUTS[:example] = {
26
+ :white => Paint.color(:black),
27
+ :red => Paint.color(:red, :bright),
28
+ :title => Paint.color(:underline),
29
+ }
30
+ ```
31
+
32
+ The methods become "rubymagically" available in a `Paint` child model:
33
+
34
+ ```ruby
35
+ Paint::Example.red 'Ruby' # => "\e[31;1mRuby\e[0m"
36
+ Paint::Example.white # => "\e[37m"
37
+ ```
38
+
39
+ As you can see, the helper methods look useful and can take either one (wrap string) or none (only color) arguments. You can also include them:
40
+
41
+ ```ruby
42
+ include Paint::Example
43
+ red # => "\e[31;1m"
44
+ white 'Ruby' # => "\e[30m"
45
+ ```
46
+
47
+ All shortcuts, defined in your shortcut namespace at this time, are now (privately) available in your current namespace (without relying a `method_missing` implementation).
48
+
49
+ Furthermore, there are variations of this approach. You get a different behaviour, when you include the `String` sub-module.
50
+
51
+ ```ruby
52
+ include Paint::Example::String
53
+ "Ruby".title # => "\e[4mRuby\e[0m"
54
+ 5.red # => "\e[31;1m5\e[0m"
55
+ ```
56
+
57
+ In this case, `self` will be converted to a string and wrapped with the specific color code. Note, that the helper methods don't take any arguments when using this style of inclusion.
58
+
59
+ The third way allows you to get a single color helper method to avoid cluttering namespaces:
60
+
61
+ ```ruby
62
+ include Paint::Example::Prefix::ExampleName
63
+ "Ruby".example_name(:red) # => "\e[31;1mRuby\e[0m"
64
+ ```
@@ -1,3 +1,3 @@
1
1
  module Paint
2
- SHORTCUTS_VERSION = '1.0.0'
2
+ SHORTCUTS_VERSION = '2.0.0'.freeze
3
3
  end
@@ -17,13 +17,12 @@ Gem::Specification.new do |s|
17
17
  lib/paint/shortcuts_version.rb
18
18
  ]
19
19
  s.extra_rdoc_files = %w[
20
- README.rdoc
21
- SHORTCUTS.rdoc
22
- CHANGELOG.rdoc
20
+ README.md
21
+ SHORTCUTS.md
22
+ CHANGELOG.md
23
23
  MIT-LICENSE.txt
24
24
  ]
25
25
 
26
26
  s.required_ruby_version = '>= 1.9.3'
27
- s.add_dependency 'paint', '~> 1.0'
28
- s.add_development_dependency 'rspec', '~> 3.2'
27
+ s.add_dependency 'paint', '>= 1.0', '< 3.0'
29
28
  end
metadata CHANGED
@@ -1,57 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paint-shortcuts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
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: 2015-03-22 00:00:00.000000000 Z
11
+ date: 2016-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paint
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.2'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
30
+ - - "<"
39
31
  - !ruby/object:Gem::Version
40
- version: '3.2'
32
+ version: '3.0'
41
33
  description: Extends the paint gem to support custom color shortcuts.
42
34
  email: mail@janlelis.de
43
35
  executables: []
44
36
  extensions: []
45
37
  extra_rdoc_files:
46
- - README.rdoc
47
- - SHORTCUTS.rdoc
48
- - CHANGELOG.rdoc
38
+ - README.md
39
+ - SHORTCUTS.md
40
+ - CHANGELOG.md
49
41
  - MIT-LICENSE.txt
50
42
  files:
51
- - CHANGELOG.rdoc
43
+ - CHANGELOG.md
52
44
  - MIT-LICENSE.txt
53
- - README.rdoc
54
- - SHORTCUTS.rdoc
45
+ - README.md
46
+ - SHORTCUTS.md
55
47
  - lib/paint/shortcuts.rb
56
48
  - lib/paint/shortcuts_version.rb
57
49
  - paint-shortcuts.gemspec
@@ -75,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
67
  version: '0'
76
68
  requirements: []
77
69
  rubyforge_project:
78
- rubygems_version: 2.4.6
70
+ rubygems_version: 2.5.2
79
71
  signing_key:
80
72
  specification_version: 4
81
73
  summary: Terminal painter! Shortcut extension.
@@ -1,42 +0,0 @@
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
-
7
- === 0.9.0
8
- * Don't colorize strings via shortcuts when Paint.mode == 0
9
- * Freeze bundled ascii color data
10
-
11
- === 0.8.7
12
- * Fix caching bug for random ansi color
13
-
14
- === 0.8.6
15
- * Add missing require 'rbconfig' and travis test everything
16
-
17
- === 0.8.5
18
- * Support 256 color on windows' ConEmu
19
-
20
- === 0.8.4
21
- * Fix post-install message unicode
22
-
23
- === 0.8.3
24
- * Paint.[] also accepts uppercased hex strings (gh#2)
25
- * Performance tweaks (thanks to murphy) (gh#4, #5)
26
- * API change: deactivate colorizing with Paint.mode = 0
27
-
28
- === 0.8.2
29
- * Paint.[] with only a single string argument does not colorize the string anymore, but returns the plain string
30
- * New pseudo color :random - returns a random ansi color
31
-
32
- === 0.8.1
33
- * Improve rgb function with better gray scale values
34
- * Add Paint.mode:
35
- * Set to 0 to deactivate colorizing
36
- * Set to 16 or 8 and all color generation methods will generate simple ansi colors
37
- * Set to 256 for 256 color support
38
- * Tries to automatically detect your terminal's features
39
- * Minor changes
40
-
41
- === 0.8.0
42
- * Initial release
@@ -1,137 +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
- * Supports setting 256 colors (for capable terminals)
8
- * Supports setting any effects (although most terminals won't support it)
9
- * Simple to use
10
- * Faster than most similar gems due to caching
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 to get started 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
-
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:
112
-
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
115
-
116
- == Utilities
117
- There are some supporting methods available. You can get a <tt>p</tt> like alternative for calling <tt>puts Paint.[]</tt>:
118
-
119
- require 'paint/pa'
120
- pa "Ruby", :red, :underline # same as puts Paint["Ruby", :red, :underline]
121
-
122
- Another helper method is <tt>Paint.unpaint</tt>, which removes any ansi colors:
123
-
124
- Paint.unpaint( Paint['Ruby', :red, :bright] ).should == 'Ruby'
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
-
129
- == J-_-L
130
-
131
- Copyright (c) 2011-2015 Jan Lelis <http://janlelis.com>, released under the MIT license.
132
-
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]:
134
- * {CyberShadow}[https://github.com/CyberShadow]
135
- * {korun}[https://github.com/korun]
136
- * {mhaylock}[https://github.com/mhaylock]
137
- * {korny}[https://github.com/rubychan]
@@ -1,51 +0,0 @@
1
- = Paint::SHORTCUTS
2
-
3
- == Setup
4
- Add to Gemfile:
5
-
6
- gem 'paint-shortcuts'
7
-
8
- and run `bundle install`
9
-
10
- In Ruby do:
11
-
12
- require 'paint/shortcuts'
13
-
14
- == Description
15
- 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) ;)
16
-
17
- 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:
18
-
19
- Paint::SHORTCUTS[:example] = {
20
- :white => Paint.color(:black),
21
- :red => Paint.color(:red, :bright),
22
- :title => Paint.color(:underline),
23
- }
24
-
25
- The methods become "rubymagically" available in a <tt>Paint</tt> child model:
26
-
27
- Paint::Example.red 'Ruby' # => "\e[31;1mRuby\e[0m"
28
- Paint::Example.white # => "\e[37m"
29
-
30
- 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.
31
-
32
- Fortunately, you can include them:
33
-
34
- include Paint::Example
35
- red # => "\e[31;1m"
36
- white 'Ruby' # => "\e[30m"
37
-
38
- All shortcuts, defined in your shortcut namespace at this time, are now (privately) available in your current namespace (without using a method_missing implementation).
39
-
40
- Furthermore, there are two variations of this approach:
41
-
42
- include Paint::Example::String
43
- "Ruby".title # => "\e[4mRuby\e[0m"
44
- 5.red # => "\e[31;1m5\e[0m"
45
-
46
- 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.
47
-
48
- The third way allows you to get a single color helper method to avoid cluttering namespaces:
49
-
50
- include Paint::Example::Prefix::ExampleName
51
- "Ruby".example_name(:red) # => "\e[31;1mRuby\e[0m"