color_echo 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71656796cab59b1ebe1d27d680e2ce4c30b7b604
4
- data.tar.gz: 2406fffc8c2a85628cfc797da963bc8bf373e705
3
+ metadata.gz: b057ff2dcd468a18b71e8997da18992987c6749c
4
+ data.tar.gz: 02fe38f9973436d2793057c603b7bd4421b37e41
5
5
  SHA512:
6
- metadata.gz: 9c955163de5d79d247474036f1a53608376e9e9383322bbc5b672ec8dada2618c32ed444f514c186f18fe4caed9f503780dae04cef29b66c342a8b1a0d3fa46c
7
- data.tar.gz: 4ae8cca7ff900843822a143ab41b9d8dc38321dd948d011514010144afa9bd138366516995ffe5ea129ba5ec0c2003fc601526e0349bc27bc8a8489a560cc687
6
+ metadata.gz: e8da10993a717801bb3d13e1579cb13f7471a30ef1ec0457a9491a8d277647a2f5ed72862aa4f6f1b3f048dca3c66ddf2ae14b8e3d72ed4d23db208e94789a7e
7
+ data.tar.gz: 9dab57abc01d2bc31a4fa97ce28e4abf51b05a4cdf249631bd9f6326d56eff0dec3e3346302bf6c46f7060b217806648089c8e47d9e16a0e22275a10c1e857b9
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # color_echo
2
2
  Decorate the command line output with ANSI escape sequence.
3
- String that is output by "print, puts, p" method is decorated.
3
+ Text 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.9.0
6
+ Version: 1.0.0
7
7
  Compliant Rubys Version: 2.0.0, 2.1.0 (for Linux)
8
8
  License: MIT
9
9
  Gems repository: http://rubygems.org/gems/color_echo
@@ -61,23 +61,10 @@ puts "output is -> " + output
61
61
  ![screen shot](/images/get1.png)
62
62
 
63
63
 
64
- ## You can run on the command line
65
- <pre>
66
- * Usage
67
- color_echo [options]
68
-
69
- * Options
70
- -v:
71
- Display version of color_echo.
72
-
73
- --symbol_list, -s
74
- Display symbol list that can to specify.
75
-
76
- --index_list, -l
77
- Display color index list that can to specify.
78
-
79
- If your server using the rbenv, You have to do `rbenv rehash`.
80
- </pre>
64
+ ## Command Line Interface
65
+ You can use color_echo on command line!
66
+ ![screen shot](/images/cli1.png)
67
+ ![screen shot](/images/cli2.png)
81
68
 
82
69
 
83
70
  ## module functions
@@ -321,37 +308,40 @@ puts "Disable rainbow mode."
321
308
  ![screen shot](/images/screenshot.png)
322
309
 
323
310
  ## Release Note
311
+ * v1.0.0,
312
+ * Add command line interface.
313
+
324
314
  * v0.9.0, 2014-01-19
325
- * Added a mode to receive as the words with ANSI escape sequence; without output to display.
315
+ * Add a mode to receive as the words with ANSI escape sequence; without output to display.
326
316
 
327
317
  * v0.8.0, 2014-01-14
328
- * Changed for the specified arguments of reset method.
329
- * Fixed small bugs.
318
+ * Change for the specified arguments of reset method.
319
+ * Fix small bugs.
330
320
 
331
321
  * v0.7.0, 2014-01-08
332
- * Added new method -> pickup
333
- * Added new symbol that can to specify in reset method of first parameter -> CE.reset(:pickup)
322
+ * Add new method -> pickup
323
+ * Add new symbol that can to specify in reset method of first parameter -> CE.reset(:pickup)
334
324
 
335
325
  * v0.6.0, 2014-01-05
336
- * Added command line tool.
326
+ * Add command line tool.
337
327
 
338
328
  * v0.5.0, 2014-12-16
339
- * Added a new method -> \#once, \#times
329
+ * Add a new method -> \#once, \#times
340
330
 
341
331
  * v0.4.0, 2014-12-11
342
- * Can to select 256 colors.
332
+ * Add 256 colors.
343
333
 
344
334
  * v0.3.0, 2014-12-08
345
- * High color can now be selected.
346
- * Multiple text attribute can now be selected.
347
- * Added parameter to the #reset method.
335
+ * Add high colors.
336
+ * Can to select multi value in ch_tx method.
337
+ * Add parameter to the #reset method.
348
338
 
349
339
  * v0.2.4, 2014-12-04
350
- * Can now be able to specify a non-string when rainbow mode.
351
- * Cab now be able to take over the setting of other types of sequence when rainbow mode.
340
+ * Can to specify a non-string when rainbow mode.
341
+ * Cab take over the setting of other types of sequence when rainbow mode.
352
342
 
353
343
  * v0.2.3, 2014-12-02
354
- * Fixed small bugs.
344
+ * Fix small bugs.
355
345
 
356
346
  * v0.2.0
357
347
  * Added new method -> rainbow
@@ -1,10 +1,28 @@
1
1
  #!/usr/bin/env ruby
2
- require "color_echo"
3
- #require_relative "../lib/color_echo.rb"
2
+
3
+ def require_color_echo
4
+ require "color_echo"
5
+ #require_relative "../lib/color_echo"
6
+ end
7
+
8
+ def require_color_echo_get
9
+ require "color_echo/get"
10
+ #require_relative "../lib/color_echo/get"
11
+ end
12
+
13
+ def version
14
+ require_color_echo
15
+
16
+ puts CE::VERSION
17
+ exit 0
18
+ end
4
19
 
5
20
  def usage
21
+ require_color_echo
22
+
6
23
  CE.once.ch :yellow
7
24
  puts <<-EOS
25
+
8
26
  #{CE::LIBS_NAME} - #{CE::SUMMARY}
9
27
  VERSION: #{CE::VERSION}
10
28
  README: #{CE::DOCS_PAGE}
@@ -12,31 +30,97 @@ def usage
12
30
  EOS
13
31
 
14
32
  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)
33
+ headers = ["* Usage", "* Options", "* Example"]
34
+ headers_op = [
35
+ "-v:", "--symbol_list:", "--index_list:", "--pickup word [--pickup word ...]:", "--fg color_name:", "--bg color_name:",
36
+ "--tx text_attribute[,...]:", "--watch:", "-n:", "-h:"
37
+ ]
38
+ CE.pickup(headers, :h_green)
39
+ CE.pickup(headers_op, :cyan)
19
40
 
20
41
  puts padding + "* Usage"
21
42
 
22
- CE.once.ch :h_blue
23
- puts padding * 2 + "color_echo [-h] [options]" + $/ + $/
43
+ CE.ch :h_blue
44
+ puts padding * 2 + "color_echo [options] text"
45
+ puts padding * 2 + "color_echo [options] < /path/to/file"
46
+ puts padding * 2 + "echo text | color_echo [options]"
47
+ puts padding * 2 + "color_echo -v"
48
+ puts padding * 2 + "color_echo -s"
49
+ puts padding * 2 + "color_echo -l"
50
+ puts padding * 2 + "color_echo -h" + $/ + $/
51
+ CE.off :fg
24
52
 
25
53
  puts padding + "* Options"
26
54
 
27
- puts padding + "-v:"
28
- puts padding * 2 + "Display version of color_echo." + $/ + $/
55
+ puts padding * 2 + "-v:"
56
+ puts padding * 3 + "Display version of color_echo." + $/ + $/
29
57
 
30
- puts padding + "--symbol_list, -s"
31
- puts padding * 2 + "Display symbol list that can to specify." + $/ + $/
58
+ puts padding * 2 + "--symbol_list:"
59
+ puts padding * 3 + "Display symbol list that can to specify."
60
+ puts padding * 3 + "short option is -s." + $/ + $/
32
61
 
33
- puts padding + "--index_list, -l"
34
- puts padding * 2 + "Display color index list that can to specify." + $/ + $/
62
+ puts padding * 2 + "--index_list:"
63
+ puts padding * 3 + "Display color index list that can to specify."
64
+ puts padding * 3 + "short option is -l." + $/ + $/
65
+
66
+ puts padding * 2 + "--pickup word [--pickup word ...]:"
67
+ puts padding * 3 + "Decorate your specified wrods. You can use this option any number of times."
68
+ puts padding * 3 + "Regular expressions can be used; like that -> /^foo/i"
69
+ puts padding * 3 + "short option is -p." + $/ + $/
70
+
71
+ puts padding * 2 + "--fg color_name:"
72
+ puts padding * 3 + "Decorate the foreground color."
73
+ puts padding * 3 + "short option is -f." + $/ + $/
74
+
75
+ puts padding * 2 + "--bg color_name:"
76
+ puts padding * 3 + "Decorate the background color."
77
+ puts padding * 3 + "short option is -b." + $/ + $/
78
+
79
+ puts padding * 2 + "--tx text_attribute[,...]:"
80
+ puts padding * 3 + "Decorate the text attribute."
81
+ puts padding * 3 + "short option is -t." + $/ + $/
82
+
83
+ puts padding * 2 + "--watch:"
84
+ puts padding * 3 + "Interactive mode. Break word is -> exit, quit, bye; Or Ctl + c"
85
+ puts padding * 3 + "short option is -w." + $/ + $/
86
+
87
+ puts padding * 2 + "-n:"
88
+ puts padding * 3 + "Do not output the trailing newline." + $/ + $/
89
+
90
+ puts padding * 2 + "-h:"
91
+ puts padding * 3 + "Show this message." + $/ + $/
92
+
93
+ puts padding + "* Example"
94
+
95
+ CE.once.ch :h_magenta
96
+ puts padding * 2 + %(* color_echo can to highlight even when you following the log file by tailf, tail -f.)
97
+ puts padding * 3 + %(tailf /var/log/httpd/access_log | color_echo -w -p "127.0.0.1" -t bold)
98
+ puts padding * 3 + %(tailf /var/log/php/php_error.log | color_echo -w -p "foo.php" -p "Fatal error:" -f h_blue) + $/ + $/
99
+
100
+ CE.once.ch :h_magenta
101
+ puts padding * 2 + %(* color_echo is useful to read the access log, etc.)
102
+ puts padding * 3 + %(cat /var/log/httpd/access_log | color_echo -p "Sun Jan 18" -f h_cyan -t underscore | less)
103
+ puts padding * 3 + %(color_echo -p "Sun Jan 18" -f h_cyan -t underscore < /var/log/httpd/access_log | less)
104
+ puts padding * 3 + %((color_echo -f cyan -p /\\\\s2..\\\\s/ | color_echo -f h_red -p /\\\\s5..\\\\s/ | less) < /var/log/httpd/access_log)
105
+ puts padding * 3 + %(sed -n 1,1000p /var/log/httpd/access_log | color_echo -f cyan -p /\\\\s2..\\\\s/ | color_echo -f h_red -p /\\\\s5..\\\\s/ | less) + $/ + $/
106
+
107
+ CE.once.ch :h_magenta
108
+ puts padding * 2 + %(* It is a simple to use.)
109
+ puts padding * 3 + %(color_echo Hello\\!\\! -f h_white -b index199)
110
+ puts padding * 3 + %(color_echo Hello\\!\\! -t blink,bold -f magenta) + $/ + $/
111
+
112
+ CE.once.ch :h_magenta
113
+ puts padding * 2 + %(* color_echo can receive the standard input.)
114
+ puts padding * 3 + %(echo FooFoOfOO | color_echo -t reverse_video)
115
+ puts padding * 3 + %(echo FooFoOfOO | color_echo -f index130 -p /foo$/i | color_echo -f index180 -p /^foo/i)
116
+ puts padding * 3 + %(netstat -na | color_echo -p ":80" | color_echo -p "127.0.0.1" -f h_cyan) + $/ + $/
35
117
 
36
118
  exit 0
37
119
  end
38
120
 
39
121
  def display_color_index
122
+ require_color_echo
123
+
40
124
  CE.rainbow
41
125
  cnt = 134
42
126
  padding = " " * 2
@@ -66,6 +150,8 @@ def display_color_index
66
150
  end
67
151
 
68
152
  def display_symbol_list
153
+ require_color_echo
154
+
69
155
  symbols_color = [
70
156
  :black,
71
157
  :gray,
@@ -117,7 +203,8 @@ def display_symbol_list
117
203
 
118
204
  puts padding + header_text_attrs
119
205
  symbols_text_attr.each do |tx_name|
120
- CE.off(:tx).tx tx_name
206
+ CE.off(:tx)
207
+ CE.tx tx_name if tx_name != :concealed
121
208
  puts "#{padding*2}:#{tx_name}" + " " * (30 - tx_name.to_s.size)
122
209
  end
123
210
 
@@ -126,26 +213,99 @@ def display_symbol_list
126
213
  exit 0
127
214
  end
128
215
 
129
- usage if ARGV.size != 1
216
+ def output_interactive
217
+ exit_words = ["quit", "exit", "bye"]
218
+ while input = STDIN.gets
219
+ input.chomp!
220
+ exit 0 if exit_words.index(input)
221
+ eval(@code_decorate)
222
+ puts CE.get(input)
223
+ end
224
+ end
225
+
226
+ def output(target)
227
+ eval(@code_decorate)
228
+ begin
229
+ print CE.get(target)
230
+ rescue Errno::EPIPE
231
+ end
232
+ end
233
+
234
+ def parse_options
235
+ @fg = nil
236
+ @bg = nil
237
+ @tx = nil
238
+ @pickups = []
239
+ @is_watch = false
240
+ @last_lb = true
241
+
242
+ require "optparse"
243
+ opt = OptionParser.new
244
+
245
+ opt.on("-h") { usage }
246
+ opt.on("-v") { version }
247
+ opt.on("-s", "--symbol_list") { display_symbol_list }
248
+ opt.on("-l", "--index_list") { display_color_index }
249
+ opt.on("--fg val", "-f val") { |val| @fg = val }
250
+ opt.on("--bg val", "-b val") { |val| @bg = val }
251
+ opt.on("--tx val", "-t val") { |val| @tx = val }
252
+ opt.on("--pickup val", "-p val") { |val| @pickups << val }
253
+ opt.on("-w", "--watch") { @is_watch = true }
254
+ opt.on("-n") { @last_lb = false }
255
+
256
+ begin
257
+ opt.parse!(ARGV)
130
258
 
131
- require "optparse"
132
- opt = OptionParser.new
259
+ rescue => err
260
+ warn "Parse Error! Please check usage!" + $/ + $/
261
+ usage
262
+ end
263
+
264
+ @fg = "yellow" if @fg == nil && @bg == nil && @tx == nil
265
+ @fg = @fg.intern if @fg != nil
266
+ @bg = @bg.intern if @bg != nil
267
+
268
+ if @tx != nil
269
+ res = []
270
+ @tx.split(",").each do |val|
271
+ res << val.intern
272
+ end
273
+ @tx = res
274
+ end
275
+
276
+ # parse pickups
277
+ if @pickups.size > 0
278
+ code_pickup = ""
279
+ @pickups.each_index do |index|
280
+ if @pickups[index][0] == "/" && (@pickups[index][-1] == "/" || @pickups[index][-2] == "/")
281
+ @pickups[index] = eval(@pickups[index])
282
+ end
283
+
284
+ code_pickup += %(.pickup(@pickups[#{index}], @fg, @bg, @tx))
285
+ end
286
+ @code_decorate = "CE" + code_pickup
287
+ else
288
+ @code_decorate = %(CE.ch(@fg, @bg, @tx))
289
+ end
290
+ end
133
291
 
134
- opt.on("-h") { usage }
135
- opt.on("-v") { puts CE::VERSION; exit 0 }
136
- opt.on("-s", "--symbol_list") { display_symbol_list }
137
- opt.on("-l", "--index_list") { display_color_index }
292
+ has_stdin = select([STDIN], [], [], 0) != nil || FileTest.pipe?(STDIN)
293
+ usage if !has_stdin && ARGV.size == 0
138
294
 
139
- begin
140
- opt.parse!(ARGV)
295
+ # parse options and set the decorate code that execute by eval
296
+ parse_options
141
297
 
142
- rescue OptionParser::InvalidOption => err
143
- mess = "[OPTION ERROR] Invalid option ->"
144
- err.args.each do |op|
145
- mess += %( '#{op}')
298
+ require_color_echo_get
299
+ if @is_watch
300
+ # Interactive mode
301
+ output_interactive
302
+ else
303
+ if has_stdin
304
+ target = STDIN.read
305
+ else
306
+ target = ARGV.join(" ")
307
+ target += $/ if @last_lb
146
308
  end
147
- mess += " (OptionParser::InvalidOption)"
148
- warn mess + $/ + $/
149
309
 
150
- usage
310
+ output(target)
151
311
  end
@@ -1,6 +1,6 @@
1
1
  # color_echo
2
2
  # Decorate the command line output with ANSI escape sequence.
3
- # String that is output by "print, puts, p" method is decorated.
3
+ # Text 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
6
  require_relative "color_echo/get"
@@ -1,11 +1,11 @@
1
1
  module CE
2
2
  LIBS_NAME = "color_echo"
3
- VERSION = "0.9.0"
3
+ VERSION = "1.0.0"
4
4
  SUMMARY = "Decorate the command line output with ANSI escape sequence."
5
5
  DOCS_PAGE = "https://github.com/khotta/color_echo"
6
6
  DESCRIPTION = <<EOS
7
7
  #{SUMMARY}
8
- String that is output by "print, puts, p" method is decorated.
8
+ Text that is output by "print, puts, p" method is decorated.
9
9
  It is also can to decorate only your specified words!
10
10
  EOS
11
11
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_echo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.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: 2015-01-19 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Decorate the command line output with ANSI escape sequence.
15
- String that is output by "print, puts, p" method is decorated.
15
+ Text that is 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
  executables: