color_echo 3.0.0 → 3.1.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: d6506be07d0069c30e631fe82b4b2efb44deb11c
4
- data.tar.gz: 6c5ef32192472f4be0d8c507fb50ad5bdb59e221
3
+ metadata.gz: 6bde265f335a5fd1611039aa47bb7525a4fa5871
4
+ data.tar.gz: fbbfa7841a06fd8b7f8227a44f83bfd75c067bc4
5
5
  SHA512:
6
- metadata.gz: 15e8243c5504922d0fd2bc9bd90acac164f8d028af05d5d3b2e6b92c5af9c56e1ac81f51a1117d9b8dbb2ceac30e09681effd2529ed5c496eeb4268ae5235fc8
7
- data.tar.gz: a0cc6e4418eff5461d137ebeb36b9898dacbc3d63aca9a3a190499b2056acd9f45d74cc143f1e0483c616c3fbca12e782c5182eb588be381530733e5c01fc35c
6
+ metadata.gz: efa3cb80047d62e6456f3b2a9c3496084be62bb307aaeeffc9a3ce76b9b48b3ebfa63eb86c6c1e2f10a679c39155fa828240e12965951f7e25fbf9f8f54a759c
7
+ data.tar.gz: 7cc9b92feb89d30cd0484bfc95d5d9af92b6110b305eaa465ac51005793bf105750db244bd39f645c50e0b8d0e1290be26783a5fbcff565830dbdfad869d2e40
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014,2015 Kazuya Hotta
1
+ Copyright (c) 2014-2016 Kazuya Hotta
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -4,6 +4,9 @@ Decorates command line output with ANSI escape sequence.
4
4
  Documents and all informations are as below =(^x^=
5
5
  http://colorecho.net
6
6
 
7
+ See on rubygems
8
+ https://rubygems.org/gems/color_echo
9
+
7
10
  ### You can choose 256 colors!!
8
11
  ![screen shot](/image/colorindex01.png)
9
12
  ![screen shot](/image/colorindex02.png)
@@ -250,7 +250,7 @@ def read_conf(conf_path, list)
250
250
 
251
251
  opname = ((/^-/ =~ op[0]) == nil) ? (op[0].size > 1 ? "--" : "-") + op[0] : op[0]
252
252
  additions << opname
253
- additions << op[1] if defined? op[1]
253
+ additions << op[1] if (defined? op[1]) && op[1] != nil
254
254
  end
255
255
  else
256
256
  # Missing specified file
@@ -294,6 +294,7 @@ def read_conf(conf_path, list)
294
294
  opt.on("-R", "--refresh" ) { refresh = true }
295
295
  opt.parse!(additions)
296
296
  end
297
+
297
298
  @fg ||= fg
298
299
  @bg ||= bg
299
300
  @tx ||= tx
@@ -51,9 +51,8 @@ def usage
51
51
 
52
52
  CE.once.ch :yellow
53
53
  puts <<-EOS
54
- #{CE::LIBS_NAME} - #{CE::SUMMARY}
54
+ #{CE::LIBS_NAME} - #{CE::DESCRIPTION}
55
55
  VERSION: #{CE::VERSION}
56
- README: #{CE::DOCS_PAGE}
57
56
 
58
57
  EOS
59
58
 
@@ -1,7 +1,6 @@
1
1
  # color_echo
2
- # Decorate the command line output with ANSI escape sequence.
3
- # Text that output by "print, puts, p" method is decorated.
4
- # It is also can to decorate only your specified words!
2
+ #
3
+ # Decorates command line output with ANSI escape sequence.
5
4
 
6
5
  require_relative "color_echo/get"
7
6
  require_relative "color_echo/override"
@@ -1,11 +1,7 @@
1
1
  module CE
2
2
  LIBS_NAME = "color_echo"
3
- VERSION = "3.0.0"
3
+ VERSION = "3.1.0"
4
4
  SUMMARY = "Decorates command line output with ANSI escape sequence."
5
5
  HOMEPAGE = "http://colorecho.net"
6
- DESCRIPTION = <<EOS
7
- #{SUMMARY}
8
- Text that output by "print, puts, p" method is decorated.
9
- It is also can to decorate only your specified words!
10
- EOS
6
+ DESCRIPTION = %(#{SUMMARY} #{HOMEPAGE})
11
7
  end
@@ -182,7 +182,7 @@ module CE
182
182
  def get(text)
183
183
  if @@allow_output
184
184
  caller()[0] =~ /(.*?):(\d+)/
185
- warn (%([WARNING] #{$1} #{$2}: You can't call CE.get. You must to read like -> require 'color_echo/get' ))
185
+ warn (%([WARNING] #{$1} #{$2}: You can't call CE.get. You must read like -> require 'color_echo/get' ))
186
186
  return text
187
187
  end
188
188
 
@@ -226,6 +226,22 @@ module CE
226
226
  return self
227
227
  end
228
228
 
229
+ # @param symbol arg
230
+ # @return array
231
+ def withdraw(*arg)
232
+ deleted = []
233
+ arg.each do |target|
234
+ deleted << @@assgined.delete(target)
235
+ end
236
+
237
+ return deleted
238
+ end
239
+
240
+ # @return array
241
+ def get_assigned
242
+ return @@assgined
243
+ end
244
+
229
245
  # method alias
230
246
  alias_method :off, :reset
231
247
  alias_method :disable, :reset
@@ -13,3 +13,4 @@ require_relative "module/textattr"
13
13
  require_relative "module/off"
14
14
  require_relative "functions"
15
15
  require_relative "internal"
16
+ require_relative "private_task"
@@ -15,11 +15,10 @@ def puts(*arg)
15
15
  CE.task.call(*arg)
16
16
  end
17
17
 
18
- # TODO
19
- #def printf(*arg)
20
- # CE.task.call(*arg)
21
- #end
18
+ def printf(*arg)
19
+ CE.task.call(*arg)
20
+ end
22
21
 
23
- #def putc(*arg)
24
- # CE.task.call(*arg)
25
- #end
22
+ def putc(*arg)
23
+ CE.task.call(*arg)
24
+ end
@@ -0,0 +1,67 @@
1
+ module CE
2
+ private
3
+ def task_available(called, arg)
4
+ # change output destination to StringIO Object
5
+ strio = StringIO.new
6
+ $stdout = strio
7
+
8
+ # call original method
9
+ eval("@@#{called}").call(*arg)
10
+
11
+ # change output destination to STDOUT
12
+ $stdout = STDOUT
13
+
14
+ # get output text
15
+ if @@rainbow
16
+ output = add_rainbow(strio.string)
17
+ else
18
+ output = strio.string
19
+
20
+ # try to remove escape sequence code
21
+ output = cleanup_text(output) if @@refresh
22
+
23
+ # decorate pickup
24
+ if @@pickup_list.size > 0
25
+ output = add_pickup_code(output)
26
+ end
27
+
28
+ # add start code in header
29
+ output = get_start_code + output
30
+
31
+ # add reset code in front of line feed
32
+ output = add_reset_line_feed(output)
33
+ end
34
+
35
+ # output to STDOUT
36
+ if @@allow_output
37
+ $stdout.print output
38
+ # auto off
39
+ if @@cnt_limit > 0
40
+ @@cnt_limit -= 1
41
+ # to reset
42
+ if @@cnt_limit == 0
43
+ reset
44
+ end
45
+ end
46
+ else
47
+ reset if !@@stateful_getter
48
+ return output
49
+ end
50
+ end
51
+
52
+ # this task will be called if CE.unuse was called
53
+ private
54
+ def task_unuse(called, arg)
55
+ if @@allow_output
56
+ # call original method
57
+ eval("@@#{called}").call(*arg)
58
+ else
59
+ # just return
60
+ output = ""
61
+ arg.each do |elem|
62
+ output += elem
63
+ end
64
+ return output
65
+ end
66
+ end
67
+ end
@@ -10,91 +10,48 @@ module CE
10
10
  @@code_text_attr = ""
11
11
  @@code_highlights = []
12
12
  @@code_rainbow = ""
13
- # count number for times method
14
- @@cnt_limit = 0
15
- @@pickup_list = {}
16
- # how much pattern having?
17
- @@cnt_pickups = 0
18
- @@stateful_getter = false
19
-
20
- @@print = method :print
21
- @@p = method :p
22
- @@puts = method :puts
23
-
24
- @@get = lambda do |text|
25
- print text
26
- end
27
-
28
- @@task = lambda do |*arg|
29
- if available?
30
- # change output destination to StringIO Object
31
- strio = StringIO.new
32
- $stdout = strio
33
13
 
34
- # call original method
35
- if RUBY_VERSION >= "2.3.0"
36
- eval("@@#{caller_locations(1).first.label}").call(*arg)
37
- else
38
- eval("@@#{caller_locations(2).first.label}").call(*arg)
39
- end
14
+ # count number for times method
15
+ @@cnt_limit = 0
40
16
 
41
- # change output destination to STDOUT
42
- $stdout = STDOUT
17
+ # pickup patterns and decoration of it
18
+ @@pickup_list = {}
43
19
 
44
- # get output text
45
- if @@rainbow
46
- output = add_rainbow(strio.string)
47
- else
48
- output = strio.string
20
+ # how much patterns having?
21
+ @@cnt_pickups = 0
49
22
 
50
- # try to remove escape sequence code
51
- output = cleanup_text(output) if @@refresh
23
+ # is stateful when 'color_echo/get'?
24
+ @@stateful_getter = false
52
25
 
53
- # decorate pickup
54
- if @@pickup_list.size > 0
55
- output = add_pickup_code(output)
56
- end
26
+ # assgined methods to decorate
27
+ @@assgined = [:puts, :p, :print, :printf, :putc]
57
28
 
58
- # add start code in header
59
- output = get_start_code + output
29
+ # save methods
30
+ @@puts = method :puts
31
+ @@p = method :p
32
+ @@print = method :print
33
+ @@printf = method :printf
34
+ @@putc = method :putc
60
35
 
61
- # add reset code in front of line feed
62
- output = add_reset_line_feed(output)
63
- end
36
+ # closure for CE.get
37
+ @@get = lambda do |text|
38
+ print text
39
+ end
64
40
 
65
- # output to STDOUT
66
- if @@allow_output
67
- $stdout.print output
68
- # auto off
69
- if @@cnt_limit > 0
70
- @@cnt_limit -= 1
71
- # to reset
72
- if @@cnt_limit == 0
73
- reset
74
- end
75
- end
76
- else
77
- reset if !@@stateful_getter
78
- return output
79
- end
41
+ # assgined methods will be overwritten as this closure
42
+ @@task = lambda do |*arg|
43
+ # get function name that was called
44
+ if RUBY_VERSION >= "2.3.0"
45
+ called = caller_locations(1).first.label
46
+ else
47
+ called = caller_locations(2).first.label
48
+ end
80
49
 
81
- # no available "color echo"
50
+ if available? && called == "get" || @@assgined.index(called.intern)
51
+ task_available(called, arg)
82
52
  else
83
- if @@allow_output
84
- # call original method
85
- if RUBY_VERSION >= "2.3.0"
86
- eval("@@#{caller_locations(1).first.label}").call(*arg)
87
- else
88
- eval("@@#{caller_locations(2).first.label}").call(*arg)
89
- end
90
- else
91
- # just return
92
- output = ""
93
- arg.each do |elem|
94
- output += elem
95
- end
96
- return output
97
- end
53
+ # no available "color echo"
54
+ task_unuse(called, arg)
98
55
  end
99
56
  end
100
57
  end
metadata CHANGED
@@ -1,19 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: color_echo
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.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-27 00:00:00.000000000 Z
11
+ date: 2016-02-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: |
14
- Decorates command line output with ANSI escape sequence.
15
- Text that output by "print, puts, p" method is decorated.
16
- It is also can to decorate only your specified words!
13
+ description: Decorates command line output with ANSI escape sequence. http://colorecho.net
17
14
  email:
18
15
  - khotta116@gmail.com
19
16
  executables:
@@ -35,6 +32,7 @@ files:
35
32
  - lib/color_echo/module/off.rb
36
33
  - lib/color_echo/module/textattr.rb
37
34
  - lib/color_echo/override.rb
35
+ - lib/color_echo/private_task.rb
38
36
  - lib/color_echo/variables.rb
39
37
  homepage: http://colorecho.net
40
38
  licenses:
@@ -60,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
58
  version: '0'
61
59
  requirements: []
62
60
  rubyforge_project:
63
- rubygems_version: 2.5.1
61
+ rubygems_version: 2.4.5.1
64
62
  signing_key:
65
63
  specification_version: 4
66
64
  summary: Decorates command line output with ANSI escape sequence.