colorize 0.7.7 → 0.8.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: 4d6a78ce56a2f5f15a6aa385d4392ed77573bafd
4
- data.tar.gz: a6bebc23aa54dedd2024e76730d2dff2102042c1
3
+ metadata.gz: 0be0a115e11c6219ca857f092e1ff9b066242644
4
+ data.tar.gz: c223c4263dd10b8446ce5a07940233d754b5c70d
5
5
  SHA512:
6
- metadata.gz: d98cd2d1831808834717eb8abbed5478804c0f1b1bfc465a44b5561a720d8691817f21e05e94cccd74ebfe2666699247b0f62893526f76aea8da68937333a36c
7
- data.tar.gz: b789dee63ba19a0b4f1d177dc034006e58526e3ef875b51950cd6e7298343a716f90e8b4da291fb0d82d252bc571ab6070b5db6a8f650ffedd310a9c099a4e8a
6
+ metadata.gz: 8e6b4c310dda218b54beb32fc4117de4d6ff080cf3966bcfa83302af56de3806ab0032df29764838800802adbff81482eb00b60614eb7b8e4720bba329762b9e
7
+ data.tar.gz: e080a425e29bb91a6763c9fb120391d43b3aca8f8c5887b8a105d2c84145bf86bbfaf3a7c3ec33bd51a0c065a9025d87d984258323250304555b7869f90e301d
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.8.0 / 2016-06-27
2
+ * add ColorizedString class
3
+ * update README file
4
+ * add rubocop.yml and follow style
5
+ * add italic mode
6
+ * remove interpreter warrnings
7
+
1
8
  == 0.7.7 / 2015-04-19
2
9
  * update gems
3
10
 
data/README.md CHANGED
@@ -1,7 +1,14 @@
1
1
  colorize [![Gem Version](https://badge.fury.io/rb/colorize.svg)](http://badge.fury.io/rb/colorize) [![Build Status](https://travis-ci.org/fazibear/colorize.svg?branch=master)](https://travis-ci.org/fazibear/colorize) [![Code Climate](https://codeclimate.com/github/fazibear/colorize/badges/gpa.svg)](https://codeclimate.com/github/fazibear/colorize) [![Test Coverage](https://codeclimate.com/github/fazibear/colorize/badges/coverage.svg)](https://codeclimate.com/github/fazibear/colorize)
2
2
  ========
3
3
 
4
- Ruby String class extension. Adds methods to set text color, background color and, text effects on ruby console and command line output, using ANSI escape sequences.
4
+ Ruby gem for colorizing text using ANSI escape sequences.
5
+ Extends `String` class or add a `ColorizedString` with methods to set text color, background color and text effects.
6
+
7
+ modes
8
+ -----
9
+
10
+ * `require 'colorize'` - Extends String class
11
+ * `require 'colorized_string'` - add ColorizedString class
5
12
 
6
13
  features
7
14
  --------
@@ -9,13 +16,24 @@ features
9
16
  * change string color
10
17
  * change string background
11
18
  * change string effect
19
+ * display color samples
20
+ * disable colorization
12
21
 
13
22
  usage
14
23
  -----
15
24
 
16
- Some usage samples:
17
-
18
25
  ```ruby
26
+ require 'colorize'
27
+
28
+ String.colors # return array of all possible colors names
29
+ String.modes # return array of all possible modes
30
+ String.color_samples # displays color samples in all combinations
31
+ String.disable_colorization # check if colorization is disabled
32
+ String.disable_colorization = false # enable colorization
33
+ String.disable_colorization false # enable colorization
34
+ String.disable_colorization = true # disable colorization
35
+ String.disable_colorization true # disable colorization
36
+
19
37
  puts "This is blue".colorize(:blue)
20
38
  puts "This is light blue".colorize(:light_blue)
21
39
  puts "This is also blue".colorize(:color => :blue)
@@ -28,17 +46,31 @@ puts "This is blue text on red".blue.on_red.blink
28
46
  puts "This is uncolorized".blue.on_red.uncolorize
29
47
  ```
30
48
 
31
- Class methods:
32
-
33
49
  ```ruby
34
- String.colors # return array of all possible colors names
35
- String.modes # return array of all possible modes
36
- String.color_samples # displays color samples in all combinations
37
- String.disable_colorization # check if colorization is disabled
38
- String.disable_colorization = false # enable colorization
39
- String.disable_colorization false # enable colorization
40
- String.disable_colorization = true # disable colorization
41
- String.disable_colorization true # disable colorization
50
+ require 'colorized_string'
51
+
52
+ ColorizedString.colors # return array of all possible colors names
53
+ ColorizedString.modes # return array of all possible modes
54
+ ColorizedString.color_samples # displays color samples in all combinations
55
+ ColorizedString.disable_colorization # check if colorization is disabled
56
+ ColorizedString.disable_colorization = false # enable colorization
57
+ ColorizedString.disable_colorization false # enable colorization
58
+ ColorizedString.disable_colorization = true # disable colorization
59
+ ColorizedString.disable_colorization true # disable colorization
60
+
61
+ puts ColorizedString["This is blue"].colorize(:blue)
62
+ puts ColorizedString["This is light blue"].colorize(:light_blue)
63
+ puts ColorizedString["This is also blue"].colorize(:color => :blue)
64
+ puts ColorizedString["This is light blue with red background"].colorize(:color => :light_blue, :background => :red)
65
+ puts ColorizedString["This is light blue with red background"].colorize(:light_blue ).colorize( :background => :red)
66
+ puts ColorizedString["This is blue text on red"].blue.on_red
67
+ puts ColorizedString["This is red on blue"].colorize(:red).on_blue
68
+ puts ColorizedString["This is red on blue and underline"].colorize(:red).on_blue.underline
69
+ puts ColorizedString["This is blue text on red"].blue.on_red.blink
70
+ puts ColorizedString["This is uncolorized"].blue.on_red.uncolorize
71
+
72
+ puts ColorizedString.new("This is blue").blue
73
+ puts ColorizedString.new("This is light blue").colorize(:light_blue)
42
74
  ```
43
75
 
44
76
  requirements
@@ -56,7 +88,7 @@ install
56
88
  license
57
89
  -------
58
90
 
59
- Copyright (C) 2007-2015 Michał Kalbarczyk
91
+ Copyright (C) 2007-2016 Michał Kalbarczyk
60
92
 
61
93
  This program is free software; you can redistribute it and/or modify
62
94
  it under the terms of the GNU General Public License as published by
data/Rakefile CHANGED
@@ -5,4 +5,9 @@ Rake::TestTask.new do |t|
5
5
  end
6
6
 
7
7
  desc 'Run tests'
8
- task :default => :test
8
+ task :default do
9
+ ENV['TEST'] = 'test/test_colorize.rb'
10
+ Rake::Task[:test].execute
11
+ ENV['TEST'] = 'test/test_colorized_string.rb'
12
+ Rake::Task[:test].execute
13
+ end
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'colorize'
3
- s.version = '0.7.7'
3
+ s.version = '0.8.0'
4
4
 
5
5
  s.authors = ['Michał Kalbarczyk']
6
6
  s.email = 'fazibear@gmail.com'
7
7
 
8
- s.date = Time.now.strftime("%Y-%m-%d")
8
+ s.date = Time.now.strftime('%Y-%m-%d')
9
9
 
10
10
  s.homepage = 'http://github.com/fazibear/colorize'
11
- s.description = 'Ruby String class extension. Adds methods to set text color, background color and, text effects on ruby console and command line output, using ANSI escape sequences.'
12
- s.summary = 'Add color methods to String class'
13
- s.license = 'GPL-2'
11
+ s.description = 'Extends String class or add a ColorizedString with methods to set text color, background color and text effects.'
12
+ s.summary = 'Ruby gem for colorizing text using ANSI escape sequences.'
13
+ s.license = 'GPL-2.0'
14
14
 
15
15
  s.require_paths = ['lib']
16
16
 
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('colorize/class_methods', File.dirname(__FILE__))
2
2
  require File.expand_path('colorize/instance_methods', File.dirname(__FILE__))
3
3
  #
4
- # Colorize String class extension.
4
+ # String class extension.
5
5
  #
6
6
  class String
7
7
  extend Colorize::ClassMethods
@@ -1,12 +1,15 @@
1
1
  module Colorize
2
2
  module ClassMethods
3
-
4
3
  #
5
4
  # Property to disable colorization
6
5
  #
7
6
  def disable_colorization(value = nil)
8
7
  if value.nil?
9
- @disable_colorization || false
8
+ if defined?(@disable_colorization)
9
+ @disable_colorization || false
10
+ else
11
+ false
12
+ end
10
13
  else
11
14
  @disable_colorization = (value || false)
12
15
  end
@@ -39,17 +42,17 @@ module Colorize
39
42
  def color_samples
40
43
  colors.permutation(2).each do |background, color|
41
44
  sample_text = "#{color.inspect.rjust(15)} on #{background.inspect.ljust(15)}"
42
- puts "#{sample_text.colorize(:color => color, :background => background)} #{sample_text}"
45
+ puts "#{new(sample_text).colorize(:color => color, :background => background)} #{sample_text}"
43
46
  end
44
47
  end
45
48
 
46
49
  #
47
50
  # Method removed, raise NoMethodError
48
51
  #
49
- def color_matrix(txt = '')
52
+ def color_matrix(_ = '')
50
53
  fail NoMethodError, '#color_matrix method was removed, try #color_samples instead'
51
54
  end
52
-
55
+
53
56
  # private
54
57
 
55
58
  #
@@ -76,13 +79,14 @@ module Colorize
76
79
  {
77
80
  :default => 0, # Turn off all attributes
78
81
  :bold => 1, # Set bold mode
82
+ :italic => 3, # Set italic mode
79
83
  :underline => 4, # Set underline mode
80
84
  :blink => 5, # Set blink mode
81
85
  :swap => 7, # Exchange foreground and background colors
82
86
  :hide => 8 # Hide text (foreground color would be the same as background)
83
87
  }
84
88
  end
85
-
89
+
86
90
  #
87
91
  # Generate color and on_color methods
88
92
  #
@@ -1,6 +1,5 @@
1
1
  module Colorize
2
2
  module InstanceMethods
3
-
4
3
  #
5
4
  # Change color of string
6
5
  #
@@ -20,9 +19,9 @@ module Colorize
20
19
  def colorize(params)
21
20
  return self if self.class.disable_colorization
22
21
  require_windows_libs
23
- scan_for_colors.inject('') do |str, match|
24
- defaults_colors(match)
22
+ scan_for_colors.inject(self.class.new) do |str, match|
25
23
  colors_from_params(match, params)
24
+ defaults_colors(match)
26
25
  str << "\033[#{match[0]};#{match[1]};#{match[2]}m#{match[3]}\033[0m"
27
26
  end
28
27
  end
@@ -31,7 +30,7 @@ module Colorize
31
30
  # Return uncolorized string
32
31
  #
33
32
  def uncolorize
34
- scan_for_colors.inject('') do |str, match|
33
+ scan_for_colors.inject(self.class.new) do |str, match|
35
34
  str << match[3]
36
35
  end
37
36
  end
@@ -70,8 +69,8 @@ module Colorize
70
69
  # Set colors from params hash
71
70
  #
72
71
  def colors_from_hash(match, hash)
73
- match[0] = mode(hash[:mode]) if mode(hash[:mode])
74
- match[1] = color(hash[:color]) if color(hash[:color])
72
+ match[0] = mode(hash[:mode]) if mode(hash[:mode])
73
+ match[1] = color(hash[:color]) if color(hash[:color])
75
74
  match[2] = background_color(hash[:background]) if background_color(hash[:background])
76
75
  end
77
76
 
@@ -113,23 +112,21 @@ module Colorize
113
112
  end
114
113
 
115
114
  def split_colors(match)
116
- colors = (match[0] || "").split(';')
117
- Array.new(4).tap do |array|
118
- array[0], array[1], array[2] = colors if colors.length == 3
119
- array[1] = colors if colors.length == 1
120
- array[3] = match[1] || match[2]
121
- end
115
+ colors = (match[0] || '').split(';')
116
+ array = Array.new(3)
117
+ array[0], array[1], array[2] = colors if colors.length == 3
118
+ array[1] = colors if colors.length == 1
119
+ array[3] = match[1] || match[2]
120
+ array
122
121
  end
123
122
 
124
123
  #
125
124
  # Require windows libs
126
125
  #
127
126
  def require_windows_libs
128
- begin
129
- require 'Win32/Console/ANSI' if RUBY_VERSION < "2.0.0" && RUBY_PLATFORM =~ /win32/
130
- rescue LoadError
131
- raise 'You must gem install win32console to use colorize on Windows'
132
- end
127
+ require 'Win32/Console/ANSI' if RUBY_VERSION < '2.0.0' && RUBY_PLATFORM =~ /win32/
128
+ rescue LoadError
129
+ raise 'You must gem install win32console to use colorize on Windows'
133
130
  end
134
131
  end
135
132
  end
@@ -1,7 +1,7 @@
1
- require "codeclimate-test-reporter"
1
+ require 'codeclimate-test-reporter'
2
2
  CodeClimate::TestReporter.start
3
3
 
4
- require "minitest/autorun"
4
+ require 'minitest/autorun'
5
5
  require File.dirname(__FILE__) + '/../lib/colorize'
6
6
 
7
7
  class TestColorize < Minitest::Test
@@ -68,25 +68,28 @@ class TestColorize < Minitest::Test
68
68
 
69
69
  def test_uncolorize
70
70
  assert_equal 'This is uncolorized'.blue.on_red.uncolorize,
71
- "This is uncolorized"
71
+ 'This is uncolorized'
72
72
  end
73
73
 
74
74
  def test_colorized?
75
75
  assert_equal 'Red'.red.colorized?, true
76
76
  assert_equal 'Blue'.colorized?, false
77
77
  assert_equal 'Green'.blue.green.uncolorize.colorized?, false
78
- assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').colorized?, true
79
- assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').uncolorize.colorized?, false
78
+ end
79
+
80
+ def test_concatenated__colorize?
81
+ assert_equal "none #{'red'.red} none #{'blue'.blue} none".colorized?, true
82
+ assert_equal "none #{'red'.red} none #{'blue'.blue} none".uncolorize.colorized?, false
80
83
  end
81
84
 
82
85
  def test_concatenated_strings_on_green
83
- assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').on_green,
84
- "\e[0;39;42mnone\e[0m\e[0;31;42mred\e[0m\e[0;39;42mnone\e[0m\e[0;34;42mblue\e[0m\e[0;39;42mnone\e[0m"
86
+ assert_equal "none #{'red'.red} none #{'blue'.blue} none".on_green,
87
+ "\e[0;39;42mnone \e[0m\e[0;31;42mred\e[0m\e[0;39;42m none \e[0m\e[0;34;42mblue\e[0m\e[0;39;42m none\e[0m"
85
88
  end
86
89
 
87
90
  def test_concatenated_strings_uncolorize
88
- assert_equal ('none' + 'red'.red + 'none' + 'blue'.blue + 'none').uncolorize,
89
- "nonerednonebluenone"
91
+ assert_equal "none #{'red'.red} none #{'blue'.blue} none".uncolorize,
92
+ 'none red none blue none'
90
93
  end
91
94
 
92
95
  def test_frozen_strings
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Kalbarczyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-19 00:00:00.000000000 Z
11
+ date: 2016-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,9 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.4'
55
- description: Ruby String class extension. Adds methods to set text color, background
56
- color and, text effects on ruby console and command line output, using ANSI escape
57
- sequences.
55
+ description: Extends String class or add a ColorizedString with methods to set text
56
+ color, background color and text effects.
58
57
  email: fazibear@gmail.com
59
58
  executables: []
60
59
  extensions: []
@@ -71,7 +70,7 @@ files:
71
70
  - test/test_colorize.rb
72
71
  homepage: http://github.com/fazibear/colorize
73
72
  licenses:
74
- - GPL-2
73
+ - GPL-2.0
75
74
  metadata: {}
76
75
  post_install_message:
77
76
  rdoc_options: []
@@ -89,9 +88,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
88
  version: '0'
90
89
  requirements: []
91
90
  rubyforge_project:
92
- rubygems_version: 2.4.5
91
+ rubygems_version: 2.5.1
93
92
  signing_key:
94
93
  specification_version: 4
95
- summary: Add color methods to String class
94
+ summary: Ruby gem for colorizing text using ANSI escape sequences.
96
95
  test_files:
97
96
  - test/test_colorize.rb