color_echo 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -43
- data/bin/color_echo +45 -49
- data/lib/color_echo/const.rb +1 -1
- data/lib/color_echo/module_functions.rb +78 -15
- data/lib/color_echo/variables.rb +8 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51b73486f80605fc2b29e9a87129e3f528222599
|
4
|
+
data.tar.gz: a1fcdaa02b03ee665075e7768fa05931f5a9216f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3640bb11d8f5477ab2cc93b809e9f691e42ff28d9d174a7d2dab546d96cad801aacecb33e18b3faf668d29b9c4f93ca658896d0d5fb223527db30c205585928c
|
7
|
+
data.tar.gz: b180b3d77e7df8420c8ad493768407b6031161722c8af5efb60d50ea43e4eb9a2fe6600f104701ad98396c0c3d09103f88a4db07a7ccbd469cbc6876db6973b3
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Decorate the command line output with ANSI escape sequence.
|
|
3
3
|
String that is output by "print, puts, p" method is decorated.
|
4
4
|
It is also can to decorate only your specified words!
|
5
5
|
|
6
|
-
Version: 0.
|
6
|
+
Version: 0.8.0
|
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
|
@@ -25,7 +25,23 @@ ex.) CE.ch :index197, :index230
|
|
25
25
|
![screen shot](/images/color_index.png)
|
26
26
|
![screen shot](/images/color_index2.png)
|
27
27
|
|
28
|
-
|
28
|
+
## You can to decorate your specified words!
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
CE.fg(:h_cyan).pickup("color_echo", :h_white, :red, :underscore).pickup("COLOR_ECHO", :h_yellow)
|
32
|
+
|
33
|
+
puts <<EOS
|
34
|
+
xxxxxxxxxxxxxxxxxcolor_echoxxxxxxxxxxxxxxxxxxxxxxxx
|
35
|
+
xxxxcolor_echoxxxxxxxCOLOR_ECHOxxxxxxxxxxxxxxxxxxxx
|
36
|
+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
37
|
+
xxxxxxxxxxxxxxxxxcolor_echoxxxxxxxxxxcolor_echoxxxx
|
38
|
+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
39
|
+
EOS
|
40
|
+
```
|
41
|
+
![screen shot](/images/pickup1.png)
|
42
|
+
|
43
|
+
|
44
|
+
## You can run on the command line
|
29
45
|
<pre>
|
30
46
|
* Usage
|
31
47
|
color_echo [options]
|
@@ -43,14 +59,26 @@ ex.) CE.ch :index197, :index230
|
|
43
59
|
If your server using the rbenv, You have to do `rbenv rehash`.
|
44
60
|
</pre>
|
45
61
|
|
62
|
+
|
46
63
|
## module functions
|
47
|
-
|
64
|
+
|
65
|
+
#### CE.pickup(target, foreground=:red, backgruond=nil, text_attribute)
|
66
|
+
To decorate the words that specfied in the String or Regexp or Array of them.
|
67
|
+
If state of enable rainbow mode, This feature is disabled.
|
68
|
+
- Parameter target -> string|regexp or array of them
|
69
|
+
- Parameter foreground -> symbol|nil
|
70
|
+
- Parameter background -> symbol|nil
|
71
|
+
- Parameter text_attribute -> symbol or array of them
|
72
|
+
- Return -> self
|
73
|
+
|
74
|
+
|
75
|
+
#### CE.ch_fg(foreground)
|
48
76
|
Change the foreground color to the your specified color.
|
49
77
|
- Alias -> fg
|
50
|
-
- Parameter -> symbol
|
78
|
+
- Parameter foreground -> symbol
|
51
79
|
- Return -> self
|
52
80
|
|
53
|
-
* symbol list:
|
81
|
+
* symbol list of foreground:
|
54
82
|
* black
|
55
83
|
* red
|
56
84
|
* green
|
@@ -74,13 +102,13 @@ ex.) CE.ch_fg :red #=> foreground color will be changed red
|
|
74
102
|
|
75
103
|
|
76
104
|
|
77
|
-
#### CE.ch_bg
|
105
|
+
#### CE.ch_bg(background)
|
78
106
|
Change the background color to the your specified color.
|
79
107
|
- Alias -> bg
|
80
|
-
- Parameter -> symbol
|
108
|
+
- Parameter background -> symbol
|
81
109
|
- Return -> self
|
82
110
|
|
83
|
-
* symbol list:
|
111
|
+
* symbol list of background:
|
84
112
|
* black
|
85
113
|
* red
|
86
114
|
* green
|
@@ -103,13 +131,13 @@ ex.) CE.ch_bg :white #=> background color will be changed white
|
|
103
131
|
|
104
132
|
|
105
133
|
|
106
|
-
#### CE.ch_tx
|
134
|
+
#### CE.ch_tx(text_attribute)
|
107
135
|
Change the text attribute to the your specified decoration.
|
108
136
|
- Alias -> tx
|
109
|
-
- Parameter -> symbol
|
137
|
+
- Parameter attribute -> symbol or array of them
|
110
138
|
- Return -> self
|
111
139
|
|
112
|
-
* symbol list:
|
140
|
+
* symbol list of text attribute:
|
113
141
|
* bold
|
114
142
|
* underscore
|
115
143
|
* blink
|
@@ -121,35 +149,41 @@ ex.) CE.ch_tx :blink #=> text blink on
|
|
121
149
|
|
122
150
|
#### CE.ch foreground [,background [,text_attribute]]
|
123
151
|
Change collectively.
|
124
|
-
- Parameter foreground ->
|
125
|
-
- Parameter background ->
|
126
|
-
- Parameter text_attribute ->
|
152
|
+
- Parameter foreground -> symbol|nil
|
153
|
+
- Parameter background -> symbol|nil
|
154
|
+
- Parameter text_attribute -> symbol or array of them
|
127
155
|
- Return -> self
|
128
156
|
|
129
157
|
ex.) CE.ch :white, :green
|
130
158
|
ex.) CE.ch :h_red, nil, :blink
|
131
159
|
|
132
|
-
|
160
|
+
|
161
|
+
#### CE.reset(scope=:all)
|
133
162
|
Reset to set the escape sequence.
|
134
163
|
- Alias -> off, disable
|
135
|
-
- Parameter
|
164
|
+
- Parameter scope -> symbol or array of them
|
136
165
|
- Return -> self
|
137
166
|
|
138
|
-
ex.) CE.reset
|
139
|
-
ex.) CE.reset :
|
140
|
-
ex.) CE.reset :
|
141
|
-
ex.) CE.reset
|
167
|
+
ex.) CE.reset #=> reset all of the set escape sequence.
|
168
|
+
ex.) CE.reset :fg #=> foreground color will be reset.
|
169
|
+
ex.) CE.reset :bg #=> background color will be reset.
|
170
|
+
ex.) CE.reset :tx #=> text attribute will be reset.
|
171
|
+
ex.) CE.reset :pickup #=> pickup text will be reset.
|
172
|
+
ex.) CE.reset :rainbow #=> rainbow mode will be reset and swich off.
|
173
|
+
ex.) CE.reset [:fg. :tx] #=> foreground color and ext attribute will be reset.
|
142
174
|
|
143
175
|
|
144
176
|
#### CE.once
|
145
177
|
Reset automatically after once output.
|
146
178
|
- Return -> self
|
147
179
|
|
180
|
+
|
148
181
|
#### CE.times(cnt)
|
149
182
|
Reset automatically after cnt times output.
|
150
183
|
- Parameter cnt -> Integer
|
151
184
|
- Return -> self
|
152
185
|
|
186
|
+
|
153
187
|
```ruby
|
154
188
|
CE.once.ch :h_yellow, :h_red, :underscore
|
155
189
|
puts "decorated"
|
@@ -173,29 +207,6 @@ Force ignore the function of this library.
|
|
173
207
|
Text color will change to rainbow color.
|
174
208
|
|
175
209
|
|
176
|
-
## You can to decorate your specified words!
|
177
|
-
|
178
|
-
#### CE.pickup(target, foreground=:red, backgruond=nil, *textattr)
|
179
|
-
To decorate the words that specfied in the String or Regexp or Array of them.
|
180
|
-
If state of enable rainbow mode, This feature is disabled.
|
181
|
-
- Parameter target -> String|Regexp|Array
|
182
|
-
- Parameter foreground -> Symbol or nil
|
183
|
-
- Parameter background -> Symbol or nil
|
184
|
-
- Parameter text_attribute -> Symbol
|
185
|
-
- Return -> self
|
186
|
-
|
187
|
-
```ruby
|
188
|
-
CE.fg(:h_cyan).pickup("color_echo", :h_white, :red, :underscore).pickup("COLOR_ECHO", :h_yellow)
|
189
|
-
|
190
|
-
puts <<EOS
|
191
|
-
xxxxxxxxxxxxxxxxxcolor_echoxxxxxxxxxxxxxxxxxxxxxxxx
|
192
|
-
xxxxcolor_echoxxxxxxxCOLOR_ECHOxxxxxxxxxxxxxxxxxxxx
|
193
|
-
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
194
|
-
xxxxxxxxxxxxxxxxxcolor_echoxxxxxxxxxxcolor_echoxxxx
|
195
|
-
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
196
|
-
EOS
|
197
|
-
```
|
198
|
-
![screen shot](/images/pickup1.png)
|
199
210
|
|
200
211
|
### Example
|
201
212
|
```ruby
|
@@ -283,6 +294,10 @@ puts "Disable rainbow mode."
|
|
283
294
|
![screen shot](/images/screenshot.png)
|
284
295
|
|
285
296
|
## Release Note
|
297
|
+
* v0.8.0, 2014-01-14
|
298
|
+
* Changed for the specified arguments of reset method.
|
299
|
+
* Fixed small bugs.
|
300
|
+
|
286
301
|
* v0.7.0, 2014-01-08
|
287
302
|
* Added new method -> pickup
|
288
303
|
* Added new symbol that can to specify in reset method of first parameter -> CE.reset(:pickup)
|
data/bin/color_echo
CHANGED
@@ -3,59 +3,35 @@ require "color_echo"
|
|
3
3
|
#require_relative "../lib/color_echo.rb"
|
4
4
|
|
5
5
|
def usage
|
6
|
-
CE.ch :yellow
|
7
|
-
puts
|
6
|
+
CE.once.ch :yellow
|
7
|
+
puts <<-EOS
|
8
8
|
#{CE::LIBS_NAME} - #{CE::SUMMARY}
|
9
9
|
VERSION: #{CE::VERSION}
|
10
10
|
README: #{CE::DOCS_PAGE}
|
11
11
|
|
12
|
-
EOS
|
12
|
+
EOS
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
padding = " " * 4
|
15
|
+
headers = ["* Usage", "* Options"]
|
16
|
+
headers_op = ["-v:", "--symbol_list, -s", "--index_list, -l"]
|
17
|
+
CE.pickup(headers, :cyan)
|
18
|
+
CE.pickup(headers_op, :h_green)
|
18
19
|
|
19
|
-
|
20
|
-
puts <<EOS
|
21
|
-
color_echo [-h] [options]
|
22
|
-
|
23
|
-
EOS
|
24
|
-
|
25
|
-
CE.once.ch :cyan
|
26
|
-
puts <<EOS
|
27
|
-
* Options
|
28
|
-
EOS
|
29
|
-
|
30
|
-
CE.once.ch :h_green
|
31
|
-
puts <<EOS
|
32
|
-
-v:
|
33
|
-
EOS
|
34
|
-
|
35
|
-
puts <<EOS
|
36
|
-
Display version of color_echo.
|
37
|
-
|
38
|
-
EOS
|
39
|
-
|
40
|
-
CE.once.ch :h_green
|
41
|
-
puts <<EOS
|
42
|
-
--symbol_list, -s
|
43
|
-
EOS
|
44
|
-
|
45
|
-
puts <<EOS
|
46
|
-
Display symbol list that can to specify.
|
47
|
-
EOS
|
20
|
+
puts padding + "* Usage"
|
48
21
|
|
49
|
-
CE.once.ch :
|
50
|
-
puts
|
22
|
+
CE.once.ch :h_blue
|
23
|
+
puts padding * 2 + "color_echo [-h] [options]" + $/ + $/
|
51
24
|
|
52
|
-
|
53
|
-
EOS
|
25
|
+
puts padding + "* Options"
|
54
26
|
|
55
|
-
puts
|
56
|
-
|
27
|
+
puts padding + "-v:"
|
28
|
+
puts padding * 2 + "Display version of color_echo." + $/ + $/
|
57
29
|
|
58
|
-
|
30
|
+
puts padding + "--symbol_list, -s"
|
31
|
+
puts padding * 2 + "Display symbol list that can to specify." + $/ + $/
|
32
|
+
|
33
|
+
puts padding + "--index_list, -l"
|
34
|
+
puts padding * 2 + "Display color index list that can to specify." + $/ + $/
|
59
35
|
|
60
36
|
exit
|
61
37
|
end
|
@@ -88,7 +64,7 @@ def display_color_index
|
|
88
64
|
end
|
89
65
|
|
90
66
|
def display_symbol_list
|
91
|
-
|
67
|
+
symbols_color = [
|
92
68
|
:black,
|
93
69
|
:gray,
|
94
70
|
:red,
|
@@ -104,10 +80,17 @@ def display_symbol_list
|
|
104
80
|
:cyan,
|
105
81
|
:h_cyan,
|
106
82
|
:white,
|
107
|
-
:h_white
|
83
|
+
:h_white
|
84
|
+
]
|
85
|
+
symbols_text_attr = [
|
86
|
+
:bold,
|
87
|
+
:underscore,
|
88
|
+
:blink,
|
89
|
+
:reverse_video,
|
90
|
+
:concealed
|
108
91
|
]
|
109
92
|
|
110
|
-
CE.rainbow
|
93
|
+
CE.times(3).rainbow
|
111
94
|
cnt = 60
|
112
95
|
padding = " " * 2
|
113
96
|
mes = "OK, Let me check color name list... :)"
|
@@ -115,14 +98,27 @@ def display_symbol_list
|
|
115
98
|
puts padding + " " * ((cnt - mes.size)/2) + mes
|
116
99
|
puts padding + "-" * cnt
|
117
100
|
|
118
|
-
|
101
|
+
header_colors = "* foreground or background colors"
|
102
|
+
header_text_attrs = "* text attributes"
|
103
|
+
CE.pickup([header_colors, header_text_attrs], :cyan, nil, [:underscore, :bold])
|
104
|
+
|
105
|
+
puts padding + header_colors
|
106
|
+
symbols_color.each do |color_name|
|
119
107
|
CE.off(:bg).fg color_name
|
120
|
-
print "#{padding}:#{color_name}" + " " * (11 - color_name.to_s.size)
|
108
|
+
print "#{padding*2}:#{color_name}" + " " * (11 - color_name.to_s.size)
|
121
109
|
CE.bg color_name
|
122
110
|
puts color_name.to_s + " " * (30 - color_name.to_s.size)
|
123
111
|
end
|
124
112
|
|
125
|
-
CE.off
|
113
|
+
CE.off [:bg, :fg]
|
114
|
+
print $/ + $/
|
115
|
+
|
116
|
+
puts padding + header_text_attrs
|
117
|
+
symbols_text_attr.each do |tx_name|
|
118
|
+
CE.off(:tx).tx tx_name
|
119
|
+
puts "#{padding*2}:#{tx_name}" + " " * (30 - tx_name.to_s.size)
|
120
|
+
end
|
121
|
+
|
126
122
|
print $/
|
127
123
|
end
|
128
124
|
|
data/lib/color_echo/const.rb
CHANGED
@@ -24,26 +24,83 @@ module CE
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# reset code
|
27
|
+
# @param scope symbol|array
|
27
28
|
# @return self
|
28
|
-
def reset(
|
29
|
-
if
|
30
|
-
|
29
|
+
def reset(scope=:all)
|
30
|
+
if scope.is_a?(Array)
|
31
|
+
scopes = scope
|
32
|
+
else
|
33
|
+
scopes = [scope]
|
34
|
+
end
|
31
35
|
|
32
|
-
|
33
|
-
|
36
|
+
scopes.each do |scope|
|
37
|
+
case scope
|
38
|
+
when :all
|
39
|
+
reset_fg
|
40
|
+
reset_bg
|
41
|
+
reset_tx
|
42
|
+
reset_pickup
|
43
|
+
reset_rainbow
|
44
|
+
when :fg
|
45
|
+
reset_fg
|
46
|
+
when :bg
|
47
|
+
reset_bg
|
48
|
+
when :tx
|
49
|
+
reset_tx
|
50
|
+
when :pickup
|
51
|
+
reset_pickup
|
52
|
+
when :rainbow
|
53
|
+
reset_rainbow
|
54
|
+
end
|
55
|
+
end
|
34
56
|
|
35
|
-
|
36
|
-
|
57
|
+
return self
|
58
|
+
end
|
37
59
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
60
|
+
# reset foreground code
|
61
|
+
# @return self
|
62
|
+
def reset_fg
|
63
|
+
@@code_fg_color = ""
|
64
|
+
return self
|
65
|
+
end
|
66
|
+
|
67
|
+
# reset background code
|
68
|
+
# @return self
|
69
|
+
def reset_bg
|
70
|
+
@@code_bg_color = ""
|
71
|
+
return self
|
72
|
+
end
|
73
|
+
|
74
|
+
# reset text attr code
|
75
|
+
# @return self
|
76
|
+
def reset_tx
|
77
|
+
@@code_text_attr = ""
|
78
|
+
return self
|
79
|
+
end
|
80
|
+
|
81
|
+
# reset pickup code
|
82
|
+
# @return self
|
83
|
+
def reset_pickup
|
84
|
+
@@pickup_list = {}
|
85
|
+
return self
|
86
|
+
end
|
46
87
|
|
88
|
+
# reset and off raubow mode
|
89
|
+
# @return self
|
90
|
+
def reset_rainbow
|
91
|
+
@@code_rainbow = ""
|
92
|
+
@@rainbow = false
|
93
|
+
return self
|
94
|
+
end
|
95
|
+
|
96
|
+
# reset all state of code
|
97
|
+
# @return self
|
98
|
+
def reset_all
|
99
|
+
reset_fg
|
100
|
+
reset_bg
|
101
|
+
reset_tx
|
102
|
+
reset_pickup
|
103
|
+
reset_rainbow
|
47
104
|
return self
|
48
105
|
end
|
49
106
|
|
@@ -288,6 +345,12 @@ module CE
|
|
288
345
|
:enable?,
|
289
346
|
:unuse,
|
290
347
|
:reset,
|
348
|
+
:reset_fg,
|
349
|
+
:reset_bg,
|
350
|
+
:reset_tx,
|
351
|
+
:reset_pickup,
|
352
|
+
:reset_rainbow,
|
353
|
+
:reset_all,
|
291
354
|
:off,
|
292
355
|
:disable,
|
293
356
|
:times,
|
data/lib/color_echo/variables.rb
CHANGED
@@ -25,6 +25,8 @@ module CE
|
|
25
25
|
# change output destination to STDOUT
|
26
26
|
$stdout = STDOUT
|
27
27
|
|
28
|
+
#is_hit_pickup = false
|
29
|
+
|
28
30
|
# output to STDOUT
|
29
31
|
if @@rainbow
|
30
32
|
output = add_rainbow(strio.string)
|
@@ -33,7 +35,9 @@ module CE
|
|
33
35
|
|
34
36
|
# decorate pickup
|
35
37
|
if @@pickup_list.size > 0
|
38
|
+
#before_output = String.new(output)
|
36
39
|
output = add_pickup_code(output)
|
40
|
+
#is_hit_pickup = before_output != output
|
37
41
|
end
|
38
42
|
|
39
43
|
# add start code in haed
|
@@ -48,7 +52,10 @@ module CE
|
|
48
52
|
# auto off
|
49
53
|
if @@cnt_limit > 0
|
50
54
|
@@cnt_limit -= 1
|
51
|
-
|
55
|
+
# to reset
|
56
|
+
if @@cnt_limit == 0
|
57
|
+
reset [:fg, :bg, :tx, :rainbow]
|
58
|
+
end
|
52
59
|
end
|
53
60
|
|
54
61
|
# no available "color echo"
|
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.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khotta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Decorate the command line output with ANSI escape sequence.
|
@@ -36,8 +36,11 @@ homepage: https://github.com/khotta/color_echo
|
|
36
36
|
licenses:
|
37
37
|
- MIT
|
38
38
|
metadata: {}
|
39
|
-
post_install_message:
|
40
|
-
|
39
|
+
post_install_message: |2+
|
40
|
+
|
41
|
+
Thank you for installing! =(^x^=
|
42
|
+
See also https://github.com/khotta/color_echo
|
43
|
+
|
41
44
|
rdoc_options: []
|
42
45
|
require_paths:
|
43
46
|
- lib
|