colorize 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,4 +1,8 @@
1
- == 0.5.7 / 2000-11-24
1
+ == 0.5.8 / 2009-12-02
2
+ * code cleanups
3
+ * removed 'ruby -w' warnings
4
+
5
+ == 0.5.7 / 2009-11-24
2
6
  * moved to github/gemcutter
3
7
  * 1.9 compatibile
4
8
 
data/README.rdoc CHANGED
@@ -19,13 +19,13 @@ Ruby string class extension. It add some methods to set color, background color
19
19
  puts "This is blue".colorize( :blue )
20
20
  puts "This is light blue".colorize( :light_blue )
21
21
  puts "This is also blue".colorize( :color => :blue )
22
- puts "This is blue with red background".colorize( :color => :light_blue, :background => :red )
23
- puts "This is blue with red background".colorize( :light_blue ).colorize( :background => :red )
22
+ puts "This is light blue with red background".colorize( :color => :light_blue, :background => :red )
23
+ puts "This is light blue with red background".colorize( :light_blue ).colorize( :background => :red )
24
24
  puts "This is blue text on red".blue.on_red
25
25
  puts "This is red on blue".colorize( :red ).on_blue
26
- puts "This is uncolorized".blue.on_red.uncolorize
27
26
  puts "This is red on blue and underline".colorize( :red ).on_blue.underline
28
27
  puts "This is blue text on red".blue.on_red.blink
28
+ puts "This is uncolorized".blue.on_red.uncolorize
29
29
 
30
30
  Class methods:
31
31
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.7
1
+ 0.5.8
data/colorize.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{colorize}
8
- s.version = "0.5.7"
8
+ s.version = "0.5.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["fazibear"]
12
- s.date = %q{2009-11-24}
12
+ s.date = %q{2009-12-02}
13
13
  s.description = %q{Ruby string class extension. It add some methods to set color, background color and text effect on console easier. Uses ANSI escape sequences.}
14
14
  s.email = %q{fazibear@gmail.com}
15
15
  s.extra_rdoc_files = [
data/lib/colorize.rb CHANGED
@@ -55,7 +55,7 @@ class String
55
55
  nil
56
56
  end
57
57
  end
58
-
58
+
59
59
  public
60
60
 
61
61
  #
@@ -66,21 +66,21 @@ class String
66
66
  # puts "This is blue".colorize( :blue )
67
67
  # puts "This is light blue".colorize( :light_blue )
68
68
  # puts "This is also blue".colorize( :color => :blue )
69
- # puts "This is blue with red background".colorize( :color => :light_blue, :background => :red )
70
- # puts "This is blue with red background".colorize( :light_blue ).colorize( :background => :red )
69
+ # puts "This is light blue with red background".colorize( :color => :light_blue, :background => :red )
70
+ # puts "This is light blue with red background".colorize( :light_blue ).colorize( :background => :red )
71
71
  # puts "This is blue text on red".blue.on_red
72
72
  # puts "This is red on blue".colorize( :red ).on_blue
73
73
  # puts "This is red on blue and underline".colorize( :red ).on_blue.underline
74
74
  # puts "This is blue text on red".blue.on_red.blink
75
+ # puts "This is uncolorized".blue.on_red.uncolorize
75
76
  #
76
77
  def colorize( params )
77
-
78
78
  return self unless STDOUT.isatty
79
79
 
80
80
  begin
81
- require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
81
+ require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
82
82
  rescue LoadError
83
- raise 'You must gem install win32console to use color on Windows'
83
+ raise 'You must gem install win32console to use colorize on Windows'
84
84
  end
85
85
 
86
86
  color_parameters = {}
@@ -93,58 +93,58 @@ class String
93
93
  color_parameters[:color] = COLORS[params]
94
94
  end
95
95
 
96
- color_parameters[:color] ||= @color || 9
97
- color_parameters[:background] ||= @background || 9
98
- color_parameters[:mode] ||= @mode || 0
96
+ color_parameters[:color] ||= @color ||= COLORS[:default]
97
+ color_parameters[:background] ||= @background ||= COLORS[:default]
98
+ color_parameters[:mode] ||= @mode ||= MODES[:default]
99
99
 
100
- color_parameters[:uncolorized] ||= @uncolorized || self.dup
100
+ color_parameters[:uncolorized] ||= @uncolorized ||= self.dup
101
101
 
102
102
  # calculate bright mode
103
103
  color_parameters[:color] += 50 if color_parameters[:color] > 10
104
104
 
105
105
  color_parameters[:background] += 50 if color_parameters[:background] > 10
106
106
 
107
- return "\033[#{color_parameters[:mode]};#{color_parameters[:color]+30};#{color_parameters[:background]+40}m#{color_parameters[:uncolorized]}\033[0m".set_color_parameters( color_parameters )
107
+ "\033[#{color_parameters[:mode]};#{color_parameters[:color]+30};#{color_parameters[:background]+40}m#{color_parameters[:uncolorized]}\033[0m".set_color_parameters( color_parameters )
108
108
  end
109
109
 
110
-
111
110
  #
112
111
  # Return uncolorized string
113
112
  #
114
113
  def uncolorize
115
- return @uncolorized || self
114
+ @uncolorized || self
116
115
  end
117
116
 
118
117
  #
119
118
  # Return true if sting is colorized
120
119
  #
121
120
  def colorized?
122
- return !@uncolorized.nil?
121
+ !defined?(@uncolorized).nil?
123
122
  end
124
123
 
125
124
  #
126
125
  # Make some color and on_color methods
127
126
  #
128
127
  COLORS.each_key do | key |
129
- eval <<-"end_eval"
130
- def #{key.to_s}
131
- return self.colorize( :color => :#{key.to_s} )
132
- end
133
- def on_#{key.to_s}
134
- return self.colorize( :background => :#{key.to_s} )
135
- end
136
- end_eval
128
+ next if key == :default
129
+
130
+ define_method key do
131
+ self.colorize( :color => key )
132
+ end
133
+
134
+ define_method "on_#{key}" do
135
+ self.colorize( :background => key )
136
+ end
137
137
  end
138
138
 
139
139
  #
140
140
  # Methods for modes
141
141
  #
142
142
  MODES.each_key do | key |
143
- eval <<-"end_eval"
144
- def #{key.to_s}
145
- return self.colorize( :mode => :#{key.to_s} )
146
- end
147
- end_eval
143
+ next if key == :default
144
+
145
+ define_method key do
146
+ self.colorize( :mode => key )
147
+ end
148
148
  end
149
149
 
150
150
  class << self
@@ -185,7 +185,7 @@ class String
185
185
  String.colors.reverse.each_with_index do | back, index |
186
186
  puts "#{"|".rjust(txt.length)*(size-index)} < #{back}"
187
187
  end
188
+ ""
188
189
  end
189
190
  end
190
- puts
191
191
  end
@@ -1,11 +1,49 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestColorize < Test::Unit::TestCase
4
+ def test_blue_symbol
5
+ assert "This is blue".colorize(:blue) == "\e[0;34;49mThis is blue\e[0m"
6
+ end
7
+
8
+ def test_blue_hash
9
+ assert "This is also blue".colorize( :color => :blue) == "\e[0;34;49mThis is also blue\e[0m"
10
+ end
11
+
12
+ def test_light_blue_symbol
13
+ assert "This is light blue".colorize(:light_blue) == "\e[0;94;49mThis is light blue\e[0m"
14
+ end
15
+
16
+ def test_light_blue_with_red_background_hash
17
+ assert "This is light blue with red background".colorize( :color => :light_blue, :background => :red ) == "\e[0;94;41mThis is light blue with red background\e[0m"
18
+ end
19
+
20
+ def test_light_blue_with_red_background_symbol_and_hash
21
+ assert "This is light blue with red background".colorize( :light_blue ).colorize( :background => :red ) == "\e[0;144;41mThis is light blue with red background\e[0m"
22
+ end
23
+
24
+ def test_blue_with_red_background_method
25
+ assert "This is blue text on red".blue.on_red == "\e[0;34;41mThis is blue text on red\e[0m"
26
+ end
27
+
28
+ def test_red_with_blue_background_symbol_and_method
29
+ assert "This is red on blue".colorize( :red ).on_blue == "\e[0;31;44mThis is red on blue\e[0m"
30
+ end
31
+
32
+ def test_red_with_blue_background_and_underline_sumbol_and_methods
33
+ assert "This is red on blue and underline".colorize( :red ).on_blue.underline == "\e[4;31;44mThis is red on blue and underline\e[0m"
34
+ end
35
+
36
+ def test_blue_with_red_background_and_blink_methods
37
+ assert "This is blue text on red".blue.on_red.blink == "\e[5;34;41mThis is blue text on red\e[0m"
38
+ end
4
39
 
5
- def setup
40
+ def test_uncolorize
41
+ assert "This is uncolorized".blue.on_red.uncolorize == "This is uncolorized"
6
42
  end
7
-
8
- def test_truth
9
- assert true
43
+
44
+ def test_colorized?
45
+ assert "Red".red.colorized? == true
46
+ assert "Blue".colorized? == false
47
+ assert "Green".blue.green.uncolorize.colorized? == false
10
48
  end
11
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - fazibear
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-24 00:00:00 +01:00
12
+ date: 2009-12-02 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15