color_echo 2.0.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module CE
2
2
  module TextAttr
3
3
  BOLD = "\033[1m"
4
- UNDERSCORE = "\033[4m"
4
+ UNDERLINE = "\033[4m"
5
5
  BLINK = "\033[5m"
6
6
  REVERSE_VIDEO = "\033[7m"
7
7
  CONCEALED = "\033[8m"
@@ -2,7 +2,7 @@ module CE
2
2
  @@allow_output = true
3
3
  end
4
4
 
5
- # override Kernel methods
5
+ # override Kernel module functions
6
6
  def print(*arg)
7
7
  CE.task.call(*arg)
8
8
  end
@@ -14,3 +14,12 @@ end
14
14
  def puts(*arg)
15
15
  CE.task.call(*arg)
16
16
  end
17
+
18
+ # TODO
19
+ #def printf(*arg)
20
+ # CE.task.call(*arg)
21
+ #end
22
+
23
+ #def putc(*arg)
24
+ # CE.task.call(*arg)
25
+ #end
@@ -8,12 +8,14 @@ module CE
8
8
  @@code_bg_color = ""
9
9
  @@code_fg_color = ""
10
10
  @@code_text_attr = ""
11
- @@code_hitline_bg_color = ""
12
- @@code_hitline_fg_color = ""
13
- @@code_hitline_text_attr = ""
11
+ @@code_highlights = []
14
12
  @@code_rainbow = ""
13
+ # count number for times method
15
14
  @@cnt_limit = 0
16
15
  @@pickup_list = {}
16
+ # how much pattern having?
17
+ @@cnt_pickups = 0
18
+ @@stateful_getter = false
17
19
 
18
20
  @@print = method :print
19
21
  @@p = method :p
@@ -39,8 +41,6 @@ module CE
39
41
  # change output destination to STDOUT
40
42
  $stdout = STDOUT
41
43
 
42
- #is_hit_pickup = false
43
-
44
44
  # get output text
45
45
  if @@rainbow
46
46
  output = add_rainbow(strio.string)
@@ -52,12 +52,10 @@ module CE
52
52
 
53
53
  # decorate pickup
54
54
  if @@pickup_list.size > 0
55
- #before_output = String.new(output)
56
55
  output = add_pickup_code(output)
57
- #is_hit_pickup = before_output != output
58
56
  end
59
57
 
60
- # add start code in haed
58
+ # add start code in header
61
59
  output = get_start_code + output
62
60
 
63
61
  # add reset code in front of line feed
@@ -72,11 +70,11 @@ module CE
72
70
  @@cnt_limit -= 1
73
71
  # to reset
74
72
  if @@cnt_limit == 0
75
- reset [:fg, :bg, :tx, :rainbow]
73
+ reset
76
74
  end
77
75
  end
78
76
  else
79
- reset
77
+ reset if !@@stateful_getter
80
78
  return output
81
79
  end
82
80
 
@@ -90,7 +88,12 @@ module CE
90
88
  eval("@@#{caller_locations(2).first.label}").call(*arg)
91
89
  end
92
90
  else
93
- return arg
91
+ # just return
92
+ output = ""
93
+ arg.each do |elem|
94
+ output += elem
95
+ end
96
+ return output
94
97
  end
95
98
  end
96
99
  end
metadata CHANGED
@@ -1,31 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_echo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - khotta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
- Decorate the command line output with ANSI escape sequence.
14
+ Decorates command line output with ANSI escape sequence.
15
15
  Text that output by "print, puts, p" method is decorated.
16
16
  It is also can to decorate only your specified words!
17
17
  email:
18
18
  - khotta116@gmail.com
19
19
  executables:
20
- - color_echo
21
20
  - colorecho
22
21
  extensions: []
23
22
  extra_rdoc_files: []
24
23
  files:
25
24
  - LICENSE.txt
26
- - README.ja.md
27
25
  - README.md
28
- - bin/color_echo
29
26
  - bin/colorecho
30
27
  - bin/lib/display.rb
31
28
  - lib/color_echo.rb
@@ -39,14 +36,14 @@ files:
39
36
  - lib/color_echo/module/textattr.rb
40
37
  - lib/color_echo/override.rb
41
38
  - lib/color_echo/variables.rb
42
- homepage: https://github.com/khotta/color_echo
39
+ homepage: http://colorecho.net
43
40
  licenses:
44
41
  - MIT
45
42
  metadata: {}
46
43
  post_install_message: |2+
47
44
 
48
45
  Thank you for installing! =(^x^=
49
- See also https://github.com/khotta/color_echo
46
+ See also http://colorecho.net
50
47
 
51
48
  rdoc_options: []
52
49
  require_paths:
@@ -63,8 +60,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
60
  version: '0'
64
61
  requirements: []
65
62
  rubyforge_project:
66
- rubygems_version: 2.4.5.1
63
+ rubygems_version: 2.5.1
67
64
  signing_key:
68
65
  specification_version: 4
69
- summary: Decorate the command line output with ANSI escape sequence.
66
+ summary: Decorates command line output with ANSI escape sequence.
70
67
  test_files: []
@@ -1,405 +0,0 @@
1
- # color_echo
2
- color_echo はコマンドライン出力に色をつけるライブラリです。
3
-
4
- Version: 2.0.2
5
- Compliant Rubys Version: 2.0.0, 2.1.0 (for Linux)
6
- License: MIT
7
- Gems repository: http://rubygems.org/gems/color_echo
8
-
9
- ## Installation
10
-
11
- Add this line to your application's Gemfile:
12
-
13
- gem 'color_echo'
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install color_echo
18
-
19
- ## 256色の色の選択が可能です
20
- color_echo をインストールした後 `colorecho -l` と実行してみてください。
21
- ![screen shot](/images/color_index.png)
22
- ![screen shot](/images/color_index2.png)
23
-
24
- ## 特定のワードだけを色づけすることができます
25
-
26
- ```ruby
27
- CE.fg(:h_cyan).pickup("color_echo", :h_white, :red, :underscore).pickup("COLOR_ECHO", :h_yellow)
28
-
29
- puts <<EOS
30
- xxxxxxxxxxxxxxxxxcolor_echoxxxxxxxxxxxxxxxxxxxxxxxx
31
- xxxxcolor_echoxxxxxxxCOLOR_ECHOxxxxxxxxxxxxxxxxxxxx
32
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
33
- xxxxxxxxxxxxxxxxxcolor_echoxxxxxxxxxxcolor_echoxxxx
34
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
35
- EOS
36
- ```
37
- ![screen shot](/images/pickup1.png)
38
-
39
-
40
-
41
- ## getモード
42
- 例えば `CE.fg(:index100)` のように実行すれば、color_echoは #p, #puts, #printメソッドの出力を自動で色づけします。
43
- この機能を望まない場合は `require "color_echo"` ではなく、 `require "color_echo/get"` にしてください。
44
- CE.getのパラメータに指定した色のシーケンスコードをつけて返すようになります。
45
- ```ruby
46
- require "color_echo/get"
47
-
48
- greet = CE.fg(:yellow).get("Hello")
49
- name = CE.ch(:h_blue, :gray).get("Foo")
50
- myname = CE.tx(:underscore).rainbow.get("Bar")
51
-
52
- puts greet + ", " + name + "!"
53
- puts "My name is " + myname
54
-
55
- output = CE.fg(:blue).pickup(/color$/, :index199).pickup(/^color/, :h_green).get("color color color")
56
- puts "output is -> " + output
57
- ```
58
- ![screen shot](/images/get1.png)
59
-
60
-
61
- ## コマンドラインインターフェース
62
- color_echo は Rubyの gemライブラリですが、ターミナルで実行できるようコマンドラインインターフェースが実装されています。
63
- 詳しくは、コマンドラインで `color_echo -h` と実行してみてください。
64
- ![screen shot](/images/cli1.png)
65
- ![screen shot](/images/cli2.png)
66
-
67
-
68
- ## module functions
69
-
70
- #### CE.pickup(target, foreground=:red, backgruond=nil, *text_attribute)
71
- パラメータtargetとマッチする文字列を指定した文字色、背景色、テキスト装飾で色づけします。
72
- 使用できる文字色等は、`colorecho -s` または `colorecho -l` で確認できます。
73
- `CE.rainbow` がコールされている場合はこの機能は無視されます。
74
- 例: `CE.pickup(/^foo/, :index100, nil, :bold)`
75
- - Parameter target -> string|regexp or array of them
76
- - Parameter foreground -> symbol|nil
77
- - Parameter background -> symbol|nil
78
- - Parameter text_attribute -> symbol or array of them
79
- - Return -> self
80
-
81
-
82
- #### CE.hitline(foreground=nil, background=nil, *text_attribute)
83
- CE.pickupでマッチした行に対して、指定した文字色、背景色、テキスト装飾で色づけします。
84
- - Parameter foreground -> symbol|nil
85
- - Parameter background -> symbol|nil
86
- - Parameter text_attribute -> symbol or array of them
87
- - Return -> self
88
-
89
-
90
- #### CE.ch_fg(foreground)
91
- 文字色を指定した色に変更します。
92
- - Alias -> fg
93
- - Parameter foreground -> symbol
94
- - Return -> self
95
-
96
- * symbol list of foreground:
97
- * black
98
- * red
99
- * green
100
- * yellow
101
- * blue
102
- * magenta
103
- * cyan
104
- * white
105
- * gray
106
- * h_red
107
- * h_green
108
- * h_yellow
109
- * h_blue
110
- * h_magenta
111
- * h_cyan
112
- * h_white
113
- * index[1-256]
114
-
115
- ex.) CE.ch_fg :red #=> foreground color will be changed red
116
-
117
-
118
-
119
-
120
- #### CE.ch_bg(background)
121
- 背景色を指定した色に変更します。
122
- - Alias -> bg
123
- - Parameter background -> symbol
124
- - Return -> self
125
-
126
- * symbol list of background:
127
- * black
128
- * red
129
- * green
130
- * yellow
131
- * blue
132
- * magenta
133
- * cyan
134
- * white
135
- * gray
136
- * h_red
137
- * h_green
138
- * h_yellow
139
- * h_blue
140
- * h_magenta
141
- * h_cyan
142
- * h_white
143
- * index[1-256]
144
-
145
- ex.) CE.ch_bg :white #=> background color will be changed white
146
-
147
-
148
-
149
- #### CE.ch_tx(*text_attribute)
150
- テキスト装飾を指定した色に変更します。
151
- - Alias -> tx
152
- - Parameter text_attribute -> symbol or array of them
153
- - Return -> self
154
-
155
- * symbol list of text attribute:
156
- * bold
157
- * underscore
158
- * blink
159
- * reverse_video
160
- * concealed
161
-
162
- ex.) CE.ch_tx :blink #=> text blink on
163
-
164
-
165
- #### CE.ch(foreground, background=nil, *text_attribute)
166
- 文字色、背景色、テキスト装飾を指定したものに変更します。
167
- - Parameter foreground -> symbol|nil
168
- - Parameter background -> symbol|nil
169
- - Parameter text_attribute -> symbol or array of them
170
- - Return -> self
171
-
172
- ex.) CE.ch :white, :green
173
- ex.) CE.ch :h_red, nil, :blink
174
-
175
-
176
- #### CE.reset(scope=:all)
177
- 指定した色やテキスト装飾をリセットします。リセットする範囲はスコープで決まります。
178
- デフォルトは :all ですのですべての設定がリセットされます。
179
- - Alias -> off, disable
180
- - Parameter scope -> symbol or array of them
181
- - Return -> self
182
-
183
- ex.) CE.reset #=> reset all of the set escape sequence.
184
- ex.) CE.reset :fg #=> foreground color will be reset.
185
- ex.) CE.reset :bg #=> background color will be reset.
186
- ex.) CE.reset :tx #=> text attribute will be reset.
187
- ex.) CE.reset :pickup #=> the pickups text will be reset.
188
- ex.) CE.reset :hitline #=> sequence code list will be reset that is used at match line by CE.pickup.
189
- ex.) CE.reset :rainbow #=> rainbow mode will be reset and swich off.
190
- ex.) CE.reset [:fg. :tx] #=> foreground color and ext attribute will be reset.
191
-
192
-
193
- #### CE.once
194
- 一度だけ設定した装飾を適用します。
195
- これは CE.times(1) と同様です。
196
- - Return -> self
197
-
198
-
199
- #### CE.times(cnt)
200
- 指定した回数だけ設定した装飾を適用します。
201
- - Parameter cnt -> integer
202
- - Return -> self
203
-
204
- ```ruby
205
- CE.once.ch :h_yellow, :h_red, :underscore
206
- puts "decorated"
207
- puts "switch off"
208
-
209
- puts "\n"
210
-
211
- CE.times(3).rainbow
212
- puts "one"
213
- puts "two"
214
- puts "three"
215
- puts "switch off"
216
- ```
217
- ![screen shot](/images/result_off.png)
218
-
219
-
220
- #### CE.enable_refresh(scope=:all)
221
- 与えられた入力に対して可能な限りシーケンスコードを取り除きます。
222
- - Parameter scope -> symbol
223
- - :all: いかなる時もシーケンスコードを取り除きます。
224
- - :prematch: CE.pickupで指定したパターンにマッチした時だけシーケンスコードを取り除きます。
225
- - Return -> self
226
-
227
-
228
- #### CE.disable_refresh
229
- 与えられた入力に対してシーケンスコードを取り除きません。デフォルトはこの挙動です。
230
- - Return -> self
231
-
232
-
233
- #### CE.unuse
234
- このメソッドがコールされた時点で color_echo の機能を無効にします。
235
-
236
-
237
- #### CE.rainbow
238
- 出力をレインボーにします。
239
- - Return -> self
240
-
241
-
242
- #### CE.get(text)
243
- 設定されたシーケンスコードをつけて返します。`require "color_echo/get"` を読み込んだ時だけ使えるメソッドです。
244
- - Parameter text -> string
245
- - Return -> string
246
-
247
-
248
- ### Example
249
- ```ruby
250
- #
251
- # Example Code
252
- #
253
- #require "color_echo"
254
-
255
- # force ignore the function of this library
256
- #CE.unuse
257
-
258
- CE.ch :yellow
259
- puts "fooooooooo"
260
- puts "baaaaaaaar"
261
- puts "AAAAA", "BBBBB", "CCCCC"
262
-
263
- CE.ch :white, :red
264
- print "fooooooooo"
265
- print "baaaaaaaar"
266
- print "AAAAA", "BBBBB", "CCCCC"
267
-
268
- CE.ch :black, :magenta, :underscore
269
- p "fooooooooo"
270
- p "baaaaaaaar"
271
- p "AAAAA", "BBBBB", "CCCCC"
272
-
273
- ary = ["Duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate"]
274
-
275
- CE.off
276
- puts "switch off all colors and attribute."
277
-
278
- CE.fg :red
279
- puts ary
280
-
281
- CE.bg :cyan
282
- print ary
283
-
284
- CE.tx :underscore
285
- p ary
286
-
287
- CE.fg(:black).bg(:white).tx(:blink)
288
- puts <<EOM
289
- Lorem ipsum dolor sit amet,
290
- consectetur adipisicing elit,
291
- sed do eiusmod tempor incididunt
292
- ut labore et dolore magna aliqua.
293
- EOM
294
-
295
- CE.off
296
- CE.rainbow
297
- puts "fooooooooo"
298
- puts "baaaaaaaar"
299
- puts "AAAAA", "BBBBB", "CCCCC"
300
- puts ary
301
-
302
- print "fooooooooo"
303
- print "baaaaaaaar"
304
- print "AAAAA", "BBBBB", "CCCCC"
305
- print ary
306
-
307
- p "fooooooooo"
308
- p "baaaaaaaar"
309
- p "AAAAA", "BBBBB", "CCCCC"
310
- p ary
311
-
312
- puts <<EOM
313
- Lorem ipsum dolor sit amet,
314
- consectetur adipisicing elit,
315
- sed do eiusmod tempor incididunt
316
- ut labore et dolore magna aliqua.
317
- EOM
318
-
319
- CE.tx(:underscore).bg(:black)
320
- CE.rainbow
321
- hash = {:foo => [111, 222, 333], :bar => {:str => String}}
322
- p hash
323
- p "fooooooo", ["AAA", "BBB", "CCC"]
324
-
325
- CE.off
326
- puts "Disable rainbow mode."
327
- ```
328
-
329
- #### Result
330
-
331
- ![screen shot](/images/screenshot.png)
332
-
333
- ## Release Note
334
- * v2.0.3, 2016-01-06
335
- * 最新のgemコマンドはbinで指定したファイルにシンボリックリンクが使えないため古いgemでビルドし直しました。
336
-
337
- * v2.0.2, 2016-01-06
338
- * Fixed problem as below; https://github.com/khotta/color_echo/issues/1
339
- * colorechoコマンドが使えないバグがあります。このバージョンではなくv2.0.3を使用してください。
340
-
341
- * v2.0.1, 2015-08-21
342
- * コマンドラインインターフェースで複数行の入力を与えられたときマッチした行のハイライトが正しくつかない問題を修正しました。
343
-
344
- * v2.0.0, 2015-05-20
345
- * 次の新しいメソッドを追加しました -> CE::hitline, CE.enable_refresh, CE.disable_refresh
346
- * CE.reset のスコープに CE.pickupで指定したパターンとマッチした行に適用するシーケンスコードをリセットする ':hitline' を追加しました。
347
- * tailfコマンドと colorechoコマンドを複数パイプで渡すと出力がバッファに溜まりリアルタイムで出力されない問題を解消しました。
348
- * 正しくないエンコーディングを検知した際に対話モードが終了してしまう問題を解消しました。
349
- * 対話モードを ctl + c で終了した時の WARNINGを表示しないようにしました。
350
- * コマンドラインインターフェースのデフォルトの文字色をいかなる時も 'yellow' になるようにしました。
351
-
352
- * v1.3.0, 2015-02-06
353
- * Change some options help messages.
354
- * You can call 'colorecho' as 'color_echo' in command line interface.
355
-
356
- * v1.2.0, 2015-01-28
357
- * Add -e option.
358
-
359
- * v1.1.0, 2015-01-27
360
- * Modified to output the argument when the standard input is hit.
361
- * Add --stripe option in the command line interface.
362
- * Change the delimiter of long option with a hyphen -> -symbol-list,--index-list; Can to specify also underscore as before.
363
-
364
- * v1.0.0, 2015-01-23
365
- * Add command line interface.
366
-
367
- * v0.9.0, 2015-01-19
368
- * Add a mode to receive as the words with ANSI escape sequence; without output to display.
369
-
370
- * v0.8.0, 2015-01-14
371
- * Change for the specified arguments of reset method.
372
- * Fix small bugs.
373
-
374
- * v0.7.0, 2015-01-08
375
- * Add new method -> pickup
376
- * Add new symbol that can to specify in reset method of first parameter -> CE.reset(:pickup)
377
-
378
- * v0.6.0, 2015-01-05
379
- * Add command line tool.
380
-
381
- * v0.5.0, 2014-12-16
382
- * Add a new method -> \#once, \#times
383
-
384
- * v0.4.0, 2014-12-11
385
- * Add 256 colors.
386
-
387
- * v0.3.0, 2014-12-08
388
- * Add high colors.
389
- * Can to select multi value in ch_tx method.
390
- * Add parameter to the #reset method.
391
-
392
- * v0.2.4, 2014-12-04
393
- * Can to specify a non-string when rainbow mode.
394
- * Cab take over the setting of other types of sequence when rainbow mode.
395
-
396
- * v0.2.3, 2014-12-02
397
- * Fix small bugs.
398
-
399
- * v0.2.0
400
- * Added new method -> rainbow
401
- * Added some method alias.
402
-
403
- * v0.1.0
404
- * Added new method -> ch, unuse
405
- * Added some method alias.