rainbow 2.2.2 → 3.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: ae78749f89ed058bfe6d143f96ab9140e243a0bc
4
- data.tar.gz: 0ea8625303c1f3c6668ef9cf05692db0295138a3
3
+ metadata.gz: 831ab2db7f80a9a72f2993f1e7b4f3ffa08a4495
4
+ data.tar.gz: 0f842d288049511c94a95ce9b8a9210cf5e2344b
5
5
  SHA512:
6
- metadata.gz: 6a4d28dea14c12a91fb545046183a8fe02b1da104f4dd52c59245cb045ce1116b5b2777570a211112f973ccf52d18cea9547ae1f9ce0405e72538d2dceb4237a
7
- data.tar.gz: 03c7b7197f82cd5974c01458524217cfd000a67cff73962b67440c3c44dfd261c5fa1b160da99110fb618a09b3830d0fac1b9b47e854daa28ee0543ff40856df
6
+ metadata.gz: ecde479bb8ea6f267200efaf03be79e7141bf6fccd7a7191960b2f9f52d809120a943a341f467f0a01c982ff11bf8bd23e66c8732d3af0b22643be5da13b55ec
7
+ data.tar.gz: b11241f918993558e8a4d248d9eb4b458793e926e10e7e387d5dabaf9e15a988adeda1441c93b3be9d051c939fbf566b2493ba9f8df8eff0bbf629bf36798cac
@@ -1,7 +1,13 @@
1
- Documentation:
2
- Enabled: false
1
+ inherit_from: .rubocop_todo.yml
3
2
 
4
- EmptyLinesAroundBody:
3
+ AllCops:
4
+ DisplayCopNames: true
5
+ DisplayStyleGuide: true
6
+ TargetRubyVersion: "2.1"
7
+ Exclude:
8
+ - "spec/**/*"
9
+ - "vendor/**/*"
10
+ Documentation:
5
11
  Enabled: false
6
12
 
7
13
  HashSyntax:
@@ -0,0 +1,29 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-06-30 12:37:52 +0200 using RuboCop version 0.49.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 25
12
+
13
+ # Offense count: 1
14
+ Metrics/CyclomaticComplexity:
15
+ Max: 9
16
+
17
+ # Offense count: 1
18
+ # Configuration parameters: CountComments.
19
+ Metrics/MethodLength:
20
+ Max: 23
21
+
22
+ # Offense count: 1
23
+ # Configuration parameters: CountComments.
24
+ Metrics/ModuleLength:
25
+ Max: 147
26
+
27
+ # Offense count: 1
28
+ Metrics/PerceivedComplexity:
29
+ Max: 8
@@ -1,22 +1,24 @@
1
1
  language: ruby
2
2
  cache:
3
- - bundler
3
+ bundler: true
4
+
4
5
  before_install:
5
- - gem update --system
6
6
  - gem install bundler
7
+
7
8
  bundler_args: --without guard development
8
9
 
9
10
  matrix:
10
11
  include:
11
- - rvm: 2.0.0
12
- - rvm: 2.1.9
13
- - rvm: 2.2.6
14
- - rvm: 2.3.3
15
- - rvm: 2.4.0
16
- - rvm: jruby-9.1.6.0
12
+ - rvm: 2.1.10
13
+ - rvm: 2.2.7
14
+ - rvm: 2.3.4
15
+ - rvm: 2.4.1
16
+ - rvm: jruby-9.1.14.0
17
17
  jdk: oraclejdk8
18
- env:
19
- - JRUBY_OPTS=--debug
20
- - rvm: 2.2.6
18
+ - rvm: 2.2.7
21
19
  install: true # This skips 'bundle install'
22
20
  script: gem build rainbow && gem install *.gem
21
+
22
+ env:
23
+ global:
24
+ - JRUBY_OPTS=--debug
@@ -1,47 +1,45 @@
1
1
  # Rainbow changelog
2
2
 
3
- ## 1.0.0 (2008-7-21)
4
-
5
- * initial version
3
+ ## 3.0.0 (2017-10-24)
6
4
 
7
- ## 1.0.1 (2009-3-19)
8
-
9
- * Windows support
5
+ * dropped MRI 1.9.3 compatibility
6
+ * dropped MRI 2.0 compatibility
7
+ * removed rake dependency
10
8
 
11
- ## 1.0.2 (2009-5-15)
12
-
13
- * improved support for ruby 1.8.6 and 1.9.1
14
-
15
- ## 1.0.3 (2009-7-26)
9
+ ## 2.2.2 (2017-04-21)
16
10
 
17
- * rainbow methods don't mutate the original string object anymore
11
+ * added explicit rake dependency to fix installation issue
18
12
 
19
- ## 1.0.4 (2009-11-27)
13
+ ## 2.2.1 (2016-12-28)
20
14
 
21
- * support for 256 colors
15
+ * fixed gem installation (2.2.0 was a broken release)
22
16
 
23
- ## 1.1 (2010-6-7)
17
+ ## 2.2.0 (2016-12-27)
24
18
 
25
- * option for enabling/disabling of escape code wrapping
26
- * auto-disabling when STDOUT is not a TTY
19
+ * improved Windows support
20
+ * added Ruby 2.4 support
21
+ * added `bold` alias method for `bright`
27
22
 
28
- ## 1.1.1 (2011-2-7)
23
+ ## 2.1.0 (2016-01-24)
29
24
 
25
+ * added X11 color support
26
+ * fixed `require` issue when rainbow is used as a dependency in another gem
30
27
  * improved Windows support
31
28
 
32
- ## 1.1.2 (2011-11-13)
29
+ ## 2.0.0 (2014-01-24)
33
30
 
34
- * improved compatibility with MRI 1.9.3
31
+ * disable string mixin by default
35
32
 
36
- ## 1.1.3 (2011-12-6)
33
+ ## 1.99.2 (2014-01-24)
37
34
 
38
- * improved compatibility with MRI 1.8.7
39
- * fix for regression with regards to original string mutation
35
+ * bring back ruby 1.8 support
40
36
 
41
- ## 1.1.4 (2012-4-28)
37
+ ## 1.99.1 (2013-12-28)
42
38
 
43
- * option for forcing coloring even when STDOUT is not a TTY (CLICOLOR_FORCE env var)
44
- * fix for frozen strings
39
+ * drop support for ruby 1.8
40
+ * `require "rainbow/string"` -> `require "rainbow/ext/string"`
41
+ * custom rainbow wrapper instances (with separate enabled/disabled state)
42
+ * shortcut methods for changing text color (`Rainbow("foo").red`)
45
43
 
46
44
  ## 1.99.0 (2013-12-26)
47
45
 
@@ -51,37 +49,45 @@
51
49
  * support for MRI 1.8.7, 1.9.2, 1.9.3, 2.0 and 2.1, JRuby and Rubinius
52
50
  * deprecation of Sickill::Rainbow namespace (use Rainbow.enabled = true instead)
53
51
 
54
- ## 1.99.1 (2013-12-28)
52
+ ## 1.1.4 (2012-4-28)
55
53
 
56
- * drop support for ruby 1.8
57
- * `require "rainbow/string"` -> `require "rainbow/ext/string"`
58
- * custom rainbow wrapper instances (with separate enabled/disabled state)
59
- * shortcut methods for changing text color (`Rainbow("foo").red`)
54
+ * option for forcing coloring even when STDOUT is not a TTY (CLICOLOR_FORCE env var)
55
+ * fix for frozen strings
60
56
 
61
- ## 1.99.2 (2014-01-24)
57
+ ## 1.1.3 (2011-12-6)
62
58
 
63
- * bring back ruby 1.8 support
59
+ * improved compatibility with MRI 1.8.7
60
+ * fix for regression with regards to original string mutation
64
61
 
65
- ## 2.0.0 (2014-01-24)
62
+ ## 1.1.2 (2011-11-13)
66
63
 
67
- * disable string mixin by default
64
+ * improved compatibility with MRI 1.9.3
68
65
 
69
- ## 2.1.0 (2016-01-24)
66
+ ## 1.1.1 (2011-2-7)
70
67
 
71
- * added X11 color support
72
- * fixed `require` issue when rainbow is used as a dependency in another gem
73
68
  * improved Windows support
74
69
 
75
- # 2.2.0 (2016-12-27)
70
+ ## 1.1 (2010-6-7)
76
71
 
77
- * improved Windows support
78
- * added Ruby 2.4 support
79
- * added `bold` alias method for `bright`
72
+ * option for enabling/disabling of escape code wrapping
73
+ * auto-disabling when STDOUT is not a TTY
80
74
 
81
- # 2.2.1 (2016-12-28)
75
+ ## 1.0.4 (2009-11-27)
82
76
 
83
- * fixed gem installation (2.2.0 was a broken release)
77
+ * support for 256 colors
84
78
 
85
- # 2.2.2 (2017-04-21)
79
+ ## 1.0.3 (2009-7-26)
86
80
 
87
- * added explicit rake dependency to fix installation issue
81
+ * rainbow methods don't mutate the original string object anymore
82
+
83
+ ## 1.0.2 (2009-5-15)
84
+
85
+ * improved support for ruby 1.8.6 and 1.9.1
86
+
87
+ ## 1.0.1 (2009-3-19)
88
+
89
+ * Windows support
90
+
91
+ ## 1.0.0 (2008-7-21)
92
+
93
+ * initial version
data/Gemfile CHANGED
@@ -1,17 +1,22 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in rainbow.gemspec
4
3
  gemspec
5
4
 
6
5
  gem 'rake'
7
- gem 'coveralls', require: false
8
- gem 'mime-types', '< 2.0.0', platforms: [:ruby_18]
9
- gem 'rspec'
6
+
7
+ group :test do
8
+ gem 'coveralls', require: false
9
+ gem 'rspec'
10
+ end
10
11
 
11
12
  group :development do
12
13
  gem 'mutant-rspec'
13
14
  end
14
15
 
16
+ group :test, :development do
17
+ gem 'rubocop', '~> 0.51.0'
18
+ end
19
+
15
20
  group :guard do
16
21
  gem 'guard'
17
22
  gem 'guard-rspec'
data/Guardfile CHANGED
@@ -6,4 +6,3 @@ guard :rspec, cmd: 'rspec --color' do
6
6
  watch(%r{^lib/(.+)\.rb$}) { "spec" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
8
8
  end
9
-
@@ -1,6 +1,8 @@
1
1
  # Rainbow
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rainbow.svg)](https://rubygems.org/gems/rainbow)
3
4
  [![Build Status](https://travis-ci.org/sickill/rainbow.svg?branch=master)](https://travis-ci.org/sickill/rainbow)
5
+ [![Build status](https://ci.appveyor.com/api/projects/status/vq4acb2c38642s5q?svg=true)](https://ci.appveyor.com/project/sickill/rainbow)
4
6
  [![Code Climate](https://codeclimate.com/github/sickill/rainbow.svg)](https://codeclimate.com/github/sickill/rainbow)
5
7
  [![Coverage Status](https://coveralls.io/repos/sickill/rainbow/badge.svg)](https://coveralls.io/r/sickill/rainbow)
6
8
 
@@ -27,6 +29,8 @@ puts Rainbow("this is red").red + " and " + Rainbow("this on yellow bg").bg(:yel
27
29
  # => "\e[31mthis is red\e[0m and \e[43mthis on yellow bg\e[0m and \e[4m\e[1meven bright underlined!\e[0m"
28
30
  ```
29
31
 
32
+ Or, [watch this video example](https://asciinema.org/a/J928KpHoUQ0sl54ulOSOLE71E?rows=20&speed=2.5)
33
+
30
34
  ### Rainbow presenter API
31
35
 
32
36
  Rainbow presenter adds the following methods to presented string:
@@ -63,28 +67,27 @@ calls:
63
67
  Rainbow("hola!").blue.bright.underline
64
68
  ```
65
69
 
66
- ### String mixin
70
+ ### Refinement
67
71
 
68
- If you don't like wrapping every string you want to colorize with `Rainbow()`
69
- you can include all the rainbow presenter methods directly in a String class by
70
- requiring `rainbow/ext/string`:
72
+ If you want to use the Refinements version, you can:
71
73
 
72
74
  ```ruby
73
- require 'rainbow/ext/string'
74
-
75
- puts "this is red".color(:red) + " and " + "this on yellow bg".background(:yellow) + " and " + "even bright underlined!".underline.bright
75
+ require 'rainbow/refinement'
76
+ using Rainbow
77
+ puts "Hi!".green
76
78
  ```
77
79
 
78
- This way of using Rainbow is not recommended though as it pollutes String's
79
- public interface with methods that are presentation specific.
80
-
81
- NOTE: the mixin doesn't include shortcut methods for changing text color, you
82
- should use "string".color(:blue) instead of "string".blue
80
+ Here's an IRB session example:
83
81
 
84
- NOTE: the mixin is included in String by default in rainbow 1.x versions.
85
- In rainbow 2.x the behavior was changed - if you're upgrading from 1.x to 2.x
86
- and you used direct String methods then you can either require the string
87
- extension as shown above or update your code to use the new presenter API.
82
+ ```
83
+ >> 'Hello, World!'.blue.bright.underline
84
+ NoMethodError: undefined method `blue' for "Hello, World!":String
85
+ (ripl):1:in `<main>'
86
+ >> using Rainbow
87
+ => main
88
+ >> 'Hello, World!'.blue.bright.underline
89
+ => "\e[34m\e[1m\e[4mHello, World!\e[0m"
90
+ ```
88
91
 
89
92
  ### Color specification
90
93
 
@@ -112,6 +115,20 @@ When you specify a color with a RGB triplet rainbow finds the nearest match
112
115
  from 256 colors palette. Note that it requires a 256-colors capable terminal to
113
116
  display correctly.
114
117
 
118
+ #### Example: Choose a random color
119
+
120
+ You can pick a random color with Rainbow, it's a one-liner:
121
+
122
+ ```ruby
123
+ colors = Range.new(0,7).to_a
124
+ "whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
125
+ # => "\e[36mw\e[0m\e[37mh\e[0m\e[34mo\e[0m\e[34mo\e[0m\e[37mp\e[0m\e[34m \e[0m\e[36md\e[0m\e[33me\e[0m\e[34me\e[0m\e[37m \e[0m\e[32md\e[0m\e[35mo\e[0m\e[33mo\e[0m\e[36mp\e[0m"
126
+
127
+ colors = [:aliceblue, :antiquewhite, :aqua, :aquamarine, :azure, :beige, :bisque, :blanchedalmond, :blueviolet]
128
+ "whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
129
+ # => "\e[38;5;135mw\e[0m\e[38;5;230mh\e[0m\e[38;5;231mo\e[0m\e[38;5;135mo\e[0m\e[38;5;231mp\e[0m\e[38;5;231m \e[0m\e[38;5;122md\e[0m\e[38;5;231me\e[0m\e[38;5;231me\e[0m\e[38;5;230m \e[0m\e[38;5;122md\e[0m\e[38;5;51mo\e[0m\e[38;5;51mo\e[0m\e[38;5;51mp\e[0m"
130
+ ```
131
+
115
132
  ### Configuration
116
133
 
117
134
  Rainbow can be enabled/disabled globally by setting:
@@ -154,16 +171,6 @@ colorize all the strings, even the ones that go through file writing
154
171
  formatters. You can easily solve that by disabling coloring for the Rainbow
155
172
  instances that are used by formatters with file output.
156
173
 
157
- ## Windows support
158
-
159
- For Windows support on Ruby < 2.0, you should install the following gems:
160
-
161
- ```ruby
162
- gem install windows-pr win32console
163
- ```
164
-
165
- If the above gems aren't installed then all strings are returned unmodified.
166
-
167
174
  ## Installation
168
175
 
169
176
  Add it to your Gemfile:
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+
2
3
  require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new
3
5
 
4
- RSpec::Core::RakeTask.new(:spec)
6
+ require 'rubocop/rake_task'
7
+ RuboCop::RakeTask.new
5
8
 
6
- task :default => :spec
9
+ task default: %i[spec rubocop]
@@ -0,0 +1,40 @@
1
+ ---
2
+
3
+ version: "{build}"
4
+
5
+ install:
6
+ - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
7
+ - bundle config --local path vendor/bundle
8
+ - bundle install --jobs 3 --retry 3 --without guard development
9
+
10
+ build: off
11
+
12
+ cache:
13
+ - vendor/bundle
14
+
15
+ init:
16
+ - git config --global core.autocrlf true
17
+
18
+ before_test:
19
+ - ruby -v
20
+ - gem -v
21
+ - bundle -v
22
+
23
+ test_script:
24
+ - bundle exec rake
25
+
26
+ environment:
27
+ matrix:
28
+ - RUBY_VERSION: 21
29
+ - RUBY_VERSION: 21-x64
30
+ - RUBY_VERSION: 22
31
+ - RUBY_VERSION: 22-x64
32
+ - RUBY_VERSION: 23
33
+ - RUBY_VERSION: 23-x64
34
+
35
+ matrix:
36
+ fast_finish: true
37
+
38
+ branches:
39
+ only:
40
+ - master
@@ -1,8 +1,6 @@
1
1
  require_relative 'rainbow/global'
2
- require_relative 'rainbow/legacy'
3
2
 
4
3
  module Rainbow
5
-
6
4
  def self.new
7
5
  Wrapper.new(global.enabled)
8
6
  end
@@ -10,15 +8,4 @@ module Rainbow
10
8
  self.enabled = false unless STDOUT.tty? && STDERR.tty?
11
9
  self.enabled = false if ENV['TERM'] == 'dumb'
12
10
  self.enabled = true if ENV['CLICOLOR_FORCE'] == '1'
13
-
14
- # On Windows systems, try to load the local ANSI support library if Ruby version < 2
15
- # Ruby 2.x on Windows includes ANSI support.
16
- if RUBY_PLATFORM =~ /mswin|cygwin|mingw/ && RUBY_VERSION.to_i < 2
17
- begin
18
- require 'Win32/Console/ANSI'
19
- rescue LoadError
20
- self.enabled = false
21
- end
22
- end
23
-
24
11
  end
@@ -1,12 +1,11 @@
1
1
  module Rainbow
2
2
  class Color
3
-
4
3
  attr_reader :ground
5
4
 
6
5
  def self.build(ground, values)
7
6
  unless [1, 3].include?(values.size)
8
- fail ArgumentError,
9
- "Wrong number of arguments for color definition, should be 1 or 3"
7
+ raise ArgumentError,
8
+ "Wrong number of arguments for color definition, should be 1 or 3"
10
9
  end
11
10
 
12
11
  color = values.size == 1 ? values.first : values
@@ -25,9 +24,9 @@ module Rainbow
25
24
  elsif X11Named.color_names.include?(color)
26
25
  X11Named.new(ground, color)
27
26
  else
28
- fail ArgumentError,
29
- "Unknown color name, valid names: " +
30
- (Named.color_names + X11Named.color_names).join(', ')
27
+ raise ArgumentError,
28
+ "Unknown color name, valid names: " +
29
+ (Named.color_names + X11Named.color_names).join(', ')
31
30
  end
32
31
  when Array
33
32
  RGB.new(ground, *color)
@@ -46,7 +45,6 @@ module Rainbow
46
45
  end
47
46
 
48
47
  class Indexed < Color
49
-
50
48
  attr_reader :num
51
49
 
52
50
  def initialize(ground, num)
@@ -59,11 +57,9 @@ module Rainbow
59
57
 
60
58
  [code]
61
59
  end
62
-
63
60
  end
64
61
 
65
62
  class Named < Indexed
66
-
67
63
  NAMES = {
68
64
  black: 0,
69
65
  red: 1,
@@ -73,26 +69,28 @@ module Rainbow
73
69
  magenta: 5,
74
70
  cyan: 6,
75
71
  white: 7,
76
- default: 9,
77
- }
72
+ default: 9
73
+ }.freeze
78
74
 
79
75
  def self.color_names
80
76
  NAMES.keys
81
77
  end
82
78
 
79
+ def self.valid_names
80
+ color_names.join(', ')
81
+ end
82
+
83
83
  def initialize(ground, name)
84
84
  unless Named.color_names.include?(name)
85
- fail ArgumentError,
86
- "Unknown color name, valid names: #{Named.color_names.join(', ')}"
85
+ raise ArgumentError,
86
+ "Unknown color name, valid names: #{self.class.valid_names}"
87
87
  end
88
88
 
89
89
  super(ground, NAMES[name])
90
90
  end
91
-
92
91
  end
93
92
 
94
93
  class RGB < Indexed
95
-
96
94
  attr_reader :r, :g, :b
97
95
 
98
96
  def self.to_ansi_domain(value)
@@ -101,7 +99,7 @@ module Rainbow
101
99
 
102
100
  def initialize(ground, *values)
103
101
  if values.min < 0 || values.max > 255
104
- fail ArgumentError, "RGB value outside 0-255 range"
102
+ raise ArgumentError, "RGB value outside 0-255 range"
105
103
  end
106
104
 
107
105
  super(ground, 8)
@@ -116,10 +114,9 @@ module Rainbow
116
114
 
117
115
  def code_from_rgb
118
116
  16 + self.class.to_ansi_domain(r) * 36 +
119
- self.class.to_ansi_domain(g) * 6 +
120
- self.class.to_ansi_domain(b)
117
+ self.class.to_ansi_domain(g) * 6 +
118
+ self.class.to_ansi_domain(b)
121
119
  end
122
-
123
120
  end
124
121
 
125
122
  class X11Named < RGB
@@ -129,16 +126,18 @@ module Rainbow
129
126
  NAMES.keys
130
127
  end
131
128
 
129
+ def self.valid_names
130
+ color_names.join(', ')
131
+ end
132
+
132
133
  def initialize(ground, name)
133
134
  unless X11Named.color_names.include?(name)
134
- fail ArgumentError,
135
- "Unknown color name, valid names: #{X11Named.color_names.join(', ')}"
135
+ raise ArgumentError,
136
+ "Unknown color name, valid names: #{self.class.valid_names}"
136
137
  end
137
138
 
138
139
  super(ground, *NAMES[name])
139
140
  end
140
-
141
141
  end
142
-
143
142
  end
144
143
  end