color_echo 1.3.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7525bc00bc7a3864587b5033958c44163ff1901e
4
- data.tar.gz: 1fce685256af1ca16e36e92781a84cebfffd09d9
3
+ metadata.gz: e03c82c73008a98fc0daa0e8d2a8da08f85fb696
4
+ data.tar.gz: 3178951912dfeaadf75a2b0d19f23dbbb0a37817
5
5
  SHA512:
6
- metadata.gz: 387023506fd719b45daf5ddb58b09aa695dae3919be64233c7c102ac74937ff371719f2e01776ee973e1d942341b5144808cf43419f04eb738d61f402b792cb4
7
- data.tar.gz: 902ef9eb6ca0443d95bf56ab22a49824f78579a2b17e4c46c9c8f89b78db2def5b9cc711b97cedf13a8312ecf8e2e3a6c44be61b69e42a3d5c486bc84d406285
6
+ metadata.gz: 5e4d8511962670bb346d3838c2d6713fcae884730ca55f8ff0aed15045e633ec402ac8d57574a86dd405f367a932d0333dd68a0daec58caeac48289ef28b9bf5
7
+ data.tar.gz: 550071bdb3785ad5b7c4bacbeb23b07773f5bc37bd3fa577116cb18e84860ba49691781fef67ff8fe1c68a01273fe249508c83ad54bd9d524e6a4f5a0bc37145
@@ -0,0 +1,395 @@
1
+ # color_echo
2
+ color_echo はコマンドライン出力に色をつけるライブラリです。
3
+
4
+ Version: 2.0.0
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
+
205
+ #### CE.enable_refresh(scope=:all)
206
+ 与えられた入力に対して可能な限りシーケンスコードを取り除きます。
207
+ - Parameter scope -> symbol
208
+ - :all: いかなる時もシーケンスコードを取り除きます。
209
+ - :prematch: CE.pickupで指定したパターンにマッチした時だけシーケンスコードを取り除きます。
210
+ - Return -> self
211
+
212
+
213
+ #### CE.disable_refresh
214
+ 与えられた入力に対してシーケンスコードを取り除きません。デフォルトはこの挙動です。
215
+ - Return -> self
216
+
217
+
218
+ ```ruby
219
+ CE.once.ch :h_yellow, :h_red, :underscore
220
+ puts "decorated"
221
+ puts "switch off"
222
+
223
+ puts "\n"
224
+
225
+ CE.times(3).rainbow
226
+ puts "one"
227
+ puts "two"
228
+ puts "three"
229
+ puts "switch off"
230
+ ```
231
+ ![screen shot](/images/result_off.png)
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.0, 2014-05-20
335
+ * 次の新しいメソッドを追加しました -> CE::hitline, CE.enable_refresh, CE.disable_refresh
336
+ * CE.reset のスコープに CE.pickupで指定したパターンとマッチした行に適用するシーケンスコードをリセットする ':hitline' を追加しました。
337
+ * tailfコマンドと colorechoコマンドを複数パイプで渡すと出力がバッファに溜まりリアルタイムで出力されない問題を解消しました。
338
+ * 正しくないエンコーディングを検知した際に対話モードが終了してしまう問題を解消しました。
339
+ * 対話モードを ctl + c で終了した時の WARNINGを表示しないようにしました。
340
+ * コマンドラインインターフェースのデフォルトの文字色をいかなる時も 'yellow' になるようにしました。
341
+
342
+ * v1.3.0, 2014-02-06
343
+ * Change some options help messages.
344
+ * You can call 'colorecho' as 'color_echo' in command line interface.
345
+
346
+ * v1.2.0, 2015-01-28
347
+ * Add -e option.
348
+
349
+ * v1.1.0, 2015-01-27
350
+ * Modified to output the argument when the standard input is hit.
351
+ * Add --stripe option in the command line interface.
352
+ * Change the delimiter of long option with a hyphen -> -symbol-list,--index-list; Can to specify also underscore as before.
353
+
354
+ * v1.0.0, 2015-01-23
355
+ * Add command line interface.
356
+
357
+ * v0.9.0, 2015-01-19
358
+ * Add a mode to receive as the words with ANSI escape sequence; without output to display.
359
+
360
+ * v0.8.0, 2015-01-14
361
+ * Change for the specified arguments of reset method.
362
+ * Fix small bugs.
363
+
364
+ * v0.7.0, 2015-01-08
365
+ * Add new method -> pickup
366
+ * Add new symbol that can to specify in reset method of first parameter -> CE.reset(:pickup)
367
+
368
+ * v0.6.0, 2015-01-05
369
+ * Add command line tool.
370
+
371
+ * v0.5.0, 2014-12-16
372
+ * Add a new method -> \#once, \#times
373
+
374
+ * v0.4.0, 2014-12-11
375
+ * Add 256 colors.
376
+
377
+ * v0.3.0, 2014-12-08
378
+ * Add high colors.
379
+ * Can to select multi value in ch_tx method.
380
+ * Add parameter to the #reset method.
381
+
382
+ * v0.2.4, 2014-12-04
383
+ * Can to specify a non-string when rainbow mode.
384
+ * Cab take over the setting of other types of sequence when rainbow mode.
385
+
386
+ * v0.2.3, 2014-12-02
387
+ * Fix small bugs.
388
+
389
+ * v0.2.0
390
+ * Added new method -> rainbow
391
+ * Added some method alias.
392
+
393
+ * v0.1.0
394
+ * Added new method -> ch, unuse
395
+ * Added some method alias.
data/README.md CHANGED
@@ -3,10 +3,11 @@ Decorate the command line output with ANSI escape sequence.
3
3
  Text that output by "print, puts, p" method is decorated.
4
4
  It is also can to decorate only your specified words!
5
5
 
6
- Version: 1.3.0
6
+ Version: 2.0.0
7
7
  Compliant Rubys Version: 2.0.0, 2.1.0 (for Linux)
8
8
  License: MIT
9
- Gems repository: http://rubygems.org/gems/color_echo
9
+ Gems repository: http://rubygems.org/gems/color_echo
10
+ Japanese Document: https://github.com/khotta/color_echo/blob/master/README.ja.md
10
11
 
11
12
  ## Installation
12
13
 
@@ -69,7 +70,7 @@ You can use color_echo on command line!
69
70
 
70
71
  ## module functions
71
72
 
72
- #### CE.pickup(target, foreground=:red, backgruond=nil, text_attribute)
73
+ #### CE.pickup(target, foreground=:red, backgruond=nil, *text_attribute)
73
74
  To decorate the words that specfied in the String or Regexp or Array of them.
74
75
  If state of enable rainbow mode, This feature is disabled.
75
76
  - Parameter target -> string|regexp or array of them
@@ -79,6 +80,14 @@ If state of enable rainbow mode, This feature is disabled.
79
80
  - Return -> self
80
81
 
81
82
 
83
+ #### CE.hitline(foreground=nil, background=nil, *text_attribute)
84
+ To decorate match lines by CE.pickup method with specified here.
85
+ - Parameter foreground -> symbol|nil
86
+ - Parameter background -> symbol|nil
87
+ - Parameter text_attribute -> symbol or array of them
88
+ - Return -> self
89
+
90
+
82
91
  #### CE.ch_fg(foreground)
83
92
  Change the foreground color to the your specified color.
84
93
  - Alias -> fg
@@ -138,7 +147,7 @@ ex.) CE.ch_bg :white #=> background color will be changed white
138
147
 
139
148
 
140
149
 
141
- #### CE.ch_tx(text_attribute)
150
+ #### CE.ch_tx(*text_attribute)
142
151
  Change the text attribute to the your specified decoration.
143
152
  - Alias -> tx
144
153
  - Parameter text_attribute -> symbol or array of them
@@ -154,7 +163,7 @@ Change the text attribute to the your specified decoration.
154
163
  ex.) CE.ch_tx :blink #=> text blink on
155
164
 
156
165
 
157
- #### CE.ch foreground [,background [,text_attribute]]
166
+ #### CE.ch(foreground, background=nil, *text_attribute)
158
167
  Change collectively.
159
168
  - Parameter foreground -> symbol|nil
160
169
  - Parameter background -> symbol|nil
@@ -175,7 +184,8 @@ ex.) CE.reset #=> reset all of the set escape sequence.
175
184
  ex.) CE.reset :fg #=> foreground color will be reset.
176
185
  ex.) CE.reset :bg #=> background color will be reset.
177
186
  ex.) CE.reset :tx #=> text attribute will be reset.
178
- ex.) CE.reset :pickup #=> pickup text 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.
179
189
  ex.) CE.reset :rainbow #=> rainbow mode will be reset and swich off.
180
190
  ex.) CE.reset [:fg. :tx] #=> foreground color and ext attribute will be reset.
181
191
 
@@ -191,6 +201,20 @@ Reset automatically after cnt times output.
191
201
  - Return -> self
192
202
 
193
203
 
204
+ #### CE.enable_refresh(scope=:all)
205
+ Try to remove the sequence code from the given.
206
+ - Parameter scope -> symbol
207
+ - :all: Try to remove the sequence code from the given always.
208
+ - :prematch: If given matches, Try to remove sequence code from it.
209
+ - Return -> self
210
+
211
+
212
+ #### CE.disable_refresh
213
+ Not try to remove the sequence code from the given.
214
+ Default is this.
215
+ - Return -> self
216
+
217
+
194
218
  ```ruby
195
219
  CE.once.ch :h_yellow, :h_red, :underscore
196
220
  puts "decorated"
@@ -308,6 +332,14 @@ puts "Disable rainbow mode."
308
332
  ![screen shot](/images/screenshot.png)
309
333
 
310
334
  ## Release Note
335
+ * v2.0.0, 2014-05-20
336
+ * Add new method -> CE::hitline, CE.enable_refresh, CE.disable_refresh, Please check the reference.
337
+ * Can to select new parameter ':hitline' in CE.reset.
338
+ * Flushes any buffered data when output data to STDOUT.
339
+ * Fixed bug, When the input was included invalid encoding.
340
+ * Fixed not to be output the interruptted message, When you pressed ctl + C.
341
+ * Fixed default foreground color to yellow in command line interface.
342
+
311
343
  * v1.3.0, 2014-02-06
312
344
  * Change some options help messages.
313
345
  * You can call 'colorecho' as 'color_echo' in command line interface.