color_echo 1.2.0 → 1.3.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: 9de36abdfab11068e2ed52e7907bedca5118b433
4
- data.tar.gz: 1ee5d4784d0860e95d9f63ce7e0097cef525e908
3
+ metadata.gz: 7525bc00bc7a3864587b5033958c44163ff1901e
4
+ data.tar.gz: 1fce685256af1ca16e36e92781a84cebfffd09d9
5
5
  SHA512:
6
- metadata.gz: a003cc5c7903d4e1feda4cafa81a4bab5e8ca1b5c19b0694e412a788da339ef7f2fc5cbaa88c0e9103a9bb5ca982bb9abf1dcbe39889986bea8a6468cdd46b72
7
- data.tar.gz: 34567dec9ac2acafaba4d716d0603403668d20a9dcfd223d098e6789d1d3fc11760bfbdda3b740fc963331f088d5bebff4032e74945a9c5361c6150864f1b993
6
+ metadata.gz: 387023506fd719b45daf5ddb58b09aa695dae3919be64233c7c102ac74937ff371719f2e01776ee973e1d942341b5144808cf43419f04eb738d61f402b792cb4
7
+ data.tar.gz: 902ef9eb6ca0443d95bf56ab22a49824f78579a2b17e4c46c9c8f89b78db2def5b9cc711b97cedf13a8312ecf8e2e3a6c44be61b69e42a3d5c486bc84d406285
data/README.md CHANGED
@@ -3,7 +3,7 @@ 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.2.0
6
+ Version: 1.3.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
@@ -308,29 +308,33 @@ puts "Disable rainbow mode."
308
308
  ![screen shot](/images/screenshot.png)
309
309
 
310
310
  ## Release Note
311
- * v1.2.0, 2014-01-28
311
+ * v1.3.0, 2014-02-06
312
+ * Change some options help messages.
313
+ * You can call 'colorecho' as 'color_echo' in command line interface.
314
+
315
+ * v1.2.0, 2015-01-28
312
316
  * Add -e option.
313
317
 
314
- * v1.1.0, 2014-01-27
318
+ * v1.1.0, 2015-01-27
315
319
  * Modified to output the argument when the standard input is hit.
316
320
  * Add --stripe option in the command line interface.
317
321
  * Change the delimiter of long option with a hyphen -> -symbol-list,--index-list; Can to specify also underscore as before.
318
322
 
319
- * v1.0.0, 2014-01-23
323
+ * v1.0.0, 2015-01-23
320
324
  * Add command line interface.
321
325
 
322
- * v0.9.0, 2014-01-19
326
+ * v0.9.0, 2015-01-19
323
327
  * Add a mode to receive as the words with ANSI escape sequence; without output to display.
324
328
 
325
- * v0.8.0, 2014-01-14
329
+ * v0.8.0, 2015-01-14
326
330
  * Change for the specified arguments of reset method.
327
331
  * Fix small bugs.
328
332
 
329
- * v0.7.0, 2014-01-08
333
+ * v0.7.0, 2015-01-08
330
334
  * Add new method -> pickup
331
335
  * Add new symbol that can to specify in reset method of first parameter -> CE.reset(:pickup)
332
336
 
333
- * v0.6.0, 2014-01-05
337
+ * v0.6.0, 2015-01-05
334
338
  * Add command line tool.
335
339
 
336
340
  * v0.5.0, 2014-12-16
@@ -68,20 +68,21 @@ def parse_options
68
68
  require "optparse"
69
69
  opt = OptionParser.new
70
70
 
71
- opt.on("-h") { usage }
72
- opt.on("-v") { version }
73
- opt.on("-s", "--symbol-list") { display_symbol_list }
74
- opt.on("-l", "--index-list") { display_color_index }
75
- opt.on("--symbol_list") { display_symbol_list } # for compatibility
76
- opt.on("--index_list") { display_color_index } # for compatibility
77
- opt.on("--fg val", "-f val") { |val| @fg = val }
78
- opt.on("--bg val", "-b val") { |val| @bg = val }
79
- opt.on("--tx val", "-t val") { |val| @tx = val }
80
- opt.on("--pickup val", "-p val") { |val| @pickups << val }
81
- opt.on("-w", "--watch") { @is_watch = true }
82
- opt.on("-n") { @last_lb = false }
83
- opt.on("-e") { @enable_lf = true }
84
- opt.on("--stripe") { @is_stripe = true }
71
+ opt.on("-h", @explain_h) { usage }
72
+ opt.on("-v", @explain_v) { version }
73
+ opt.on("-s", "--symbol-list", @explain_s) { display_symbol_list }
74
+ opt.on("-l", "--index-list", @explain_l) { display_color_index }
75
+ opt.on("--fg val", "-f val", @explain_f) { |val| @fg = val }
76
+ opt.on("--bg val", "-b val", @explain_b) { |val| @bg = val }
77
+ opt.on("--tx val", "-t val", @explain_t) { |val| @tx = val }
78
+ opt.on("--pickup val", "-p val", @explain_p) { |val| @pickups << val }
79
+ opt.on("-w", "--watch", @explain_w) { @is_watch = true }
80
+ opt.on("-n", @explain_n) { @last_lb = false }
81
+ opt.on("-e", @explain_e) { @enable_lf = true }
82
+ opt.on("--stripe", @explain_stripe) { @is_stripe = true }
83
+
84
+ opt.on("--symbol_list", @explain_s + " - [compatibility]" ) { display_symbol_list }
85
+ opt.on("--index_list", @explain_l + " - [compatibility]") { display_color_index }
85
86
 
86
87
  begin
87
88
  opt.parse!(ARGV)
@@ -128,10 +129,12 @@ end
128
129
  has_stdin = select([STDIN], [], [], 0) != nil || FileTest.pipe?(STDIN)
129
130
  usage if !has_stdin && ARGV.size == 0
130
131
 
132
+ require_color_echo_get
133
+ Version = CE::VERSION
134
+
131
135
  # parse options and set the decorate code that execute by eval
132
136
  parse_options
133
137
 
134
- require_color_echo_get
135
138
  if @is_watch
136
139
  # Interactive mode
137
140
  @exit_words = ["quit", "exit", "bye"]
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env ruby
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
+ require_relative "./lib/display"
14
+
15
+ def output_interactive
16
+ output_stripe_interactive if @is_stripe
17
+
18
+ while input = STDIN.gets
19
+ input.chomp!
20
+ exit 0 if @exit_words.index(input)
21
+ eval(@code_decorate)
22
+ puts CE.get(input)
23
+ end
24
+ end
25
+
26
+ def output_stripe_interactive
27
+ cnt = 0
28
+ while input = STDIN.gets
29
+ input.chomp!
30
+ exit 0 if @exit_words.index(input)
31
+ eval(@code_decorate) if cnt % 2 == 0
32
+ puts CE.get(input)
33
+ cnt += 1
34
+ end
35
+ end
36
+
37
+ def output(target)
38
+ output_stripe(target) if @is_stripe
39
+
40
+ eval(@code_decorate)
41
+ begin
42
+ print CE.get(target)
43
+ rescue Errno::EPIPE
44
+ end
45
+ exit 0
46
+ end
47
+
48
+ def output_stripe(target)
49
+ cnt = 0
50
+ target.split($/).each do |record|
51
+ eval(@code_decorate) if cnt % 2 == 0
52
+ puts CE.get(record)
53
+ cnt += 1
54
+ end
55
+ exit 0
56
+ end
57
+
58
+ def parse_options
59
+ @fg = nil
60
+ @bg = nil
61
+ @tx = nil
62
+ @pickups = []
63
+ @is_watch = false
64
+ @last_lb = true
65
+ @enable_lf = false
66
+ @is_stripe = false
67
+
68
+ require "optparse"
69
+ opt = OptionParser.new
70
+
71
+ opt.on("-h", @explain_h) { usage }
72
+ opt.on("-v", @explain_v) { version }
73
+ opt.on("-s", "--symbol-list", @explain_s) { display_symbol_list }
74
+ opt.on("-l", "--index-list", @explain_l) { display_color_index }
75
+ opt.on("--fg val", "-f val", @explain_f) { |val| @fg = val }
76
+ opt.on("--bg val", "-b val", @explain_b) { |val| @bg = val }
77
+ opt.on("--tx val", "-t val", @explain_t) { |val| @tx = val }
78
+ opt.on("--pickup val", "-p val", @explain_p) { |val| @pickups << val }
79
+ opt.on("-w", "--watch", @explain_w) { @is_watch = true }
80
+ opt.on("-n", @explain_n) { @last_lb = false }
81
+ opt.on("-e", @explain_e) { @enable_lf = true }
82
+ opt.on("--stripe", @explain_stripe) { @is_stripe = true }
83
+
84
+ opt.on("--symbol_list", @explain_s + " - [compatibility]" ) { display_symbol_list }
85
+ opt.on("--index_list", @explain_l + " - [compatibility]") { display_color_index }
86
+
87
+ begin
88
+ opt.parse!(ARGV)
89
+
90
+ rescue => err
91
+ warn "Parse Error! Please check usage!" + $/ + $/
92
+ usage
93
+ end
94
+
95
+ @fg = "yellow" if @fg == nil && @bg == nil && @tx == nil
96
+ @fg = @fg.intern if @fg != nil
97
+ @bg = @bg.intern if @bg != nil
98
+
99
+ if @tx != nil
100
+ res = []
101
+ @tx.split(",").each do |val|
102
+ res << val.intern
103
+ end
104
+ @tx = res
105
+ end
106
+
107
+ # ignore --pickup option when specified --stripe option
108
+ if @pickups.size > 0 && @is_stripe
109
+ warn "pickup option is ignored because your specified --stripe option."
110
+ @pickups = []
111
+ end
112
+
113
+ # parse pickups
114
+ if @pickups.size > 0
115
+ code_pickup = ""
116
+ @pickups.each_index do |index|
117
+ if @pickups[index][0] == "/" && (@pickups[index][-1] == "/" || @pickups[index][-2] == "/")
118
+ @pickups[index] = eval(@pickups[index])
119
+ end
120
+
121
+ code_pickup += %(.pickup(@pickups[#{index}], @fg, @bg, @tx))
122
+ end
123
+ @code_decorate = "CE" + code_pickup
124
+ else
125
+ @code_decorate = %(CE.ch(@fg, @bg, @tx))
126
+ end
127
+ end
128
+
129
+ has_stdin = select([STDIN], [], [], 0) != nil || FileTest.pipe?(STDIN)
130
+ usage if !has_stdin && ARGV.size == 0
131
+
132
+ require_color_echo_get
133
+ Version = CE::VERSION
134
+
135
+ # parse options and set the decorate code that execute by eval
136
+ parse_options
137
+
138
+ if @is_watch
139
+ # Interactive mode
140
+ @exit_words = ["quit", "exit", "bye"]
141
+ output_interactive
142
+ else
143
+ if has_stdin
144
+ target = STDIN.read
145
+
146
+ if ARGV.size > 0
147
+ print target
148
+ argv = ARGV.join(" ")
149
+ argv += $/ if @last_lb
150
+ output(argv)
151
+ end
152
+ else
153
+ target = ARGV.join(" ")
154
+ target += $/ if @last_lb
155
+ end
156
+
157
+ if @enable_lf
158
+ target.gsub!("\\r\\n", $/)
159
+ target.gsub!("\\n", $/)
160
+ target.gsub!("\\r", $/)
161
+ end
162
+
163
+ output(target)
164
+ end
@@ -1,3 +1,16 @@
1
+ @explain_v = "Show version of color_echo."
2
+ @explain_s = "Show symbol list that can to specify."
3
+ @explain_l = "Show color index list that can to specify."
4
+ @explain_p = "Decorate your specified wrods. You can use this option any number of times."
5
+ @explain_f = "Specify the foreground color."
6
+ @explain_b = "Specify the background color."
7
+ @explain_t = "Specify the text attributes."
8
+ @explain_w = "Interactive mode. Break word is -> exit, quit, bye; Or Ctl + c"
9
+ @explain_n = "Do not output the trailing newline."
10
+ @explain_e = "Enable interpretation of line feed."
11
+ @explain_h = "Show this message."
12
+ @explain_stripe = "Decorate on every other line. pickup option is ignored."
13
+
1
14
  def version
2
15
  require_color_echo
3
16
 
@@ -41,49 +54,48 @@ def usage
41
54
  puts padding + "* Options"
42
55
 
43
56
  puts padding * 2 + "-v:"
44
- puts padding * 3 + "Display version of color_echo." + $/ + $/
57
+ puts padding * 3 + @explain_v + $/ + $/
45
58
 
46
59
  puts padding * 2 + "--symbol-list:"
47
- puts padding * 3 + "Display symbol list that can to specify."
60
+ puts padding * 3 + @explain_s
48
61
  puts padding * 3 + "short option is -s." + $/ + $/
49
62
 
50
63
  puts padding * 2 + "--index-list:"
51
- puts padding * 3 + "Display color index list that can to specify."
64
+ puts padding * 3 + @explain_l
52
65
  puts padding * 3 + "short option is -l." + $/ + $/
53
66
 
54
67
  puts padding * 2 + "--pickup word [--pickup word ...]:"
55
- puts padding * 3 + "Decorate your specified wrods. You can use this option any number of times."
68
+ puts padding * 3 + @explain_p
56
69
  puts padding * 3 + "Regular expressions can be used; like that -> /^foo/i"
57
70
  puts padding * 3 + "short option is -p." + $/ + $/
58
71
 
59
72
  puts padding * 2 + "--fg color_name:"
60
- puts padding * 3 + "Decorate the foreground color."
73
+ puts padding * 3 + @explain_f
61
74
  puts padding * 3 + "short option is -f." + $/ + $/
62
75
 
63
76
  puts padding * 2 + "--bg color_name:"
64
- puts padding * 3 + "Decorate the background color."
77
+ puts padding * 3 + @explain_b
65
78
  puts padding * 3 + "short option is -b." + $/ + $/
66
79
 
67
80
  puts padding * 2 + "--tx text_attribute[,...]:"
68
- puts padding * 3 + "Decorate the text attribute."
81
+ puts padding * 3 + @explain_t
69
82
  puts padding * 3 + "short option is -t." + $/ + $/
70
83
 
71
84
  puts padding * 2 + "--watch:"
72
- puts padding * 3 + "Interactive mode. Break word is -> exit, quit, bye; Or Ctl + c"
85
+ puts padding * 3 + @explain_w
73
86
  puts padding * 3 + "short option is -w." + $/ + $/
74
87
 
75
88
  puts padding * 2 + "--stripe:"
76
- puts padding * 3 + "Decorate on every other line."
77
- puts padding * 3 + "pickup option is ignored." + $/ + $/
89
+ puts padding * 3 + @explain_stripe + $/ + $/
78
90
 
79
91
  puts padding * 2 + "-n:"
80
- puts padding * 3 + "Do not output the trailing newline." + $/ + $/
92
+ puts padding * 3 + @explain_n + $/ + $/
81
93
 
82
94
  puts padding * 2 + "-e:"
83
- puts padding * 3 + "Enable interpretation of line feed." + $/ + $/
95
+ puts padding * 3 + @explain_e + $/ + $/
84
96
 
85
97
  puts padding * 2 + "-h:"
86
- puts padding * 3 + "Show this message." + $/ + $/
98
+ puts padding * 3 + @explain_h + $/ + $/
87
99
 
88
100
  puts padding + "* Example"
89
101
 
@@ -1,6 +1,6 @@
1
1
  module CE
2
2
  LIBS_NAME = "color_echo"
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.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
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: 1.2.0
4
+ version: 1.3.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-28 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Decorate the command line output with ANSI escape sequence.
@@ -17,12 +17,14 @@ description: |
17
17
  email:
18
18
  executables:
19
19
  - color_echo
20
+ - colorecho
20
21
  extensions: []
21
22
  extra_rdoc_files: []
22
23
  files:
23
24
  - LICENSE.txt
24
25
  - README.md
25
26
  - bin/color_echo
27
+ - bin/colorecho
26
28
  - bin/lib/display.rb
27
29
  - lib/color_echo.rb
28
30
  - lib/color_echo/const.rb