paint 0.8.7 → 0.9.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: ced283d5b465e7b6542cfd6753100e230498dbe9
4
- data.tar.gz: e816d3cf009e99ef5e2f9797bd7c0605c5790f77
3
+ metadata.gz: bfb6c0865f627879375ff54af807216e5e0f736d
4
+ data.tar.gz: fa3d2cf817aa88e67cca7a8bceab448321da4c59
5
5
  SHA512:
6
- metadata.gz: f6706e6a54863b5504137291bdb1e300bcdc8a5950f8525fdf9b1bc6828bd45c0cada92f4211735dc766f28c2c102b1eb02fc62b0afe635834ba324aea5a97f4
7
- data.tar.gz: 5af21b99c6074ec374766b8e2aa0995240bb2e22f84d1873c134722008223fd3db6d9e8b1f892098105d997831f07bd75d77f8a961d25f96246647b58b235a74
6
+ metadata.gz: 5880654739c1fb793f43bff78d85c2ef07c9c8e83dba9011e94b59bde884596735107774fa20e0614aba53543c53356af41daef99a443311825b819c449ca18e
7
+ data.tar.gz: 71097ce6065c42c999a33ce7bfe190397c8f26e287cc720bad6a41fc94fbd6750b138f805238fc565a828551c6b6132def89e78f7f1718258a35ddbea703f8bf
@@ -1,3 +1,7 @@
1
+ === 0.9.0
2
+ * Don't colorize strings via shortcuts when Paint.mode == 0
3
+ * Freeze bundled ascii color data
4
+
1
5
  === 0.8.7
2
6
  * Fix caching bug for random ansi color
3
7
 
File without changes
@@ -1,4 +1,4 @@
1
- {<img src="https://travis-ci.org/janlelis/paint.png" />}[https://travis-ci.org/janlelis/paint]
1
+ = Ruby Paint {<img src="https://travis-ci.org/janlelis/paint.png" />}[https://travis-ci.org/janlelis/paint]
2
2
 
3
3
  Paint manages terminal colors and effects for you. It combines the strengths of *term-ansicolor*, *rainbow* and other similar projects into a simple to use, however still flexible terminal colorization gem with no core extensions by default.
4
4
 
@@ -21,6 +21,12 @@ Install with:
21
21
 
22
22
  gem install paint
23
23
 
24
+ Or add to Gemfile:
25
+
26
+ gem 'paint'
27
+
28
+ and run `bundle install`
29
+
24
30
  In Ruby do:
25
31
 
26
32
  require 'paint'
@@ -165,11 +171,10 @@ Another helper method is <tt>Paint.unpaint</tt>, which removes any ansi colors:
165
171
 
166
172
  == J-_-L
167
173
 
168
- Copyright (c) 2011-2013 Jan Lelis, http://rbjl.net, released under the MIT license.
174
+ Copyright (c) 2011-2014 Jan Lelis <http://janlelis.com>, released under the MIT license.
169
175
 
170
- Mainly influenced by rainbow[https://github.com/sickill/rainbow] and {term-ansicolor}[https://github.com/flori/term-ansicolor].
171
-
172
- Contributions[https://github.com/janlelis/paint/contributors] by and thanks to:
173
- * {murphy}[https://github.com/rubychan]
176
+ 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]:
174
177
  * {CyberShadow}[https://github.com/CyberShadow]
175
-
178
+ * {korun}[https://github.com/korun]
179
+ * {mhaylock}[https://github.com/mhaylock]
180
+ * {korny}[https://github.com/rubychan]
data/Rakefile CHANGED
@@ -42,15 +42,6 @@ task :gemspec do
42
42
  gemspec.validate
43
43
  end
44
44
 
45
- #Rake::RDocTask.new do |rdoc|
46
- # require File.expand_path( File.join( 'lib', 'paint') )
47
- #
48
- # rdoc.rdoc_dir = 'doc'
49
- # rdoc.title = "paint #{Paint::VERSION}"
50
- # rdoc.rdoc_files.include('README*')
51
- # rdoc.rdoc_files.include('lib/**/*.rb')
52
- #end
53
-
54
45
  desc "Run a Benchmark"
55
46
  task :benchmark do
56
47
  require 'benchmark'
@@ -58,11 +49,11 @@ task :benchmark do
58
49
  class String
59
50
  include Term::ANSIColor
60
51
  end
61
-
52
+
62
53
  require 'rainbow'
63
54
  $:.unshift '../lib'
64
55
  require 'paint'
65
-
56
+
66
57
  n = 100_000
67
58
  colors = [:black, :red, :green, :yellow, :blue, :magenta, :cyan]
68
59
  def colors.next
@@ -71,7 +62,7 @@ task :benchmark do
71
62
  end
72
63
  Benchmark.bmbm 30 do |results|
73
64
  string = 'Ruby is awesome!'
74
-
65
+
75
66
  results.report 'cycle' do
76
67
  n.times do
77
68
  colors.next
@@ -83,16 +74,16 @@ task :benchmark do
83
74
  Paint[string, colors.next]
84
75
  end
85
76
  end
86
-
77
+
87
78
  results.report 'term-ansicolor' do
88
79
  n.times do
89
80
  string.send(colors.next)
90
81
  end
91
82
  end
92
-
83
+
93
84
  results.report 'rainbow' do
94
85
  n.times do
95
- string.color(colors.next)
86
+ Rainbow(string).color(colors.next)
96
87
  end
97
88
  end
98
89
 
@@ -107,10 +98,10 @@ task :benchmark do
107
98
  string.send(colors.next).send("on_#{colors.next}")
108
99
  end
109
100
  end
110
-
101
+
111
102
  results.report 'rainbow with background' do
112
103
  n.times do
113
- string.color(colors.next).background(colors.next)
104
+ Rainbow(string).color(colors.next).background(colors.next)
114
105
  end
115
106
  end
116
107
  end
@@ -7,7 +7,7 @@ module Paint
7
7
  autoload :RGB_COLORS_ANSI, 'paint/rgb_colors_ansi'
8
8
 
9
9
  # Important purpose
10
- NOTHING = "\033[0m"
10
+ NOTHING = "\033[0m".freeze
11
11
 
12
12
  # Basic colors (often, the color differs when using the bright effect)
13
13
  # Final color will be 30 + value for foreground and 40 + value for background
@@ -21,7 +21,7 @@ module Paint
21
21
  :cyan => 6,
22
22
  :white => 7,
23
23
  :default => 9,
24
- }
24
+ }.freeze
25
25
 
26
26
  # Terminal effects - most of them are not supported ;)
27
27
  # See http://en.wikipedia.org/wiki/ANSI_escape_code
@@ -52,33 +52,33 @@ module Paint
52
52
  :overline => 53,
53
53
  :frame_off => 54, :encircle_off => 54,
54
54
  :overline_off => 55,
55
- }
55
+ }.freeze
56
56
 
57
57
  # cache
58
58
  ANSI_COLORS_FOREGROUND = {
59
- :black => '30',
60
- :red => '31',
61
- :green => '32',
62
- :yellow => '33',
63
- :blue => '34',
64
- :magenta => '35',
65
- :cyan => '36',
66
- :white => '37',
67
- :default => '39',
68
- }
59
+ :black => 30,
60
+ :red => 31,
61
+ :green => 32,
62
+ :yellow => 33,
63
+ :blue => 34,
64
+ :magenta => 35,
65
+ :cyan => 36,
66
+ :white => 37,
67
+ :default => 39,
68
+ }.freeze
69
69
 
70
70
  # cache
71
71
  ANSI_COLORS_BACKGROUND = {
72
- :black => '40',
73
- :red => '41',
74
- :green => '42',
75
- :yellow => '43',
76
- :blue => '44',
77
- :magenta => '45',
78
- :cyan => '46',
79
- :white => '47',
80
- :default => '49',
81
- }
72
+ :black => 40,
73
+ :red => 41,
74
+ :green => 42,
75
+ :yellow => 43,
76
+ :blue => 44,
77
+ :magenta => 45,
78
+ :cyan => 46,
79
+ :white => 47,
80
+ :default => 49,
81
+ }.freeze
82
82
 
83
83
  class << self
84
84
  # Takes a string and color options and colorizes the string
@@ -10,7 +10,7 @@ module Paint
10
10
  :magenta => [205,0,205],
11
11
  :cyan => [0,205,205],
12
12
  :white => [229,229,229],
13
- }
13
+ }.each { |k, v| v.freeze }.freeze
14
14
 
15
15
  # A list of color names for standard bright ansi colors, needed for 16 color fallback mode
16
16
  # See http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@@ -23,5 +23,5 @@ module Paint
23
23
  :magenta => [255,0,255],
24
24
  :cyan => [0,255,255],
25
25
  :white => [255,255,255],
26
- }
26
+ }.each { |k, v| v.freeze }.freeze
27
27
  end
@@ -23,7 +23,14 @@ module Paint
23
23
  # mod.define_singleton_method :method_missing do |color_name, *args|
24
24
  eigen_mod.send:define_method, :method_missing do |color_name, *args|
25
25
  if color_code = shortcuts[color_name]
26
- if args.empty? then color_code else color_code + Array(args).join + NOTHING end
26
+ string = Array(args).join
27
+ return string if Paint.mode.zero?
28
+
29
+ if args.empty?
30
+ color_code
31
+ else
32
+ color_code + string + NOTHING
33
+ end
27
34
  else
28
35
  nil
29
36
  end
@@ -37,7 +44,14 @@ module Paint
37
44
  eigen_mod.send:define_method, :included do |_|
38
45
  shortcuts.each{ |color_name, color_code|
39
46
  define_method color_name do |*args|
40
- if args.empty? then color_code else color_code + Array(args).join + NOTHING end
47
+ string = Array(args).join
48
+ return string if Paint.mode.zero?
49
+
50
+ if args.empty?
51
+ color_code
52
+ else
53
+ color_code + string + NOTHING
54
+ end
41
55
  end
42
56
  }
43
57
  private(*shortcuts.keys) unless shortcuts.empty?
@@ -50,7 +64,11 @@ module Paint
50
64
  eigen_string.send:define_method, :included do |_|
51
65
  shortcuts.each{ |color_name, color_code|
52
66
  define_method color_name do
53
- color_code + to_s + NOTHING
67
+ if Paint.mode.zero?
68
+ to_s
69
+ else
70
+ color_code + to_s + NOTHING
71
+ end
54
72
  end
55
73
  }
56
74
  end
@@ -66,7 +84,13 @@ module Paint
66
84
 
67
85
  eigen_prefix.send:define_method, :included do |_|
68
86
  define_method prefix_name.to_s.gsub(/[A-Z]/,'_\0').downcase[1..-1].to_sym do |color_name|
69
- shortcuts[color_name] && shortcuts[color_name] + to_s + NOTHING
87
+ if color_code = shortcuts[color_name]
88
+ return to_s if Paint.mode.zero?
89
+
90
+ color_code + to_s + NOTHING
91
+ else
92
+ nil
93
+ end
70
94
  end
71
95
  end
72
96
 
@@ -1,3 +1,3 @@
1
1
  module Paint
2
- VERSION = '0.8.7'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -12,20 +12,11 @@ Gem::Specification.new do |s|
12
12
  s.description = "Terminal painter / no string extensions / 256 color support / effect support / define custom shortcuts / basic usage: Paint['string', :red, :bright]"
13
13
  s.required_ruby_version = '>= 1.8.7'
14
14
  s.files = Dir.glob(%w[{lib,test,spec}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c}]) + %w{Rakefile paint.gemspec}
15
- s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
15
+ s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt"]
16
16
  s.license = 'MIT'
17
- s.add_development_dependency 'rspec'
18
- s.add_development_dependency 'rspec-core'
17
+
18
+ s.add_development_dependency 'rspec', '>= 3'
19
19
  s.add_development_dependency 'rake'
20
20
  s.add_development_dependency 'rainbow', '1.1.4'
21
21
  s.add_development_dependency 'term-ansicolor'
22
-
23
- len = s.homepage.size
24
- s.post_install_message = \
25
- (" ┌── " + "info ".ljust(len-2,'%') + "─┐\n" +
26
- " J-_-L │ " + s.homepage + " │\n" +
27
- " ├── " + "usage ".ljust(len-2,'%') + "─┤\n" +
28
- " │ " + "require 'paint'".ljust(len,' ') + " │\n" +
29
- " │ " + "puts Paint['J-_-L', :red] # \e[31mJ-_-L\e[0m".ljust(len,' ') + " │\n" +
30
- " └─" + '─'*len + "─┘").gsub('%', '─') # 1.8 workaround
31
22
  end
@@ -1,7 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- # TODO fix include specs, probably failing because of some rspec voodoo
4
-
5
3
  describe 'Paint::SHORTCUTS' do
6
4
  before do
7
5
  Paint::SHORTCUTS[:example] = {
@@ -9,32 +7,37 @@ describe 'Paint::SHORTCUTS' do
9
7
  :red => Paint.color(:red, :bright),
10
8
  :title => Paint.color(:underline),
11
9
  }
10
+
11
+ Paint.mode = 256
12
12
  end
13
13
 
14
14
  context 'Paint::Example.method_missing' do
15
15
  it 'returns a color defined in the SHORTCUTS hash under the :example key' do
16
- Paint::Example.red == "\e[31m"
16
+ Paint::Example.red.should == "\e[31;1m"
17
17
  end
18
18
 
19
19
  it 'returns a color defined in the SHORTCUTS hash under the :some_module key; method takes string to colorize' do
20
- Paint::Example.red 'J-_-L' == "\e[31;1mJ-_-L\e[0m"
20
+ Paint::Example.red('J-_-L').should == "\e[31;1mJ-_-L\e[0m"
21
21
  end
22
- end
23
22
 
24
- context 'include Paint::Example' do
25
- include Paint::Example
26
- #red.should == "\e[31;1m"
27
- #white( 'Ruby' ).should "\e[30m"
28
- end
23
+ context 'Paint.mode is 0' do
24
+ before do
25
+ Paint.mode = 0
26
+ end
29
27
 
28
+ it "doesn't colorize a string passed into a color defined in the SHORTCUTS hash under the :some_module key" do
29
+ Paint::Example.red('J-_-L').should == 'J-_-L'
30
+ end
31
+ end
32
+ end
30
33
 
31
34
  context 'include Paint::Example::String' do
32
35
  it 'adds shortcuts methods that colorize self' do
33
- class MyString < String # could also have used original String
36
+ class MyString < String
34
37
  include Paint::Example::String
35
38
  end
36
39
 
37
- # MyString.new("J-_-L").red.should == "\e[31;1mJ-_-L\e[0m"
40
+ MyString.new("J-_-L").red.should == "\e[31;1mJ-_-L\e[0m"
38
41
  end
39
42
 
40
43
  it 'adds shortcuts methods that colorize self (also works for non-String classes by calling to_s)' do
@@ -42,7 +45,8 @@ describe 'Paint::SHORTCUTS' do
42
45
  class Integer
43
46
  include Paint::Example::String
44
47
  end
45
- #123.red.should == "\e[38;5;226m123\e[0m"
48
+
49
+ 123.red.should == "\e[31;1m123\e[0m"
46
50
  end
47
51
  end
48
52
 
@@ -51,7 +55,8 @@ describe 'Paint::SHORTCUTS' do
51
55
  class Object
52
56
  include Paint::Example::Prefix::ExampleName
53
57
  end
54
- #"Ruby".example_name(:red).should == "\e[31;1mRuby\e[0m"
58
+
59
+ "Ruby".example_name(:red).should == "\e[31;1mRuby\e[0m"
55
60
  end
56
61
  end
57
62
  end
@@ -1 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../lib/paint'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |c|
5
+ c.syntax = :should
6
+ end
7
+ 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: 0.8.7
4
+ version: 0.9.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: 2014-01-19 00:00:00.000000000 Z
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec-core
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '3'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,10 +73,10 @@ executables: []
87
73
  extensions: []
88
74
  extra_rdoc_files:
89
75
  - README.rdoc
90
- - LICENSE.txt
76
+ - MIT-LICENSE.txt
91
77
  files:
92
78
  - CHANGELOG.rdoc
93
- - LICENSE.txt
79
+ - MIT-LICENSE.txt
94
80
  - README.rdoc
95
81
  - Rakefile
96
82
  - lib/paint.rb
@@ -110,9 +96,7 @@ homepage: https://github.com/janlelis/paint
110
96
  licenses:
111
97
  - MIT
112
98
  metadata: {}
113
- post_install_message: " ┌── info ───────────────────────────┐\n J-_-L │ https://github.com/janlelis/paint
114
- │\n ├── usage ──────────────────────────┤\n │ require 'paint' │\n
115
- \ │ puts Paint['J-_-L', :red] # \e[31mJ-_-L\e[0m │\n └───────────────────────────────────┘"
99
+ post_install_message:
116
100
  rdoc_options: []
117
101
  require_paths:
118
102
  - lib
@@ -128,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
112
  version: '0'
129
113
  requirements: []
130
114
  rubyforge_project:
131
- rubygems_version: 2.2.1
115
+ rubygems_version: 2.2.2
132
116
  signing_key:
133
117
  specification_version: 4
134
118
  summary: Terminal painter!