color_echo 2.0.4 → 3.0.0
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 +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +7 -404
- data/bin/colorecho +302 -77
- data/bin/lib/display.rb +118 -116
- data/lib/color_echo/const.rb +3 -3
- data/lib/color_echo/functions.rb +31 -26
- data/lib/color_echo/get.rb +2 -1
- data/lib/color_echo/internal.rb +64 -23
- data/lib/color_echo/module/textattr.rb +1 -1
- data/lib/color_echo/override.rb +10 -1
- data/lib/color_echo/variables.rb +14 -11
- metadata +7 -10
- data/README.ja.md +0 -405
- data/bin/color_echo +0 -260
data/bin/lib/display.rb
CHANGED
@@ -1,19 +1,36 @@
|
|
1
|
-
@
|
2
|
-
@
|
3
|
-
@
|
4
|
-
@
|
5
|
-
@
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
1
|
+
@padding = " " * 4
|
2
|
+
@header_s = %(-s, --symbol-list)
|
3
|
+
@explain_s = %(Shows symbol list that can to specify in foreground_color, background_color, text_attr.)
|
4
|
+
@header_l = %(-l, --index-list)
|
5
|
+
@explain_l = %(Shows color index list that can to specify in foreground_color, background_color.)
|
6
|
+
@header_p = %(-p, --pickup "pattern[,foreground_color[,background_color[,text_attribute]]]")
|
7
|
+
@explain_p = %(Decorates your specified pattern. You can use this option many times.)
|
8
|
+
@header_H = %(-H, --hightlight "foreground_color[,background_color[,text_attribute]]")
|
9
|
+
@explain_H = %(Highlight lines that match pattern which is specified by -p option.)
|
10
|
+
@header_f = %(-f, --fg color_name)
|
11
|
+
@explain_f = %(Specifies foreground color.)
|
12
|
+
@header_b = %(-b, --bg color_name)
|
13
|
+
@explain_b = %(Specifies background color.)
|
14
|
+
@header_t = %(-t, --tx text_attribute[,...])
|
15
|
+
@explain_t = %(Specifies background color.)
|
16
|
+
@header_w = %(-w, --watch)
|
17
|
+
@explain_w = %(Keeps wait for standard input.)
|
18
|
+
@header_stripe = %(--stripe)
|
19
|
+
@explain_stripe = %(Decorates on every other line.)
|
20
|
+
@header_r = %(-r, --refresh-match)
|
21
|
+
@explain_r = %(Tries to delete sequence code from input that matches -p option’s pattern)
|
22
|
+
@header_R = %(-R, --refresh)
|
23
|
+
@explain_R = %(Tries to delete sequence code from input.)
|
24
|
+
@header_c = %(-c file_name,...)
|
25
|
+
@explain_c = %(Reads options from your specify file. You can specify many files as -c foo,bar,baz.)
|
26
|
+
@header_n = %(-n)
|
10
27
|
@explain_n = %(Do not output the trailing newline.)
|
28
|
+
@header_e = %(-e)
|
11
29
|
@explain_e = %(Enable interpretation of line feed.)
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@padding = " " * 4
|
30
|
+
@header_v = %(-v)
|
31
|
+
@explain_v = %(Shows version of color_echo.)
|
32
|
+
@header_h = %(-h, --help)
|
33
|
+
@explain_h = %(Shows help message.)
|
17
34
|
@explain_usage = @padding * 2 + %(colorecho [options] message) + $/
|
18
35
|
@explain_usage += @padding * 2 + %(colorecho [options] < /path/to/file) + $/
|
19
36
|
@explain_usage += @padding * 2 + %(echo "message" | colorecho [options]) + $/
|
@@ -40,119 +57,104 @@ def usage
|
|
40
57
|
|
41
58
|
EOS
|
42
59
|
|
43
|
-
headers
|
44
|
-
headers_op = [
|
45
|
-
"-v:", "--symbol-list:", "--index-list:", "--pickup word [--pickup word ...]:", "--fg color_name:", "--bg color_name:",
|
46
|
-
"--tx text_attribute[,...]:", "--watch:", "--stripe:", %(--hightlight "foreground_color[,background_color[,text_attribute]]:"),
|
47
|
-
"--refresh:", "--refresh-pre-match:", "--help:", "-n:", "-e:"
|
48
|
-
]
|
60
|
+
headers = ["* Usage", "* Options", "* Example"]
|
49
61
|
CE.pickup(headers, :h_green)
|
50
|
-
CE.pickup(headers_op, :cyan)
|
51
62
|
|
52
63
|
puts @padding + "* Usage"
|
53
64
|
|
54
65
|
CE.ch :h_blue
|
55
|
-
puts @explain_usage + $/
|
66
|
+
puts @explain_usage + $/ * 2
|
56
67
|
CE.off :fg
|
57
68
|
|
69
|
+
headers_op = [
|
70
|
+
@header_l,
|
71
|
+
@header_p,
|
72
|
+
@header_H,
|
73
|
+
@header_f,
|
74
|
+
@header_b,
|
75
|
+
@header_t,
|
76
|
+
@header_w,
|
77
|
+
@header_n,
|
78
|
+
@header_e,
|
79
|
+
@header_h,
|
80
|
+
@header_stripe,
|
81
|
+
@header_r,
|
82
|
+
@header_R,
|
83
|
+
@header_c,
|
84
|
+
@header_v,
|
85
|
+
@header_s
|
86
|
+
]
|
87
|
+
CE.pickup(headers_op, :cyan)
|
88
|
+
|
58
89
|
puts @padding + "* Options"
|
59
90
|
|
60
|
-
puts @padding * 2 +
|
61
|
-
puts @padding * 3 + @explain_s
|
62
|
-
puts @padding * 3 + "short option is -s." + $/ + $/
|
91
|
+
puts @padding * 2 + @header_s
|
92
|
+
puts @padding * 3 + @explain_s + $/ * 2
|
63
93
|
|
64
|
-
puts @padding * 2 +
|
65
|
-
puts @padding * 3 + @explain_l
|
66
|
-
puts @padding * 3 + "short option is -l." + $/ + $/
|
67
|
-
|
68
|
-
puts @padding * 2 + "--pickup word [--pickup word ...]:"
|
69
|
-
puts @padding * 3 + @explain_p
|
70
|
-
puts @padding * 3 + "Regular expressions can be used; like that -> /^foo/i"
|
71
|
-
puts @padding * 3 + "short option is -p." + $/ + $/
|
72
|
-
|
73
|
-
puts @padding * 2 + %(--hightlight "foreground_color[,background_color[,text_attribute]]:")
|
74
|
-
puts @padding * 3 + @explain_H
|
75
|
-
puts @padding * 3 + %(example -> echo "some message" | colorecho -H "nil,gray" -p /some patturn/ -f h_yellow)
|
76
|
-
puts @padding * 3 + "short option is -H." + $/ + $/
|
77
|
-
|
78
|
-
puts @padding * 2 + "--fg color_name:"
|
79
|
-
puts @padding * 3 + @explain_f
|
80
|
-
puts @padding * 3 + "short option is -f." + $/ + $/
|
81
|
-
|
82
|
-
puts @padding * 2 + "--bg color_name:"
|
83
|
-
puts @padding * 3 + @explain_b
|
84
|
-
puts @padding * 3 + "short option is -b." + $/ + $/
|
85
|
-
|
86
|
-
puts @padding * 2 + "--tx text_attribute[,...]:"
|
87
|
-
puts @padding * 3 + @explain_t
|
88
|
-
puts @padding * 3 + "short option is -t." + $/ + $/
|
89
|
-
|
90
|
-
puts @padding * 2 + "--watch:"
|
91
|
-
puts @padding * 3 + @explain_w
|
92
|
-
puts @padding * 3 + "short option is -w." + $/ + $/
|
93
|
-
|
94
|
-
puts @padding * 2 + "--stripe:"
|
95
|
-
puts @padding * 3 + @explain_stripe + $/ + $/
|
96
|
-
|
97
|
-
puts @padding * 2 + "--refresh-pre-match:"
|
98
|
-
puts @padding * 3 + @explain_r
|
99
|
-
puts @padding * 3 + "If it matches, Try to remove sequence code from it."
|
100
|
-
puts @padding * 3 + "short option is -r." + $/ + $/
|
101
|
-
|
102
|
-
puts @padding * 2 + "--refresh:"
|
103
|
-
puts @padding * 3 + @explain_R
|
104
|
-
puts @padding * 3 + "short option is -R." + $/ + $/
|
105
|
-
|
106
|
-
puts @padding * 2 + "-n:"
|
107
|
-
puts @padding * 3 + @explain_n + $/ + $/
|
108
|
-
|
109
|
-
puts @padding * 2 + "-e:"
|
110
|
-
puts @padding * 3 + @explain_e + $/ + $/
|
111
|
-
|
112
|
-
puts @padding * 2 + "-v:"
|
113
|
-
puts @padding * 3 + @explain_v + $/ + $/
|
114
|
-
|
115
|
-
puts @padding * 2 + "--help:"
|
116
|
-
puts @padding * 3 + @explain_h
|
117
|
-
puts @padding * 3 + "short option is -h." + $/ + $/
|
118
|
-
|
119
|
-
puts @padding + "* Example"
|
120
|
-
|
121
|
-
CE.once.ch :h_magenta
|
122
|
-
puts @padding * 2 + %(* color_echo can to highlight even when you following the log file by tailf, tail -f.)
|
123
|
-
puts @padding * 3 + %(tailf /var/log/httpd/access_log | colorecho -w -p "127.0.0.1" -t bold)
|
124
|
-
puts @padding * 3 + %(tailf /var/log/php/php_error.log | colorecho -w -p "foo.php" -p "Fatal error:" -f h_blue) + $/ + $/
|
125
|
-
|
126
|
-
CE.once.ch :h_magenta
|
127
|
-
puts @padding * 2 + %(* color_echo is useful to read the access log, etc.)
|
128
|
-
puts @padding * 3 + %(cat /var/log/httpd/access_log | colorecho -p "Sun Jan 18" -f h_cyan -t underscore | less -R)
|
129
|
-
puts @padding * 3 + %(colorecho -p "Sun Jan 18" -f h_cyan -t underscore < /var/log/httpd/access_log | less -R)
|
130
|
-
puts @padding * 3 + %((colorecho -f cyan -p /\\\\s2..\\\\s/ | colorecho -f h_red -p /\\\\s5..\\\\s/ | less -R) < /var/log/httpd/access_log)
|
131
|
-
puts @padding * 3 + %(sed -n 1,1000p /var/log/httpd/access_log | colorecho -f cyan -p /\\\\s2..\\\\s/ | colorecho -f h_red -p /\\\\s5..\\\\s/ | less -R) + $/ + $/
|
132
|
-
|
133
|
-
CE.once.ch :h_magenta
|
134
|
-
puts @padding * 2 + %(* It is a simple to use.)
|
135
|
-
puts @padding * 3 + %(colorecho Hello\\!\\! -f h_white -b index199)
|
136
|
-
puts @padding * 3 + %(colorecho Hello\\!\\! -t blink,bold -f magenta) + $/ + $/
|
137
|
-
|
138
|
-
CE.once.ch :h_magenta
|
139
|
-
puts @padding * 2 + %(* color_echo can to receive the standard input.)
|
140
|
-
puts @padding * 3 + %(echo FooFoOfOO | colorecho -t reverse_video)
|
141
|
-
puts @padding * 3 + %(echo FooFoOfOO | colorecho -f index130 -p /foo$/i | colorecho -f index180 -p /^foo/i)
|
142
|
-
puts @padding * 3 + %(netstat -na | colorecho -p ":80" | colorecho -p "127.0.0.1" -f h_cyan) + $/ + $/
|
143
|
-
|
144
|
-
CE.once.ch :h_magenta
|
145
|
-
puts @padding * 2 + %(* color_echo can to decorate on every other line.)
|
146
|
-
puts @padding * 3 + %(colorecho -f gray -t bold --stripe < /path/to/file)
|
147
|
-
puts @padding * 3 + %(tailf /var/log/httpd/access_log | colorecho -w -f black -b index150 -t bold --stripe) + $/ + $/
|
94
|
+
puts @padding * 2 + @header_l
|
95
|
+
puts @padding * 3 + @explain_l + $/ * 2
|
148
96
|
|
149
|
-
|
150
|
-
puts @padding *
|
151
|
-
|
97
|
+
puts @padding * 2 + @header_p
|
98
|
+
puts @padding * 3 + @explain_p + $/ * 2
|
99
|
+
|
100
|
+
puts @padding * 2 + @header_H
|
101
|
+
puts @padding * 3 + @explain_H + $/ * 2
|
102
|
+
|
103
|
+
puts @padding * 2 + @header_f
|
104
|
+
puts @padding * 3 + @explain_f + $/ * 2
|
105
|
+
|
106
|
+
puts @padding * 2 + @header_b
|
107
|
+
puts @padding * 3 + @explain_b + $/ * 2
|
108
|
+
|
109
|
+
puts @padding * 2 + @header_t
|
110
|
+
puts @padding * 3 + @explain_t + $/ * 2
|
111
|
+
|
112
|
+
puts @padding * 2 + @header_w
|
113
|
+
puts @padding * 3 + @explain_w + $/ * 2
|
152
114
|
|
115
|
+
puts @padding * 2 + @header_stripe
|
116
|
+
puts @padding * 3 + @explain_stripe + $/ * 2
|
117
|
+
|
118
|
+
puts @padding * 2 + @header_r
|
119
|
+
puts @padding * 3 + @explain_r + $/ * 2
|
120
|
+
|
121
|
+
puts @padding * 2 + @header_R
|
122
|
+
puts @padding * 3 + @explain_R + $/ * 2
|
123
|
+
|
124
|
+
puts @padding * 2 + @header_c
|
125
|
+
puts @padding * 3 + @explain_c + $/ * 2
|
126
|
+
|
127
|
+
puts @padding * 2 + @header_n
|
128
|
+
puts @padding * 3 + @explain_n + $/ * 2
|
129
|
+
|
130
|
+
puts @padding * 2 + @header_e
|
131
|
+
puts @padding * 3 + @explain_e + $/ * 2
|
132
|
+
|
133
|
+
puts @padding * 2 + @header_v
|
134
|
+
puts @padding * 3 + @explain_v + $/ * 2
|
135
|
+
|
136
|
+
puts @padding * 2 + @header_h
|
137
|
+
puts @padding * 3 + @explain_h + $/ * 2
|
138
|
+
|
139
|
+
CE.once.rainbow
|
140
|
+
puts @padding * 2 + %(Let's enjoy colors!!) + $/ * 2
|
153
141
|
exit 0
|
154
142
|
end
|
155
143
|
|
144
|
+
def warn_display(msg, header="Runtime")
|
145
|
+
warn(%(#{header} Warning:))
|
146
|
+
warn(" " * 4 + msg + $/ * 2)
|
147
|
+
end
|
148
|
+
|
149
|
+
def error_display(msg, header="Runtime")
|
150
|
+
msgls = msg.is_a?(Array) ? msg : [msg]
|
151
|
+
warn(%(#{header} Error:))
|
152
|
+
msgls.each do |msg|
|
153
|
+
warn(" " * 4 + msg + $/)
|
154
|
+
end
|
155
|
+
exit 1
|
156
|
+
end
|
157
|
+
|
156
158
|
# TODO need pager like 'less'?
|
157
159
|
def display_color_index
|
158
160
|
require_color_echo_get
|
@@ -174,7 +176,7 @@ def display_color_index
|
|
174
176
|
mes += " " * 3
|
175
177
|
|
176
178
|
if num % 8 == 0
|
177
|
-
mes += $/
|
179
|
+
mes += $/ * 2
|
178
180
|
mes += @padding if num != 256
|
179
181
|
end
|
180
182
|
end
|
@@ -206,7 +208,7 @@ def display_symbol_list
|
|
206
208
|
]
|
207
209
|
symbols_text_attr = [
|
208
210
|
:bold,
|
209
|
-
:
|
211
|
+
:underline,
|
210
212
|
:blink,
|
211
213
|
:reverse_video,
|
212
214
|
:concealed
|
@@ -222,7 +224,7 @@ def display_symbol_list
|
|
222
224
|
|
223
225
|
header_colors = "* foreground or background colors"
|
224
226
|
header_text_attrs = "* text attributes"
|
225
|
-
CE.pickup([header_colors, header_text_attrs], :cyan, nil, [:
|
227
|
+
CE.pickup([header_colors, header_text_attrs], :cyan, nil, [:underline, :bold])
|
226
228
|
|
227
229
|
puts @padding + header_colors
|
228
230
|
symbols_color.each do |color_name|
|
@@ -233,7 +235,7 @@ def display_symbol_list
|
|
233
235
|
end
|
234
236
|
|
235
237
|
CE.off [:bg, :fg]
|
236
|
-
print $/
|
238
|
+
print $/ * 2
|
237
239
|
|
238
240
|
puts @padding + header_text_attrs
|
239
241
|
symbols_text_attr.each do |tx_name|
|
data/lib/color_echo/const.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module CE
|
2
2
|
LIBS_NAME = "color_echo"
|
3
|
-
VERSION = "
|
4
|
-
SUMMARY = "
|
5
|
-
|
3
|
+
VERSION = "3.0.0"
|
4
|
+
SUMMARY = "Decorates command line output with ANSI escape sequence."
|
5
|
+
HOMEPAGE = "http://colorecho.net"
|
6
6
|
DESCRIPTION = <<EOS
|
7
7
|
#{SUMMARY}
|
8
8
|
Text that output by "print, puts, p" method is decorated.
|
data/lib/color_echo/functions.rb
CHANGED
@@ -22,7 +22,7 @@ module CE
|
|
22
22
|
reset_bg
|
23
23
|
reset_tx
|
24
24
|
reset_pickup
|
25
|
-
|
25
|
+
reset_highlight
|
26
26
|
reset_rainbow
|
27
27
|
when :fg
|
28
28
|
reset_fg
|
@@ -32,8 +32,8 @@ module CE
|
|
32
32
|
reset_tx
|
33
33
|
when :pickup
|
34
34
|
reset_pickup
|
35
|
-
when :
|
36
|
-
|
35
|
+
when :highlight
|
36
|
+
reset_highlight
|
37
37
|
when :rainbow
|
38
38
|
reset_rainbow
|
39
39
|
end
|
@@ -108,7 +108,7 @@ module CE
|
|
108
108
|
# @param symbol bg
|
109
109
|
# @param symbol tx
|
110
110
|
# @return self
|
111
|
-
def pickup(target, fg=:
|
111
|
+
def pickup(target, fg=:cyan, bg=nil, *txs)
|
112
112
|
key = target.object_id.to_s
|
113
113
|
@@pickup_list[key] = {}
|
114
114
|
|
@@ -139,7 +139,9 @@ module CE
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
-
@@pickup_list[key][:code]
|
142
|
+
@@pickup_list[key][:code] = code_fg + code_bg + code_tx
|
143
|
+
@@pickup_list[key][:index] = @@cnt_pickups
|
144
|
+
@@cnt_pickups += 1
|
143
145
|
|
144
146
|
return self
|
145
147
|
end
|
@@ -155,49 +157,39 @@ module CE
|
|
155
157
|
|
156
158
|
# change hit lines decoration
|
157
159
|
# @return void
|
158
|
-
def
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
@@code_hitline_fg_color = ""
|
163
|
-
end
|
164
|
-
|
165
|
-
if bg.instance_of?(Symbol)
|
166
|
-
@@code_hitline_bg_color = convert_to_code("BackGround", bg)
|
167
|
-
else
|
168
|
-
@@code_hitline_bg_color = ""
|
169
|
-
end
|
160
|
+
def highlight(fg=nil, bg=nil, *txs)
|
161
|
+
fg = convert_to_code("ForeGround", fg)
|
162
|
+
bg = convert_to_code("BackGround", bg)
|
163
|
+
tx = ""
|
170
164
|
|
171
165
|
if txs.size > 0
|
166
|
+
# if text attribute has input as array
|
172
167
|
txs = txs[0] if txs[0].instance_of?(Array)
|
168
|
+
|
173
169
|
txs.each do |name|
|
174
170
|
next if !name.is_a?(Symbol)
|
175
|
-
|
171
|
+
tx += convert_to_code("TextAttr", name)
|
176
172
|
end
|
177
173
|
end
|
174
|
+
@@code_highlights << fg + bg + tx
|
178
175
|
|
179
176
|
return self
|
180
177
|
end
|
181
178
|
|
182
|
-
# get escape sequence code of that hit record line
|
183
|
-
# @return string
|
184
|
-
def get_hitline_code
|
185
|
-
return @@code_hitline_fg_color + @@code_hitline_bg_color + @@code_hitline_text_attr
|
186
|
-
end
|
187
|
-
|
188
179
|
# get decorated text
|
189
180
|
# require "color_echo/get"
|
190
181
|
# @param string text
|
191
182
|
def get(text)
|
192
183
|
if @@allow_output
|
193
|
-
|
184
|
+
caller()[0] =~ /(.*?):(\d+)/
|
185
|
+
warn (%([WARNING] #{$1} #{$2}: You can't call CE.get. You must to read like -> require 'color_echo/get' ))
|
194
186
|
return text
|
195
187
|
end
|
196
188
|
|
197
189
|
if !text.is_a?(String)
|
198
190
|
text = text.to_s
|
199
191
|
end
|
200
|
-
|
192
|
+
|
201
193
|
@@task.call(text)
|
202
194
|
end
|
203
195
|
|
@@ -221,6 +213,19 @@ module CE
|
|
221
213
|
return self
|
222
214
|
end
|
223
215
|
|
216
|
+
# CE.get will be stateful
|
217
|
+
# @return self
|
218
|
+
def stateful
|
219
|
+
@@stateful_getter = true
|
220
|
+
return self
|
221
|
+
end
|
222
|
+
|
223
|
+
# CE.get will be stateless
|
224
|
+
def stateless
|
225
|
+
@@stateful_getter = false
|
226
|
+
return self
|
227
|
+
end
|
228
|
+
|
224
229
|
# method alias
|
225
230
|
alias_method :off, :reset
|
226
231
|
alias_method :disable, :reset
|
data/lib/color_echo/get.rb
CHANGED
data/lib/color_echo/internal.rb
CHANGED
@@ -42,15 +42,14 @@ module CE
|
|
42
42
|
# @return self
|
43
43
|
def reset_pickup
|
44
44
|
@@pickup_list = {}
|
45
|
+
@@cnt_pickups = 0
|
45
46
|
return self
|
46
47
|
end
|
47
48
|
|
48
|
-
# reset
|
49
|
+
# reset highlight code
|
49
50
|
# @return self
|
50
|
-
def
|
51
|
-
@@
|
52
|
-
@@code_hitline_fg_color = ""
|
53
|
-
@@code_hitline_text_attr = ""
|
51
|
+
def reset_highlight
|
52
|
+
@@code_highlights = []
|
54
53
|
return self
|
55
54
|
end
|
56
55
|
|
@@ -75,16 +74,31 @@ module CE
|
|
75
74
|
|
76
75
|
# return start escape sequence code
|
77
76
|
# @return string
|
78
|
-
def get_start_code
|
77
|
+
def get_start_code
|
79
78
|
if @@rainbow
|
80
79
|
return @@code_rainbow
|
81
|
-
elsif type == :hitline
|
82
|
-
return @@code_hitline_fg_color + @@code_hitline_bg_color + @@code_hitline_text_attr
|
83
80
|
else
|
84
81
|
return @@code_fg_color + @@code_bg_color + @@code_text_attr
|
85
82
|
end
|
86
83
|
end
|
87
84
|
|
85
|
+
# return start escape sequence code
|
86
|
+
# @param int index
|
87
|
+
# @return string
|
88
|
+
def get_highlight_code(index=0)
|
89
|
+
if @@code_highlights[index] == nil
|
90
|
+
code = @@code_highlights[0]
|
91
|
+
if code == nil
|
92
|
+
# e.g. no specify any -H option
|
93
|
+
return ""
|
94
|
+
else
|
95
|
+
return code
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
return @@code_highlights[index]
|
100
|
+
end
|
101
|
+
|
88
102
|
# @return String
|
89
103
|
def get_reset_code
|
90
104
|
return self::Off::ALL
|
@@ -148,37 +162,64 @@ module CE
|
|
148
162
|
text = cleanup_text(text)
|
149
163
|
end
|
150
164
|
|
151
|
-
|
165
|
+
match_pattern_keys = []
|
166
|
+
# repeat as called pickup method
|
152
167
|
@@pickup_list.each_pair do |key, hash|
|
153
168
|
patterns = hash[:patterns]
|
154
169
|
code_pickup = hash[:code]
|
170
|
+
index = hash[:index]
|
155
171
|
|
156
|
-
# repeat
|
172
|
+
# repeat as patterns
|
157
173
|
patterns.each do |pattern|
|
158
|
-
# pattern is Regexp
|
159
174
|
if pattern.is_a?(Regexp)
|
160
|
-
|
175
|
+
# pattern is Regexp
|
176
|
+
if (pattern =~ text && !match_pattern_keys.index(index))
|
177
|
+
match_pattern_keys << index
|
178
|
+
end
|
179
|
+
|
180
|
+
if match_pattern_keys.size > 1
|
181
|
+
code_highlight = get_highlight_code(0)
|
182
|
+
else
|
183
|
+
code_highlight = get_highlight_code(index)
|
184
|
+
end
|
185
|
+
|
161
186
|
# global match
|
187
|
+
after_text = ""
|
162
188
|
(text.scan(pattern)).size.times do
|
163
189
|
pattern =~ text
|
164
|
-
after_text += $` + get_reset_code + code_pickup + $& + get_reset_code + get_start_code +
|
190
|
+
after_text += $` + get_reset_code + code_pickup + $& + get_reset_code + get_start_code + code_highlight
|
165
191
|
text = $'
|
166
192
|
end
|
167
|
-
text
|
168
|
-
is_match = ($& != nil) if (!is_match)
|
193
|
+
text = after_text + text
|
169
194
|
|
170
|
-
# pattern is String
|
171
195
|
else
|
172
|
-
|
173
|
-
|
196
|
+
# pattern is String
|
197
|
+
if (text.index(pattern) != nil && !match_pattern_keys.index(index))
|
198
|
+
match_pattern_keys << index
|
199
|
+
end
|
200
|
+
|
201
|
+
if match_pattern_keys.size > 1
|
202
|
+
code_highlight = get_highlight_code(0)
|
203
|
+
else
|
204
|
+
code_highlight = get_highlight_code(index)
|
205
|
+
end
|
206
|
+
|
207
|
+
text.gsub!(pattern, get_reset_code + code_pickup + pattern + get_reset_code + get_start_code + code_highlight)
|
174
208
|
end
|
175
209
|
end
|
176
210
|
end
|
177
211
|
|
178
|
-
if
|
179
|
-
|
180
|
-
|
181
|
-
text
|
212
|
+
if match_pattern_keys.size == 0
|
213
|
+
# not match
|
214
|
+
text = orgtext if @@refresh_pre_match
|
215
|
+
return text
|
216
|
+
end
|
217
|
+
|
218
|
+
if match_pattern_keys.size == 1
|
219
|
+
text = get_highlight_code(match_pattern_keys[0]) + text + get_reset_code
|
220
|
+
else
|
221
|
+
# many pattern matched, use first -H option
|
222
|
+
text = get_highlight_code(0) + text + get_reset_code
|
182
223
|
end
|
183
224
|
|
184
225
|
return text
|
@@ -189,7 +230,7 @@ module CE
|
|
189
230
|
# @param symbol name
|
190
231
|
# @return string
|
191
232
|
def convert_to_code(module_name, name)
|
192
|
-
return "" if (name
|
233
|
+
return "" if (!name.is_a?(Symbol) || name == :nil)
|
193
234
|
|
194
235
|
begin
|
195
236
|
cname = name.to_s.swapcase
|