color_echo 0.2.3 → 0.2.4

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: d7d3a8d427f0500c579883ec1383e41f925a3d29
4
- data.tar.gz: fe121aaf4ccf3b4e47df7c416c8a6629b0b9798c
3
+ metadata.gz: 5ec85d1bace70cdff14ecc1ce007aa998ce2c3c6
4
+ data.tar.gz: f0f58f7f2b30dfc534071597787ba1fc243ff1aa
5
5
  SHA512:
6
- metadata.gz: 4b37774a01401322360023eba2f8af2fa1a48a0982eb6ae14c0ec96f8567b0351605ac0ccca55cf1af1f9ebbdc5eee55bb1ed9da2b1f8f127b991b1e16780a70
7
- data.tar.gz: ad2b93edfe490738e6e73e3a26372df536a73c7b1328410176a38e60c951c2cfa759798759f22925838dd22a529b60ee1b8c7802fa971d23c38aa715f5bde2ac
6
+ metadata.gz: 613d899d95e99406f59b89508cacc0666c52ba7a44daef6967c16ecc2c14beae2c1f16c266fb9969af6a659f1f01509a835b68af82e6e927978c832d46b3d8c6
7
+ data.tar.gz: 6fbe68a495bd36b09461ceecefe60e73d66652e55564fce43b3000fc7d3d8546b796802195eea08ddd80c9bd768badc8cc13a379feb894af6e8049946ddb4f79
data/README.md CHANGED
@@ -3,7 +3,7 @@ To add color to the command line output.
3
3
  This Library will extend the Kernel module's functions(#print, #puts, #p).
4
4
  required StringIO.
5
5
 
6
- Version: 0.2.3
6
+ Version: 0.2.4
7
7
  Compliant Rubys Version: 1.9.3, 2.0.0, 2.1.0 (for Linux)
8
8
  License: MIT
9
9
  Gems repository: http://rubygems.org/gems/color_echo
@@ -86,8 +86,8 @@ This method is available in version 0.1.0 on and after.
86
86
 
87
87
  #### CE.rainbow
88
88
  Text color will change to rainbow color.
89
- String Object only.
90
- Non-string object is excluded.
89
+ ~~String Object only. Non-string object is excluded.~~ ->
90
+ Be able to specify a non-string when rainbow mode at version 0.2.4 on and after.
91
91
  This method is available in version 0.2.0 on and after.
92
92
 
93
93
  ### Example
@@ -160,6 +160,13 @@ sed do eiusmod tempor incididunt
160
160
  ut labore et dolore magna aliqua.
161
161
  EOM
162
162
 
163
+ CE.tx :underscore
164
+ CE.bg :black
165
+ CE.rainbow
166
+ hash = {:foo => [111, 222, 333], :bar => {:str => String}}
167
+ p hash
168
+ p "fooooooo", ["AAA", "BBB", "CCC"]
169
+
163
170
  CE.off
164
171
  puts "Disable rainbow mode."
165
172
  ```
@@ -170,4 +177,9 @@ puts "Disable rainbow mode."
170
177
 
171
178
 
172
179
  ## Release Note
173
- * v0.2.3, 2014-12-02, Fixed small bugs.
180
+ * v0.2.3, 2014-12-02
181
+ * Fixed small bugs.
182
+
183
+ * v0.2.4, 2014-12-04
184
+ * Be able to specify a non-string when rainbow mode.
185
+ * Be able to take over the setting of other types of sequence when rainbow mode.
@@ -1,28 +1,36 @@
1
1
  module CE
2
+ # @return bool
2
3
  def available?
3
4
  return @@enable && @@isset
4
5
  end
5
6
 
7
+ # @return bool
6
8
  def isset?
7
9
  return @@isset
8
10
  end
9
11
 
12
+ # @return bool
10
13
  def enable?
11
14
  return @@enable
12
15
  end
13
16
 
17
+ # @return void
14
18
  def unuse
15
19
  @@enable = false
16
20
  end
17
21
 
22
+ # @return void
18
23
  def reset
19
24
  @@isset = false
20
25
  @@rainbow = false
21
26
  @@code_bg_color = ""
22
27
  @@code_fg_color = ""
23
28
  @@code_text_attr = ""
29
+ @@code_rainbow = ""
24
30
  end
25
31
 
32
+ # @param Symbol name
33
+ # @return void
26
34
  def ch_fg(name)
27
35
  return nil if !name.instance_of?(Symbol)
28
36
  @@isset = true if !@@isset
@@ -30,6 +38,8 @@ module CE
30
38
  @@code_fg_color = convert_to_code("ForeGround", name)
31
39
  end
32
40
 
41
+ # @param Symbol name
42
+ # @return void
33
43
  def ch_bg(name)
34
44
  return nil if !name.instance_of?(Symbol)
35
45
  @@isset = true if !@@isset
@@ -37,6 +47,8 @@ module CE
37
47
  @@code_bg_color = convert_to_code("BackGround", name)
38
48
  end
39
49
 
50
+ # @param Symbol name
51
+ # @return void
40
52
  def ch_tx(name)
41
53
  return nil if !name.instance_of?(Symbol)
42
54
  @@isset = true if !@@isset
@@ -44,64 +56,89 @@ module CE
44
56
  @@code_text_attr = convert_to_code("TextAttr", name)
45
57
  end
46
58
 
59
+ # @param Symbol fg
60
+ # @param Symbol bg
61
+ # @param Symbol tx
62
+ # @return void
47
63
  def ch(fg, bg=nil, tx=nil)
48
64
  ch_fg(fg)
49
65
  ch_bg(bg)
50
66
  ch_tx(tx)
51
67
  end
52
68
 
69
+ # return start color sequence code
70
+ # @return String
53
71
  def get_start_code
54
- return @@code_fg_color + @@code_bg_color + @@code_text_attr
72
+ if @@rainbow
73
+ return @@code_rainbow
74
+ else
75
+ return @@code_fg_color + @@code_bg_color + @@code_text_attr
76
+ end
55
77
  end
56
78
 
79
+ # @return String
57
80
  def get_reset_code
58
81
  return self::CODE_RESET
59
82
  end
60
83
 
61
84
  # add reset & start code to line feed code
85
+ # @param String input
62
86
  def add_reset_line_feed(input)
63
87
  input.gsub!(/#{$/}/, CE::get_reset_code + $/ + CE::get_start_code)
64
88
  input += CE::get_reset_code
65
89
  return input
66
90
  end
67
91
 
92
+ # change mode to rainbow
93
+ # @return void
68
94
  def rainbow
69
- @@isset = true if !@@isset
70
- @@rainbow = true
95
+ @@isset = true if !@@isset
96
+ @@rainbow = true
97
+ @@code_rainbow = @@code_bg_color + @@code_text_attr
71
98
  end
72
99
 
100
+ # add code to be a rainbow color
101
+ # @param String text
102
+ # @return String
73
103
  def add_rainbow(text)
74
104
  cnt = 0
75
- output = ""
105
+ output = get_start_code
106
+
76
107
  text.each_char do |char|
77
108
  if char == $/
78
- output += $/
109
+ output += get_reset_code + $/ + get_start_code
79
110
  next
80
111
  end
81
112
 
82
113
  case cnt
83
114
  when 0
84
- output += ForeGround::RED + char + CODE_RESET
115
+ output += ForeGround::RED + char + CODE_RESET + get_start_code
85
116
  when 1
86
- output += ForeGround::GREEN + char + CODE_RESET
117
+ output += ForeGround::GREEN + char + CODE_RESET + get_start_code
87
118
  when 2
88
- output += ForeGround::YELLOW + char + CODE_RESET
119
+ output += ForeGround::YELLOW + char + CODE_RESET + get_start_code
89
120
  when 3
90
- output += ForeGround::BLUE + char + CODE_RESET
121
+ output += ForeGround::BLUE + char + CODE_RESET + get_start_code
91
122
  when 4
92
- output += ForeGround::MAGENTA + char + CODE_RESET
123
+ output += ForeGround::MAGENTA + char + CODE_RESET + get_start_code
93
124
  when 5
94
- output += ForeGround::CYAN + char + CODE_RESET
125
+ output += ForeGround::CYAN + char + CODE_RESET + get_start_code
95
126
  when 6
96
- output += ForeGround::WHITE + char + CODE_RESET
127
+ output += ForeGround::WHITE + char + CODE_RESET + get_start_code
97
128
  end
98
129
  cnt += 1
99
130
  cnt = 0 if cnt >= 7
100
131
  end
101
132
 
133
+ output += get_reset_code
134
+
102
135
  return output
103
136
  end
104
137
 
138
+ # get sequence code by symbol
139
+ # @param String module_name
140
+ # @param Symbol name
141
+ # @return String
105
142
  def convert_to_code(module_name, name)
106
143
  begin
107
144
  code = eval(%{#{module_name}::#{name.to_s.swapcase!}})
@@ -111,6 +148,7 @@ module CE
111
148
  return code
112
149
  end
113
150
 
151
+ # @return Proc
114
152
  def task
115
153
  return @@task
116
154
  end
@@ -121,10 +159,15 @@ module CE
121
159
  :isset?,
122
160
  :enable?,
123
161
  :unuse,
124
- :reset, :off, :disable,
125
- :ch_fg, :fg,
126
- :ch_bg, :bg,
127
- :ch_tx, :tx,
162
+ :reset,
163
+ :off,
164
+ :disable,
165
+ :ch_fg,
166
+ :fg,
167
+ :ch_bg,
168
+ :bg,
169
+ :ch_tx,
170
+ :tx,
128
171
  :ch,
129
172
  :get_start_code,
130
173
  :get_reset_code,
@@ -4,6 +4,7 @@ module CE
4
4
  @@code_bg_color = ""
5
5
  @@code_fg_color = ""
6
6
  @@code_text_attr = ""
7
+ @@code_rainbow = ""
7
8
  @@rainbow = false
8
9
 
9
10
  @@print = method :print
@@ -12,35 +13,23 @@ module CE
12
13
 
13
14
  @@task = lambda do |*arg|
14
15
  if available?
15
- if @@rainbow && arg.first.instance_of?(String)
16
- # change output destination to StringIO Object
17
- strio = StringIO.new
18
- $stdout = strio
16
+ # change output destination to StringIO Object
17
+ strio = StringIO.new
18
+ $stdout = strio
19
19
 
20
- # call original method
21
- eval("@@#{caller_locations(2).first.label}").call(*arg)
20
+ # output color sequence
21
+ $stdout.print get_start_code if !@@rainbow
22
22
 
23
- # change output destination to STDOUT
24
- $stdout = STDOUT
23
+ # call original method
24
+ eval("@@#{caller_locations(2).first.label}").call(*arg)
25
25
 
26
- # output to STDOUT
27
- $stdout.print add_rainbow(strio.string)
26
+ # change output destination to STDOUT
27
+ $stdout = STDOUT
28
28
 
29
+ # output to STDOUT
30
+ if @@rainbow
31
+ $stdout.print add_rainbow(strio.string)
29
32
  else
30
- # change output destination to StringIO Object
31
- strio = StringIO.new
32
- $stdout = strio
33
-
34
- # output color sequence
35
- $stdout.print get_start_code
36
-
37
- # call original method
38
- eval("@@#{caller_locations(2).first.label}").call(*arg)
39
-
40
- # change output destination to STDOUT
41
- $stdout = STDOUT
42
-
43
- # output to STDOUT
44
33
  $stdout.print add_reset_line_feed(strio.string)
45
34
  end
46
35
 
@@ -1,3 +1,3 @@
1
1
  module CE
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
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: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - nyanko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'To add color to the command line output.This Library will extend the
14
14
  Kernel module''s functions(#print, #puts, #p). required StringIO.'