fun_with_string_colors 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/lib/fun_with/string_colors/string_paint_inclusions.rb +30 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjE1MjhiZTZlNDg2MGNmOWQxNGIzYTA2ZTcwOWM2ODZkM2Q0NGZjNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWRiMDU5MzI1OWYzZjNlOTJlODI2NjcwNGNkYWI5YmY0NjY1NTk4Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmNlNTQyYjA1ZDc2NTAxODZlN2EzNWMzMDI2NTUwN2MyODVkNTk2ZTFiM2Ix
|
10
|
+
YTc2ZjA2MzY5YWRkNzM4MjRlYTNmNzg3ODBiOTYyZTU4ZGE1MGRlODc4MTAz
|
11
|
+
MmExYjg4ZDdmZGMwYTg2ZmZiZjgxMGRlMDM5Y2I1MzRlMGUxNTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTAzNTQ2MjBiZWQ3MzU2ODcyNDFlOGM0YWE3ZDM3MDgzOTQyMzE0MGY5MWIz
|
14
|
+
ZTc1M2RmYWZmZTU3Y2M4ZTZjNGIzYzEwMWUwNWMzMDlhNzI1MWNkNDk1ZTdi
|
15
|
+
ODU2NjA4MGUxOGJhMTJlYmRkNDkzNzkxN2QwMWZhYjc3ZWI1NTY=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -50,33 +50,15 @@ module FunWith
|
|
50
50
|
highlight_regex = colors.first.is_a?(Regexp) ? colors.shift : nil
|
51
51
|
|
52
52
|
rval = self.dup
|
53
|
-
prependers
|
54
|
-
|
55
|
-
|
56
|
-
for color in colors
|
57
|
-
case color
|
58
|
-
when :reset, :unpaint
|
59
|
-
regex = /\e\[\d+m/
|
60
|
-
rval = rval.gsub( regex, '' )
|
61
|
-
prependers = []
|
62
|
-
terminations = []
|
63
|
-
when Symbol
|
64
|
-
if ANSI_COLORS[color]
|
65
|
-
prependers << "\e[#{ANSI_COLORS[color]}m"
|
66
|
-
terminations << (ANSI_COLOR_TERMINATORS[color] || ANSI_COLOR_TERMINATORS[:color])
|
67
|
-
end
|
68
|
-
when /^\d+$/, Integer # you can give numbers/number strings directly
|
69
|
-
prependers << "\e[#{ANSI_COLORS[color] || color}m"
|
70
|
-
terminations << (ANSI_COLOR_TERMINATORS[color.to_i] || ANSI_COLOR_TERMINATORS[:color])
|
71
|
-
end
|
72
|
-
end
|
53
|
+
prependers, terminations, reset = self.fwsc_map_color_args_to_prepend_and_terminate( colors )
|
54
|
+
rval = rval.gsub( /\e\[\d+m/, '' ) if reset
|
73
55
|
|
74
56
|
if highlight_regex.nil?
|
75
57
|
#puts "prependers #{prependers.inspect}"
|
76
58
|
#puts "terminations #{terminations.inspect}"
|
77
|
-
prependers.join + rval + terminations.join
|
59
|
+
prependers.uniq.join + rval + terminations.uniq.join
|
78
60
|
else
|
79
|
-
rval.gsub( /(#{highlight_regex})/, prependers.join + "\\1" + terminations.join )
|
61
|
+
rval.gsub( /(#{highlight_regex})/, prependers.uniq.join + "\\1" + terminations.uniq.join )
|
80
62
|
end
|
81
63
|
else
|
82
64
|
self.dup # Since it returns a duplicate of the original when in paint mode, this is more consistent behavior
|
@@ -86,6 +68,32 @@ module FunWith
|
|
86
68
|
def paint?
|
87
69
|
self.class.colorize?
|
88
70
|
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
def fwsc_map_color_args_to_prepend_and_terminate( colors )
|
74
|
+
prependers = []
|
75
|
+
terminations = []
|
76
|
+
reset = false
|
77
|
+
|
78
|
+
for color in colors
|
79
|
+
case color
|
80
|
+
when :reset, :unpaint
|
81
|
+
prependers = []
|
82
|
+
terminations = []
|
83
|
+
reset = true
|
84
|
+
when Symbol
|
85
|
+
if ANSI_COLORS[color]
|
86
|
+
prependers << "\e[#{ANSI_COLORS[color]}m"
|
87
|
+
terminations << (ANSI_COLOR_TERMINATORS[color] || ANSI_COLOR_TERMINATORS[:color])
|
88
|
+
end
|
89
|
+
when /^\d+$/, Integer # you can give numbers/number strings directly
|
90
|
+
prependers << "\e[#{ANSI_COLORS[color] || color}m"
|
91
|
+
terminations << (ANSI_COLOR_TERMINATORS[color.to_i] || ANSI_COLOR_TERMINATORS[:color])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
[prependers, terminations, reset]
|
96
|
+
end
|
89
97
|
end
|
90
98
|
end
|
91
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fun_with_string_colors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fun_with_testing
|