coloring 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ #### 0.1.0 (2012-08-31)
2
+
3
+ * Added 256 colors suport
4
+ * Input params now can be Hash
5
+ * Added CLI to show all avaliable colors
6
+ * Added tests
7
+
8
+ #### 0.0.5 (2012-08-24)
9
+
10
+ * Added class method view_avaliable
11
+ * Method set_param now protected
12
+ * Added some tests
13
+
14
+ #### 0.0.4 (2012-08-22)
15
+
16
+ * Added specs
17
+ * Added full README
18
+ * Added this CHANGELOG file
19
+
20
+ #### 0.0.3 (2012-08-22)
21
+
22
+ * Start release
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## About
2
2
 
3
- Extension for Ruby string class. Extension add methods for coloring text or background in Terminal. Also add some text effects.
3
+ Extension for Ruby string class. Extension add methods for coloring text or background in Terminal. Also add some text effects. Support 256 colors.
4
4
 
5
5
  ### Features
6
6
 
@@ -12,9 +12,9 @@ Extension for Ruby string class. Extension add methods for coloring text or back
12
12
  * String.negative
13
13
  * String.hide
14
14
 
15
- Also avaliable class method to view all methods.
15
+ Also avaliable class CLI to view all methods and colors.
16
16
 
17
- Coloring::view_avaliable
17
+ $ coloring
18
18
 
19
19
  ### Installation
20
20
 
@@ -36,23 +36,33 @@ Add line:
36
36
 
37
37
  require 'coloring'
38
38
 
39
- For base colors:
39
+ For base methods:
40
40
 
41
41
  puts "Hello, World!".green
42
- puts "Hello, World!".coloring(32)
42
+ puts "Hello, World!".underline
43
+
44
+ For call coloring method:
45
+
43
46
  puts "Hello, World!".coloring(:green)
44
47
  puts "Hello, World!".coloring("green")
45
48
 
46
49
  For more params:
47
50
 
48
- puts "Hello,World!".green.underline
51
+ puts "Hello, World!".green.underline
49
52
  puts "Hello, World".green.on_red.underline
50
53
  puts "Hello, World!".coloring [:green, :on_red, :underline]
51
54
  puts "Hello, World!".coloring ["green", "on_red", "underline"]
52
- puts "Hello,World!".coloring [32, 41, 4]
53
- puts "Hello,World!".coloring(32).on_red
54
- puts "Hello,World!".coloring([:green, :underline]).on_red
55
+ puts "Hello, World!".coloring(:green).on_red
56
+ puts "Hello, World!".coloring([:green, :underline]).on_red
57
+
58
+ For 256 colors ( use CLI to show avaliable colors ):
55
59
 
60
+ puts "Hello, World!".coloring(:color => :green, :background = > :yellow)
61
+ puts "Hello, World!".coloring(:color => "green", :background => "yellow")
62
+ puts "Hello, World!".coloring(color: "green", background: "yellow")
63
+ puts "Hello, World!".coloring(color: 211, background: 35)
64
+ puts "Hello, World!".coloring(color: 211).on_green
65
+
56
66
  ### Contributing
57
67
 
58
68
  1. Fork it
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'coloring'
4
+
5
+ Coloring::gamma
6
+
@@ -34,6 +34,8 @@ module Coloring
34
34
  define_method( effect ) { self.coloring( value ) }
35
35
  end
36
36
 
37
+ protected
38
+
37
39
  # Set effect value from SGR Hash
38
40
 
39
41
  def set_param ( param )
@@ -46,14 +48,38 @@ module Coloring
46
48
  param = SGRPARAMS[param]
47
49
  end
48
50
  param
51
+
52
+ end
53
+
54
+ # Set support Hash input (support 256 colors)
55
+
56
+ def input_options ( params )
57
+
58
+ set = lambda { |e| e = e.instance_of?(Fixnum) ? e : self.set_param(e)-30 }
59
+
60
+ options = []
61
+
62
+ if params.has_key?(:background)
63
+ background = set.call(params[:background])
64
+ options << 48 << 5 << background
65
+ end
66
+ if params.has_key?(:color)
67
+ color = set.call(params[:color])
68
+ options << 38 << 5 << color
69
+ end
70
+
71
+ options
72
+
49
73
  end
50
74
 
51
- protected :set_param
75
+ public
52
76
 
53
77
  # Output method
54
78
 
55
79
  def coloring ( params )
56
80
 
81
+ params = self.input_options( params ) if params.instance_of?(Hash)
82
+
57
83
  if params.instance_of?(Array)
58
84
  all_params = params.map! { |elem| elem = self.set_param(elem).to_s }.join ";"
59
85
  else
@@ -66,12 +92,50 @@ module Coloring
66
92
 
67
93
  # Class method
68
94
 
69
- class << self
70
-
71
- def view_avaliable
72
- SGRPARAMS.each { |key, value| puts "#{key}".coloring(value) + " > String.#{key}" }
95
+ class << self
96
+
97
+ def gamma
98
+
99
+ puts "All base methods:".on_yellow + "\n\n"
100
+
101
+ SGRPARAMS.each {|key, value| puts "#{key}".coloring(value) + " method: #{key}"}
102
+
103
+ puts "\n"
104
+ puts "System colors for xterm-256color:".on_yellow + "\n\n"
105
+
106
+ 0.upto(7) do |i|
107
+ print "\033[48;5;#{i}m #{i} \033[000m"
108
+ end
109
+
110
+ puts "\n"
111
+
112
+ 8.upto(15) do |i|
113
+ print "\033[48;5;#{i}m #{i} \033[000m"
114
+ end
115
+
116
+ puts "\n\n"
117
+
118
+ 0.upto(5) do |g|
119
+ 0.upto(5) do |r|
120
+ 0.upto(5) do |b|
121
+ color = 16 + r*36 + g*6 + b
122
+ print "\033[48;5;#{color}m #{color}"
123
+ end
124
+ print "\033[0m "
125
+ end
126
+ print "\n"
127
+ end
128
+
129
+ puts "\n"
130
+ puts "Grayscale ramp:".on_yellow + "\n\n"
131
+
132
+ 232.upto(255) do |i|
133
+ print "\033[48;5;#{i}m #{i} \033[000m"
134
+ end
135
+
136
+ puts "\n"
73
137
  end
74
-
138
+
75
139
  end
76
140
 
77
141
  end
@@ -1,3 +1,3 @@
1
1
  module Coloring
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,10 +8,6 @@ describe Coloring do
8
8
 
9
9
  describe "all base methods" do
10
10
 
11
- it "should return value" do
12
- @sample.green.should_not be_nil
13
- end
14
-
15
11
  it "should return right class" do
16
12
  @sample.red.class.should == String
17
13
  end
@@ -28,20 +24,32 @@ describe Coloring do
28
24
 
29
25
  describe "method with params" do
30
26
 
31
- it "should return value" do
32
- @sample.coloring(:green).should_not be_nil
27
+ it "should raise error if no arguments" do
28
+ expect { @sample.coloring }.to raise_error
29
+ end
30
+
31
+ it "should raise error if wrong parameter for method" do
32
+ expect { @sample.coloring(:red, :on_blue) }.to raise_error
33
33
  end
34
34
 
35
35
  it "should return right class" do
36
36
  @sample.coloring(:green).class.should == String
37
37
  end
38
38
 
39
- it "should raise error if wrong parameter for method" do
40
- expect { @sample.coloring(:red, :on_blue) }.to raise_error
39
+ it "should return right content (input params: Symbol)" do
40
+ @sample.coloring(:green).should eq("\e[32mHello, World!\e[0m")
41
41
  end
42
42
 
43
- it "should return right content" do
44
- @sample.coloring(:green).should eq("\e[32mHello, World!\e[0m")
43
+ it "should return right content (input params: String)" do
44
+ @sample.coloring("green").should eq("\e[32mHello, World!\e[0m")
45
+ end
46
+
47
+ it "should return right content (input params: Hash)" do
48
+ @sample.coloring(:color => :green).should eq("\e[38;5;2mHello, World!\e[0m")
49
+ end
50
+
51
+ it "should return right content (input params > 1: Hash)" do
52
+ @sample.coloring(:color => :green, :background => :red).should eq("\e[48;5;1;38;5;2mHello, World!\e[0m")
45
53
  end
46
54
 
47
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coloring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-24 00:00:00.000000000 Z
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -30,16 +30,18 @@ dependencies:
30
30
  description: Adds methods for coloring and styling text for class String
31
31
  email:
32
32
  - oabogatenko@gmail.com
33
- executables: []
33
+ executables:
34
+ - coloring
34
35
  extensions: []
35
36
  extra_rdoc_files: []
36
37
  files:
37
38
  - .gitignore
38
- - CHANGELOG.rdoc
39
+ - CHANGELOG.md
39
40
  - Gemfile
40
41
  - LICENSE
41
42
  - README.md
42
43
  - Rakefile
44
+ - bin/coloring
43
45
  - coloring.gemspec
44
46
  - lib/coloring.rb
45
47
  - lib/coloring/version.rb
@@ -1,12 +0,0 @@
1
- == 0.0.5 (2012-08-24)
2
- * Added class method view_avaliable
3
- * Method set_param now protected
4
- * Added some tests
5
-
6
- == 0.0.4 (2012-08-22)
7
- * Added specs
8
- * Added full README
9
- * Added this CHANGELOG file
10
-
11
- == 0.0.3 (2012-08-22)
12
- * Start release