color_echo 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 922b6df5b99b54e8fc52dd2716fa5acb778b2704
4
- data.tar.gz: 8c39228ed3879d2091f0bf2925374bcae33ae83f
3
+ metadata.gz: 20f0a1335862325dff3433310f6d1b45280f35a7
4
+ data.tar.gz: 2c01eb7e252a8a2d7040ce0cfd62e45094ca9b3a
5
5
  SHA512:
6
- metadata.gz: 62f7a9e07a0ce3773ec8d2f98c5413aba5af2546521ef5738fce07a7e2e2a0ac017085b794dfd62193f3c17580fa31cabde99a2abd6f6866a618c859c16cf78e
7
- data.tar.gz: fa98969050f46c0acba35c77daa25cc7a4ebe638f058c386696c193651a871712d85b4b71d02ff52fb041fec4308dd26e699d1135cb14b189880058c34b392ae
6
+ metadata.gz: 3b582122725922b6118c7b08cb9e0dc9d6fb70c248dc2ba66e733e715a034f12f5d4b1451d857fe6e93fddb73e258e712b525baee82d7c1fa38f1383cd2d5e69
7
+ data.tar.gz: ce0641f425d46376657872e46c21e4505576f8bd4d530109ffb0633515e3d6c93cf73fb4334f8d8b1aa9cd501a921e3577823d3b68a33b260430cb6d3c1401c0
data/README.md CHANGED
@@ -3,7 +3,7 @@ To add color to the command line output.
3
3
  This Library will extend the Kernel module's functions(#print, #puts, #p).
4
4
  required StringIO.
5
5
 
6
- Version: 0.1.1
6
+ Version: 0.2.1
7
7
  Compliant Rubys Version: 1.9.3, 2.0.0, 2.1.0 (for Linux)
8
8
  License: MIT
9
9
  Gems repository: http://rubygems.org/gems/color_echo
@@ -76,9 +76,9 @@ Change collectively.
76
76
  This method is available in version 0.1.0 on and after.
77
77
  ex.) CE.ch :white, :green
78
78
 
79
- #### CE.disable
79
+ #### CE.reset
80
80
  Reset to set the color sequence.
81
- Alias is, CE::off, CE::reset
81
+ Alias is, CE::off, CE::disable
82
82
  This method alias is available in version 0.1.0 on and after.
83
83
 
84
84
  #### CE.unuse
@@ -0,0 +1,7 @@
1
+ module CE
2
+ alias_method :off, :reset
3
+ alias_method :disable, :reset
4
+ alias_method :fg, :ch_fg
5
+ alias_method :bg, :ch_bg
6
+ alias_method :tx, :ch_tx
7
+ end
@@ -0,0 +1,12 @@
1
+ module CE
2
+ module BackGround
3
+ BLACK = 40
4
+ RED = 41
5
+ GREEN = 42
6
+ YELLOW = 43
7
+ BLUE = 44
8
+ MAGENTA = 45
9
+ CYAN = 46
10
+ WHITE = 47
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module CE
2
+ CODE_RESET = "\e[0m"
3
+ end
@@ -0,0 +1,12 @@
1
+ module CE
2
+ module ForeGround
3
+ BLACK = 30
4
+ RED = 31
5
+ GREEN = 32
6
+ YELLOW = 33
7
+ BLUE = 34
8
+ MAGENTA = 35
9
+ CYAN = 36
10
+ WHITE = 37
11
+ end
12
+ end
@@ -0,0 +1,132 @@
1
+ module CE
2
+ def available?
3
+ return @@enable && @@isset
4
+ end
5
+
6
+ def isset?
7
+ return @@isset
8
+ end
9
+
10
+ def enable?
11
+ return @@enable
12
+ end
13
+
14
+ def unuse
15
+ @@enable = false
16
+ end
17
+
18
+ def reset
19
+ @@isset = false
20
+ @@rainbow = false
21
+ @@code_bg_color = ""
22
+ @@code_fg_color = ""
23
+ @@code_text_attr = ""
24
+ end
25
+
26
+ def ch_fg(name)
27
+ return nil if !name.instance_of?(Symbol)
28
+ @@isset = true if !@@isset
29
+ @@rainbow = false if @@rainbow
30
+ @@code_fg_color = convert_to_code("ForeGround", name)
31
+ end
32
+
33
+ def ch_bg(name)
34
+ return nil if !name.instance_of?(Symbol)
35
+ @@isset = true if !@@isset
36
+ @@rainbow = false if @@rainbow
37
+ @@code_bg_color = convert_to_code("BackGround", name)
38
+ end
39
+
40
+ def ch_tx(name)
41
+ return nil if !name.instance_of?(Symbol)
42
+ @@isset = true if !@@isset
43
+ @@rainbow = false if @@rainbow
44
+ @@code_text_attr = convert_to_code("TextAttr", name)
45
+ end
46
+
47
+ def ch(fg, bg=nil, tx=nil)
48
+ ch_fg(fg)
49
+ ch_bg(bg)
50
+ ch_tx(tx)
51
+ end
52
+
53
+ def get_start_code
54
+ return @@code_fg_color + @@code_bg_color + @@code_text_attr
55
+ end
56
+
57
+ def get_reset_code
58
+ return self::CODE_RESET
59
+ end
60
+
61
+ # add reset & start code to line feed code
62
+ def add_reset_line_feed(input)
63
+ input.gsub!(/#{$/}/, CE::get_reset_code + $/ + CE::get_start_code)
64
+ input += CE::get_reset_code
65
+ return input
66
+ end
67
+
68
+ def rainbow
69
+ @@isset = true if !@@isset
70
+ @@rainbow = true
71
+ end
72
+
73
+ def add_rainbow(text)
74
+ cnt = 0
75
+ output = ""
76
+ text.each_char do |char|
77
+ output += $/ if char == $/
78
+
79
+ case cnt
80
+ when 0
81
+ output += "\e[31m" + char + "\e[0m"
82
+ when 1
83
+ output += "\e[32m" + char + "\e[0m"
84
+ when 2
85
+ output += "\e[33m" + char + "\e[0m"
86
+ when 3
87
+ output += "\e[34m" + char + "\e[0m"
88
+ when 4
89
+ output += "\e[35m" + char + "\e[0m"
90
+ when 5
91
+ output += "\e[36m" + char + "\e[0m"
92
+ when 6
93
+ output += "\e[37m" + char + "\e[0m"
94
+ end
95
+ cnt += 1
96
+ cnt = 0 if cnt >= 7
97
+ end
98
+ return output
99
+ end
100
+
101
+ def convert_to_code(module_name, name)
102
+ begin
103
+ code = eval(%{#{module_name}::#{name.to_s.swapcase!}})
104
+ rescue NameError
105
+ raise(NameError ,%{:#{name} is not defined! Please check reference.})
106
+ end
107
+ return "\e[#{code}m"
108
+ end
109
+
110
+ def task
111
+ return @@task
112
+ end
113
+
114
+ require_relative "alias_method.rb"
115
+
116
+ module_function :available?,
117
+ :isset?,
118
+ :enable?,
119
+ :unuse,
120
+ :reset, :off, :disable,
121
+ :ch_fg, :fg,
122
+ :ch_bg, :bg,
123
+ :ch_tx, :tx,
124
+ :ch,
125
+ :get_start_code,
126
+ :get_reset_code,
127
+ :add_reset_line_feed,
128
+ :add_rainbow,
129
+ :rainbow,
130
+ :convert_to_code,
131
+ :task
132
+ end
@@ -0,0 +1,12 @@
1
+ # override Kernel methods
2
+ def print(*arg)
3
+ CE.task.call(*arg)
4
+ end
5
+
6
+ def p(*arg)
7
+ CE.task.call(*arg)
8
+ end
9
+
10
+ def puts(*arg)
11
+ CE.task.call(*arg)
12
+ end
@@ -0,0 +1,10 @@
1
+ module CE
2
+ module TextAttr
3
+ OFF = 0
4
+ BOLD = 1
5
+ UNDERSCORE = 4
6
+ BLINK = 5
7
+ REVERSE_VIDEO = 7
8
+ CONCEALED = 8
9
+ end
10
+ end
@@ -0,0 +1,45 @@
1
+ module CE
2
+ @@enable = true
3
+ @@isset = false
4
+ @@code_bg_color = ""
5
+ @@code_fg_color = ""
6
+ @@code_text_attr = ""
7
+ @@rainbow = false
8
+
9
+ @@print = method :print
10
+ @@p = method :p
11
+ @@puts = method :puts
12
+
13
+ @@task = lambda do |*arg|
14
+ if available?
15
+ if @@rainbow && arg.first.instance_of?(String)
16
+ arg = add_rainbow(arg.first)
17
+
18
+ # call original method
19
+ eval("@@#{caller_locations(2).first.label}").call(arg)
20
+
21
+ else
22
+ # change output destination to StringIO Object
23
+ strio = StringIO.new
24
+ $stdout = strio
25
+
26
+ # output color sequence
27
+ $stdout.print get_start_code
28
+
29
+ # call original method
30
+ eval("@@#{caller_locations(2).first.label}").call(arg)
31
+
32
+ # change output destination to STDOUT
33
+ $stdout = STDOUT
34
+
35
+ # output to STDOUT
36
+ $stdout.print add_reset_line_feed(strio.string)
37
+ end
38
+
39
+ # no available "color echo"
40
+ else
41
+ # call original method
42
+ eval("@@#{caller_locations(2).first.label}").call(arg)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module CE
2
+ VERSION = "0.2.1"
3
+ end
data/lib/color_echo.rb CHANGED
@@ -3,234 +3,17 @@
3
3
  # To add color to the command line output.
4
4
  # This Library will extend the Kernel module's functions(#print, #puts, #p).
5
5
  # @autor: Kazuya Hotta (nyanko)
6
- #
7
- require "stringio"
8
-
9
- module CE
10
- VERSION = "0.2.0"
11
- CODE_RESET = "\e[0m"
12
-
13
- @@enable = true
14
- @@isset = false
15
- @@code_bg_color = ""
16
- @@code_fg_color = ""
17
- @@code_text_attr = ""
18
- @@rainbow = false
19
-
20
- @@print = method :print
21
- @@p = method :p
22
- @@puts = method :puts
23
-
24
- @@task = lambda do |*arg|
25
- if available?
26
- if @@rainbow && arg.first.instance_of?(String)
27
- arg = add_rainbow(arg.first)
28
-
29
- # call original method
30
- eval("@@#{caller_locations(2).first.label}").call(arg)
31
-
32
- else
33
- # change output destination to StringIO Object
34
- strio = StringIO.new
35
- $stdout = strio
36
-
37
- # output color sequence
38
- $stdout.print get_start_code
39
-
40
- # call original method
41
- eval("@@#{caller_locations(2).first.label}").call(arg)
42
-
43
- # change output destination to STDOUT
44
- $stdout = STDOUT
45
-
46
- # output to STDOUT
47
- $stdout.print add_reset_line_feed(strio.string)
48
- end
49
-
50
- # no available "color echo"
51
- else
52
- # call original method
53
- eval("@@#{caller_locations(2).first.label}").call(arg)
54
- end
55
- end
56
-
57
- module ForeGround
58
- BLACK = 30
59
- RED = 31
60
- GREEN = 32
61
- YELLOW = 33
62
- BLUE = 34
63
- MAGENTA = 35
64
- CYAN = 36
65
- WHITE = 37
66
- end
67
-
68
- module BackGround
69
- BLACK = 40
70
- RED = 41
71
- GREEN = 42
72
- YELLOW = 43
73
- BLUE = 44
74
- MAGENTA = 45
75
- CYAN = 46
76
- WHITE = 47
77
- end
78
-
79
- module TextAttr
80
- OFF = 0
81
- BOLD = 1
82
- UNDERSCORE = 4
83
- BLINK = 5
84
- REVERSE_VIDEO = 7
85
- CONCEALED = 8
86
- end
87
-
88
- public
89
- def available?
90
- return @@enable && @@isset
91
- end
92
-
93
- def isset?
94
- return @@isset
95
- end
96
-
97
- def enable?
98
- return @@enable
99
- end
100
-
101
- def unuse
102
- @@enable = false
103
- end
104
-
105
- def reset
106
- @@isset = false
107
- @@rainbow = false
108
- @@code_bg_color = ""
109
- @@code_fg_color = ""
110
- @@code_text_attr = ""
111
- end
112
-
113
- def ch_fg(name)
114
- return nil if !name.instance_of?(Symbol)
115
- @@isset = true if !@@isset
116
- @@rainbow = false if @@rainbow
117
- @@code_fg_color = convert_to_code("ForeGround", name)
118
- end
119
-
120
- def ch_bg(name)
121
- return nil if !name.instance_of?(Symbol)
122
- @@isset = true if !@@isset
123
- @@rainbow = false if @@rainbow
124
- @@code_bg_color = convert_to_code("BackGround", name)
125
- end
126
-
127
- def ch_tx(name)
128
- return nil if !name.instance_of?(Symbol)
129
- @@isset = true if !@@isset
130
- @@rainbow = false if @@rainbow
131
- @@code_text_attr = convert_to_code("TextAttr", name)
132
- end
133
-
134
- def ch(fg, bg=nil, tx=nil)
135
- ch_fg(fg)
136
- ch_bg(bg)
137
- ch_tx(tx)
138
- end
139
-
140
- def get_start_code
141
- return @@code_fg_color + @@code_bg_color + @@code_text_attr
142
- end
143
-
144
- def get_reset_code
145
- return self::CODE_RESET
146
- end
147
-
148
- # add reset & start code to line feed code
149
- def add_reset_line_feed(input)
150
- input.gsub!(/#{$/}/, CE::get_reset_code + $/ + CE::get_start_code)
151
- input += CE::get_reset_code
152
- return input
153
- end
154
-
155
- def rainbow
156
- @@isset = true if !@@isset
157
- @@rainbow = true
158
- end
159
-
160
- def add_rainbow(text)
161
- cnt = 0
162
- output = ""
163
- text.each_char do |char|
164
- output += $/ if char == $/
165
-
166
- case cnt
167
- when 0
168
- output += "\e[31m" + char + "\e[0m"
169
- when 1
170
- output += "\e[32m" + char + "\e[0m"
171
- when 2
172
- output += "\e[33m" + char + "\e[0m"
173
- when 3
174
- output += "\e[34m" + char + "\e[0m"
175
- when 4
176
- output += "\e[35m" + char + "\e[0m"
177
- when 5
178
- output += "\e[36m" + char + "\e[0m"
179
- when 6
180
- output += "\e[37m" + char + "\e[0m"
181
- end
182
- cnt += 1
183
- cnt = 0 if cnt >= 7
184
- end
185
- return output
186
- end
187
-
188
- def convert_to_code(module_name, name)
189
- begin
190
- code = eval(%{#{module_name}::#{name.to_s.swapcase!}})
191
- rescue NameError
192
- raise(NameError ,%{:#{name} is not defined! Please check reference.})
193
- end
194
- return "\e[#{code}m"
195
- end
196
-
197
- def task
198
- return @@task
199
- end
200
-
201
- alias_method :off, :reset
202
- alias_method :disable, :reset
203
- alias_method :fg, :ch_fg
204
- alias_method :bg, :ch_bg
205
- alias_method :tx, :ch_tx
206
-
207
- module_function :available?,
208
- :isset?,
209
- :enable?,
210
- :unuse,
211
- :reset, :off, :disable,
212
- :ch_fg, :fg,
213
- :ch_bg, :bg,
214
- :ch_tx, :tx,
215
- :ch,
216
- :get_start_code,
217
- :get_reset_code,
218
- :add_reset_line_feed,
219
- :add_rainbow,
220
- :rainbow,
221
- :convert_to_code,
222
- :task
6
+ begin
7
+ require "stringio"
8
+ rescue LoadError
9
+ warn "color_echo required 'stringio.'"
223
10
  end
224
11
 
225
- # override Kernel methods
226
- def print(*arg)
227
- CE.task.call(*arg)
228
- end
229
-
230
- def p(*arg)
231
- CE.task.call(*arg)
232
- end
233
-
234
- def puts(*arg)
235
- CE.task.call(*arg)
236
- end
12
+ require_relative "color_echo/version.rb"
13
+ require_relative "color_echo/const.rb"
14
+ require_relative "color_echo/variables.rb"
15
+ require_relative "color_echo/background.module.rb"
16
+ require_relative "color_echo/foreground.module.rb"
17
+ require_relative "color_echo/textattr.module.rb"
18
+ require_relative "color_echo/module_functions.rb"
19
+ require_relative "color_echo/override.rb"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_echo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nyanko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-26 00:00:00.000000000 Z
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'To add color to the command line output.This Library will extend the
14
14
  Kernel module''s functions(#print, #puts, #p). required StringIO.'
@@ -21,6 +21,15 @@ files:
21
21
  - LICENSE.txt
22
22
  - README.md
23
23
  - lib/color_echo.rb
24
+ - lib/color_echo/alias_method.rb
25
+ - lib/color_echo/background.module.rb
26
+ - lib/color_echo/const.rb
27
+ - lib/color_echo/foreground.module.rb
28
+ - lib/color_echo/module_functions.rb
29
+ - lib/color_echo/override.rb
30
+ - lib/color_echo/textattr.module.rb
31
+ - lib/color_echo/variables.rb
32
+ - lib/color_echo/version.rb
24
33
  homepage: https://github.com/khotta/color_echo
25
34
  licenses:
26
35
  - MIT