color_echo 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -8
- data/bin/color_echo +18 -15
- data/bin/colorecho +164 -0
- data/bin/lib/display.rb +25 -13
- data/lib/color_echo/const.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7525bc00bc7a3864587b5033958c44163ff1901e
|
4
|
+
data.tar.gz: 1fce685256af1ca16e36e92781a84cebfffd09d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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,
|
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,
|
323
|
+
* v1.0.0, 2015-01-23
|
320
324
|
* Add command line interface.
|
321
325
|
|
322
|
-
* v0.9.0,
|
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,
|
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,
|
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,
|
337
|
+
* v0.6.0, 2015-01-05
|
334
338
|
* Add command line tool.
|
335
339
|
|
336
340
|
* v0.5.0, 2014-12-16
|
data/bin/color_echo
CHANGED
@@ -68,20 +68,21 @@ def parse_options
|
|
68
68
|
require "optparse"
|
69
69
|
opt = OptionParser.new
|
70
70
|
|
71
|
-
opt.on("-h")
|
72
|
-
opt.on("-v")
|
73
|
-
opt.on("-s", "--symbol-list") { display_symbol_list }
|
74
|
-
opt.on("-l", "--index-list") { display_color_index }
|
75
|
-
opt.on("--
|
76
|
-
opt.on("--
|
77
|
-
opt.on("--
|
78
|
-
opt.on("--
|
79
|
-
opt.on("
|
80
|
-
opt.on("
|
81
|
-
opt.on("-
|
82
|
-
opt.on("
|
83
|
-
|
84
|
-
opt.on("--
|
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"]
|
data/bin/colorecho
ADDED
@@ -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
|
data/bin/lib/display.rb
CHANGED
@@ -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 +
|
57
|
+
puts padding * 3 + @explain_v + $/ + $/
|
45
58
|
|
46
59
|
puts padding * 2 + "--symbol-list:"
|
47
|
-
puts padding * 3 +
|
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 +
|
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 +
|
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 +
|
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 +
|
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 +
|
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 +
|
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 +
|
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 +
|
92
|
+
puts padding * 3 + @explain_n + $/ + $/
|
81
93
|
|
82
94
|
puts padding * 2 + "-e:"
|
83
|
-
puts padding * 3 +
|
95
|
+
puts padding * 3 + @explain_e + $/ + $/
|
84
96
|
|
85
97
|
puts padding * 2 + "-h:"
|
86
|
-
puts padding * 3 +
|
98
|
+
puts padding * 3 + @explain_h + $/ + $/
|
87
99
|
|
88
100
|
puts padding + "* Example"
|
89
101
|
|
data/lib/color_echo/const.rb
CHANGED
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.
|
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-
|
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
|