pax_global_header 0000666 0000000 0000000 00000000064 13624005611 0014510 g ustar 00root root 0000000 0000000 52 comment=20f3b6811750d1696abcc6738ca5894c1cb23f85
paint-2.2.0/ 0000775 0000000 0000000 00000000000 13624005611 0012624 5 ustar 00root root 0000000 0000000 paint-2.2.0/.editorconfig 0000664 0000000 0000000 00000000247 13624005611 0015304 0 ustar 00root root 0000000 0000000 root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{md,rdoc,txt}]
indent_size = 4
paint-2.2.0/.gitignore 0000664 0000000 0000000 00000000073 13624005611 0014614 0 ustar 00root root 0000000 0000000 *.rbc
Rakefile.compiled.rbc
*.swp
*~
pkg
.rbx
Gemfile.lock
paint-2.2.0/.rspec 0000664 0000000 0000000 00000000040 13624005611 0013733 0 ustar 00root root 0000000 0000000 --colour
--format documentation
paint-2.2.0/.travis.yml 0000664 0000000 0000000 00000000445 13624005611 0014740 0 ustar 00root root 0000000 0000000 sudo: false
language: ruby
rvm:
- 2.7
- 2.6
- 2.5
- 2.4
- 2.3
- 2.2
- 2.1
- 2.0
- 1.9.3
- ruby-head
- jruby-head
- jruby-9.2.9.0
- truffleruby
matrix:
allow_failures:
- rvm: jruby-head
- rvm: 2.3
- rvm: 2.2
- rvm: 2.1
- rvm: 2.0
- rvm: 1.9.3
- rvm: truffleruby
paint-2.2.0/CHANGELOG.md 0000664 0000000 0000000 00000004415 13624005611 0014441 0 ustar 00root root 0000000 0000000 # CHANGELOG
### 2.2.0
* Support NO_COLOR environment variable, implements #26 (see no-color.org)
### 2.1.1
* Blacklist True Color support for urxvt, fixes #25
### 2.1.0
* Set True Color as default mode on more terminals, patch by @smoochbot
### 2.0.3
* Add `gray` alias for `white` color, patch by @AlexWayfer
### 2.0.2
* Remove `gunzip` deprecation warning
### 2.0.1
* Fix nested substitutions, patch by @mildmojo
### 2.0.0
#### Major Changes
* New default color mode `0xFFFFFF`: 24bit - true color. If this breaks your code, add `Paint.mode = 256` to the beginning of your code
* New `Paint%[]` API: Substitution mechanism for nested color strings
#### Minor Changes
* Smaller gem size (compress RGB color name data)
* Remove `Paint.update_rgb_colors` and `Paint.rainbow`
* Internal method `.hex` renamed to `.rgb_hex` and does not take "#" prefixed strings anymore
* Minor refactorings and documentation updates
### 1.0.1
* Fix case of string arguments getting mutated (see gh#14)
### 1.0.0
* Improved performance
* Option for :random colors removed (see readme)
* Separate Paint::SHORTCUTS into extra gem
* Drop support for Ruby 1 (inoffically still support 1.9.3)
### 0.9.0
* Don't colorize strings via shortcuts when Paint.mode == 0
* Freeze bundled ascii color data
### 0.8.7
* Fix caching bug for random ansi color
### 0.8.6
* Add missing require 'rbconfig' and travis test everything
### 0.8.5
* Support 256 color on windows' ConEmu
### 0.8.4
* Fix post-install message unicode
### 0.8.3
* Paint.[] also accepts uppercased hex strings (gh#2)
* Performance tweaks (thanks to murphy) (gh#4, #5)
* API change: deactivate colorizing with Paint.mode = 0
### 0.8.2
* Paint.[] with only a single string argument does not colorize the string
anymore, but returns the plain string
* New pseudo color :random - returns a random ansi color
### 0.8.1
* Improve rgb function with better gray scale values
* Add Paint.mode:
* Set to 0 to deactivate colorizing
* Set to 16 or 8 and all color generation methods will generate simple
ansi colors
* Set to 256 for 256 color support
* Tries to automatically detect your terminal's features
* Minor changes
### 0.8.0
* Initial release
paint-2.2.0/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000006236 13624005611 0015432 0 ustar 00root root 0000000 0000000 # Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at conduct@janlelis.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: https://contributor-covenant.org
[version]: https://contributor-covenant.org/version/1/4/
paint-2.2.0/Gemfile 0000664 0000000 0000000 00000000125 13624005611 0014115 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org'
gemspec name: 'paint'
gemspec name: 'paint-shortcuts'
paint-2.2.0/MIT-LICENSE.txt 0000664 0000000 0000000 00000002063 13624005611 0015077 0 ustar 00root root 0000000 0000000 The MIT LICENSE
Copyright (c) 2011-2020 Jan Lelis
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
paint-2.2.0/README.md 0000664 0000000 0000000 00000020241 13624005611 0014102 0 ustar 00root root 0000000 0000000 # Ruby Paint [
](https://badge.fury.io/rb/paint) [
](https://travis-ci.org/janlelis/paint)
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.
## Features
* No string extensions (suitable for library development)
* Simple API
* Faster than other terminal color gems ([as of January 2020](https://gist.github.com/janlelis/91413b9295c81ee873dc))
* Supports *true color* or 256 colors (for capable terminals)
* Allows you to set any terminal effects
* `Paint.mode`: Fall-back modes for terminals with less colors, supported modes:
* 0xFFFFFF (= 16777215) colors (*true color*)
* 256 colors (palette)
* 16 colors (only ANSI colors, combined with bright effect)
* 8 colors (only ANSI colors)
* 0 colors (no colors / deactivate)
## Paint 2.0 | True Color Support
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:
- Manually set `Paint.mode = 256` at the beginning of your code
- Please [open a new issue](https://github.com/janlelis/paint/issues/new) so we can figure out how to blacklist the terminal used
## Supported Rubies
* **2.7**, **2.6**, **2.5**, **2.4**
Unsupported, but might still work:
* **2.3**, **2.2**, **2.1**, **2.0**, **1.9**
## Setup
Add to `Gemfile`:
```ruby
gem 'paint'
```
and run `bundle install`.
In Ruby do:
```ruby
require 'paint'
```
## Usage
The only method you need is: `Paint.[]`
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:
```ruby
Paint['Ruby', :red] # Sets ANSI color red
Paint['Ruby', :red, :bright] # Also applies bright/bold effect
Paint['Ruby', :bright, :red] # Does the same as above
Paint['Ruby', :red, :bright, :underline] # Effects can often be combined
Paint['Ruby', :red, :blue] # The second color you define is for background
Paint['Ruby', nil, :blue] # Pass a nil before a color to ignore foreground and only set background color
Paint['Ruby', [100, 255, 5]] # You can define RGB colors. Depending on your terminal, this will create
# a "true color" or map to 256/16/8 colors.
Paint['Ruby', "gold", "snow"] # Paint supports rgb.txt color names, note that the arguments are strings
# (:yellow != "yellow")!
Paint['Ruby', "#123456"] # HTML like definitions are possible
Paint['Ruby', "fff"] # Another HTML hex definition
Paint['Ruby', :inverse] # Swaps fore- and background
Paint['Ruby', :italic, :encircle, :rapid_blink, :overline] # Probably not supported effects
Paint['Ruby'] # Don't pass any argument and the string will not be changed
```
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.
[You can find more examples in the specs.](https://github.com/janlelis/paint/blob/master/spec/paint_spec.rb)
[List of rgb.txt colors.](https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart)
## Windows Support
For ANSI support in Windows OS, you can use [ansicon](https://github.com/adoxa/ansicon) or [ConEmu](https://conemu.github.io/) or WSL(https://docs.microsoft.com/en-us/windows/wsl/install-win10).
## `Paint.mode`
You can choose between five ways to use `Paint.[]` by setting `Paint.mode` to one of the following:
* **0xFFFFFF**: Use 16777215 *true colors*
* **256**: Use the 256 colors palette
* **16**: Use the eight ANSI colors (combined with bright effect)
* **8**: Use the eight ANSI colors
* **0**: Don't colorize at all
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.
## More Details About Terminal Colors and Effects
Terminal colors/effects get created by [ANSI escape sequences](https://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:
* `:black`
* `:red`
* `:green`
* `:yellow`
* `:blue`
* `:magenta`
* `:cyan`
* `:white`, `:gray`
* (`:default`)
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.
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.
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.
### Effects
See [en.wikipedia.org/wiki/ANSI_escape_code](https://en.wikipedia.org/wiki/ANSI_escape_code) for a more detailed discussion:
#### Often supported
0) :reset, :nothing
1) :bright, :bold
4) :underline
7) :inverse, :negative
8) :conceal, :hide
22) :clean
24) :underline_off
26) :inverse_off, :positive
27) :conceal_off, :show, :reveal
#### Not widely supported
2) :faint
3) :italic
5) :blink, :slow_blink
6) :rapid_blink
9) :crossed, :crossed_out
10) :default_font, :font0
11-19) :font1, :font2, :font3, :font4, :font5, :font6, :font7, :font8, :font9
20) :fraktur
21) :bright_off, :bold_off, :double_underline
23) :italic_off, :fraktur_off
25) :blink_off
29) :crossed_off, :crossed_out_off
51) :frame
52) :encircle
53) :overline
54) :frame_off, :encircle_off
55) :overline_off
## Substitution & Nesting
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:
```ruby
Paint%['Yellow string with a %{blue_text} in it', :yellow,
blue_text: ["blue text", :blue]
]
# => "\e[33mYellow string with a \e[34mblue text\e[33m in it\e[0m"
```
## Utilities
The `Paint.random` method generates a random ANSI color you can pass into `Paint.[]`:
```ruby
Paint['Ruby', Paint.random] # Get one of eight random ANSI foreground colors
Paint['Ruby', Paint.random(true)] # Get one of eight random ANSI background colors
```
Another helper method is `Paint.unpaint`, which removes any ANSI colors:
```ruby
Paint.unpaint( Paint['Ruby', :red, :bright] ).should == 'Ruby'
```
You can get a `p` like alternative for calling `puts Paint.[]`:
```ruby
require 'paint/pa'
pa "Ruby", :red, :underline # same as puts Paint["Ruby", :red, :underline]
```
## Advanced Usage: Shortcuts
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.
## J-_-L
Copyright (c) 2011-2020 Jan Lelis , released under the
MIT license.
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)!
paint-2.2.0/Rakefile 0000664 0000000 0000000 00000002113 13624005611 0014266 0 ustar 00root root 0000000 0000000 require 'fileutils'
require 'rspec/core/rake_task'
gemspecs = %w[
paint.gemspec
paint-shortcuts.gemspec
]
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = [
'--colour',
'--format documentation',
'-r ' + File.expand_path( File.join( 'spec', 'spec_helper') ),
]
end
task :default => :spec
task :test => :spec
def gemspec_spec_for(gemspec)
eval(File.read(gemspec), binding, gemspec)
end
desc "Build the gems"
task :gems do
FileUtils.mkdir_p 'pkg'
gemspecs.each{ |gemspec|
sh "gem build #{gemspec}"
spec = gemspec_spec_for(gemspec)
FileUtils.mv "#{spec.name}-#{spec.version}.gem", 'pkg'
}
end
desc "Install the gem locally"
task :install => :gems do
gemspecs.each{ |gemspec|
spec = gemspec_spec_for(gemspec)
sh %{gem install pkg/#{spec.name}-#{spec.version}.gem --no-doc}
}
end
desc "Run a Benchmark"
task :benchmark do
ruby 'benchmark.rb'
end
desc "Print 256 colors rainbow"
task :rainbow256 do
require_relative 'lib/paint'
(0...256).each{ |color|
print Paint[' ', 48, 5, color] # print empty bg color field
}
puts
end
paint-2.2.0/SHORTCUTS.md 0000664 0000000 0000000 00000003660 13624005611 0014551 0 ustar 00root root 0000000 0000000 # Paint::SHORTCUTS [
](https://badge.fury.io/rb/paint-shortcuts)
This is an optional extension gem for [Paint](https://github.com/janlelis/paint)
## Setup
Add to `Gemfile`:
gem 'paint-shortcuts'
and run `bundle install`.
In Ruby do:
require 'paint/shortcuts'
## Description
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)
All you need to do is to setup a hash of symbol keys and escaped color sequences at:
`Paint::SHORTCUTS[:your_namespace]`:
```ruby
Paint::SHORTCUTS[:example] = {
:white => Paint.color(:black),
:red => Paint.color(:red, :bright),
:title => Paint.color(:underline),
}
```
The methods become "rubymagically" available in a `Paint` child model:
```ruby
Paint::Example.red 'Ruby' # => "\e[31;1mRuby\e[0m"
Paint::Example.white # => "\e[37m"
```
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:
```ruby
include Paint::Example
red # => "\e[31;1m"
white 'Ruby' # => "\e[30m"
```
All shortcuts, defined in your shortcut namespace at this time, are now (privately) available in your current namespace (without relying a `method_missing` implementation).
Furthermore, there are variations of this approach. You get a different behaviour, when you include the `String` sub-module.
```ruby
include Paint::Example::String
"Ruby".title # => "\e[4mRuby\e[0m"
5.red # => "\e[31;1m5\e[0m"
```
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.
The third way allows you to get a single color helper method to avoid cluttering namespaces:
```ruby
include Paint::Example::Prefix::ExampleName
"Ruby".example_name(:red) # => "\e[31;1mRuby\e[0m"
```
paint-2.2.0/benchmark.rb 0000664 0000000 0000000 00000002753 13624005611 0015112 0 ustar 00root root 0000000 0000000 require 'benchmark/ips'
# - - -
require_relative 'lib/paint'
require 'rainbow'
require 'rainbow/version'
require 'term/ansicolor'
require 'pastel'
pastel = Pastel.new
require 'ansi/code'
require 'ansi/version'
require 'hansi'
require 'hansi/version'
# - - -
puts "# TERMINAL ANSI COLORS BENCHMARK"
puts
puts " ruby: #{ RUBY_VERSION }"
puts " paint: #{ Paint::VERSION }"
puts " rainbow: #{ Rainbow::VERSION }"
puts " term/ansicolor #{ Term::ANSIColor::VERSION }"
puts " pastel #{ Pastel::VERSION }"
puts " ansi #{ ANSI::VERSION }"
puts " hansi #{ Hansi::VERSION }"
puts
puts "## ONLY FOREGROUND COLOR"
puts
# - - -
Benchmark.ips do |x|
x.report("paint"){
Paint['ANSI', :red]
}
x.report("paint w/ nesting"){
Paint%['ANSI', :red]
}
x.report("rainbow"){
Rainbow('ANSI').color(:red)
}
x.report("term/ansicolor"){
Term::ANSIColor.red('ANSI')
}
x.report("pastel"){
pastel.red('ANSI')
}
x.report("ansi"){
ANSI::Code.red('ANSI')
}
x.report("hansi"){
Hansi.render(:red, 'ANSI')
}
x.compare!
end
# - - -
puts
puts "## FOREGROUND + BACKGROUND COLOR"
puts
Benchmark.ips do |x|
x.report("paint"){
Paint['ANSI', :red, :green]
}
x.report("paint w/ nesting"){
Paint%['ANSI', :red, :green]
}
x.report("rainbow"){
Rainbow('ANSI').fg(:red).bg(:green)
}
x.report("term/ansicolor"){
Term::ANSIColor.red(Term::ANSIColor.on_green('ANSI'))
}
x.report("pastel"){
pastel.red.on_green('ANSI')
}
x.compare!
end
paint-2.2.0/data/ 0000775 0000000 0000000 00000000000 13624005611 0013535 5 ustar 00root root 0000000 0000000 paint-2.2.0/data/rgb_colors.marshal.gz 0000664 0000000 0000000 00000012312 13624005611 0017657 0 ustar 00root root 0000000 0000000 ZX }\{]Uybyݙ$T!Vҥ@$DbYғ'3sp! (
G%t ZUK* t TZŶP\1Õ5ηqw>g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