fun_with_string_colors 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.markdown +14 -0
- data/README.rdoc +17 -7
- data/VERSION +1 -1
- data/lib/fun_with/string_colors/string_paint_inclusions.rb +24 -8
- data/test/test_fun_with_string_colors.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjZhNjlhZDM0MmFkYTg1NjhmOGU3MmI0NjcyMDVlNTY0ZjlmZWRjMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWNjZDhiZWQ2MWFjYmY1MDk2YmJjOGVkMmYxOWEzNDE2ZmRkOTIyZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDI5NzJiNmU2M2E2ZTgyMWU2NGY4ZTFhMzE4YzY1OWZkNTk2OGU1ZDkzOTc5
|
10
|
+
MmJjZmQyNjg0NzljYjNkNWZhZGQzMDJhMWI2NGE1ZWQ0OGM5ZDIzM2M0NzE2
|
11
|
+
M2JmNTMzMTFiNmYwMmJkMjE1OWJkMTk4MDFmZjhhNjc0MGRlNWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Njg3OGM2ZmZlZmRiOGI3Nzc5OTU1ZDc4ZTI4MDhlZTYwMDExYzVjNWI5MjQ3
|
14
|
+
OTFhYmQxODJmY2Y1NmQ2MTQxMGQ2YzE0M2FhY2Y5MWU1YmIwNDQ4MDE4MzUz
|
15
|
+
ZDI1NzZmN2Y2M2Y2MjcwMTJiYmZhMTAwNjBlOWMwZmJkMjNiNDU=
|
data/CHANGELOG.markdown
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
0.0.3
|
2
|
+
-----
|
3
|
+
|
4
|
+
Changed the internals around, added regex highlighting functionality. See examples in README.rdoc.
|
5
|
+
|
6
|
+
0.0.2
|
7
|
+
-----
|
8
|
+
|
9
|
+
Expanded lexicon of decorations. All hail the `<blink>` tag! Removed a couple of methods.
|
10
|
+
|
11
|
+
0.0.1
|
12
|
+
-----
|
13
|
+
|
14
|
+
Initial public offering. Get in while the getting is good.
|
data/README.rdoc
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
= fun_with_string_colors
|
2
2
|
|
3
|
-
Paint your strings for prettier console output
|
4
|
-
|
5
|
-
require '
|
6
|
-
|
7
|
-
FunWith::StringColors.activate
|
8
|
-
String.colorize( true )
|
9
|
-
|
3
|
+
Paint your strings for prettier console output. Behold! The Code of Exampleage!
|
4
|
+
|
5
|
+
require 'fun_with_string_colors'
|
6
|
+
|
7
|
+
FunWith::StringColors.activate # imports functions into String
|
8
|
+
String.colorize( true ) # Yes, we want those functions to add color codes to strings.
|
9
|
+
String.colorize( STDOUT.tty? ) # only alter strings if we're in TTY (console)
|
10
|
+
|
11
|
+
puts "Hello World".paint(:pink) # Pretty shiny!
|
12
|
+
puts "Hello World".paint(:bg_red, :blue, :bold, :underline, :blink) # An affront to God and Man, I tells ya.
|
13
|
+
|
14
|
+
# If your first arg to .paint() is a regular expression, only the matches will be colored in. Useful!
|
15
|
+
puts "Hello World".paint(/hello/i, :bg_red).paint(/world/i, :bg_blue, :reverse, :underline)
|
16
|
+
String.paint? # Is painting active?
|
17
|
+
"".paint? # Same question. One setting controls all strings.
|
18
|
+
|
19
|
+
puts String::ANSI_COLORS.keys.inspect # What symbols does paint recognize?
|
10
20
|
|
11
21
|
|
12
22
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -36,12 +36,21 @@ module FunWith
|
|
36
36
|
:reverse => "\e[27m",
|
37
37
|
7 => "\e[27m",
|
38
38
|
:bold => "\e[22m",
|
39
|
-
1 => "\e[22m"
|
39
|
+
1 => "\e[22m",
|
40
|
+
:color => "\e[0m"
|
40
41
|
}
|
41
42
|
|
43
|
+
# Note: use :reset and :unpaint in isolation (no other args). It will nullify everything prior.
|
42
44
|
def paint( *colors )
|
43
45
|
if paint?
|
46
|
+
# debugger if colors.first == "95"
|
47
|
+
# puts "\e[27m\e[0m\e[22mcalling paint(*#{colors.inspect})"
|
48
|
+
|
49
|
+
colors.flatten!
|
50
|
+
highlight_regex = colors.first.is_a?(Regexp) ? colors.shift : nil
|
51
|
+
|
44
52
|
rval = self.dup
|
53
|
+
prependers = []
|
45
54
|
terminations = []
|
46
55
|
|
47
56
|
for color in colors
|
@@ -49,21 +58,28 @@ module FunWith
|
|
49
58
|
when :reset, :unpaint
|
50
59
|
regex = /\e\[\d+m/
|
51
60
|
rval = rval.gsub( regex, '' )
|
61
|
+
prependers = []
|
52
62
|
terminations = []
|
53
63
|
when Symbol
|
54
64
|
if ANSI_COLORS[color]
|
55
|
-
|
56
|
-
terminations << (ANSI_COLOR_TERMINATORS[color] ||
|
65
|
+
prependers << "\e[#{ANSI_COLORS[color]}m"
|
66
|
+
terminations << (ANSI_COLOR_TERMINATORS[color] || ANSI_COLOR_TERMINATORS[:color])
|
57
67
|
end
|
58
68
|
when /^\d+$/, Integer # you can give numbers/number strings directly
|
59
|
-
|
60
|
-
terminations << (ANSI_COLOR_TERMINATORS[color.to_i] ||
|
69
|
+
prependers << "\e[#{ANSI_COLORS[color] || color}m"
|
70
|
+
terminations << (ANSI_COLOR_TERMINATORS[color.to_i] || ANSI_COLOR_TERMINATORS[:color])
|
61
71
|
end
|
62
72
|
end
|
63
|
-
|
64
|
-
|
73
|
+
|
74
|
+
if highlight_regex.nil?
|
75
|
+
#puts "prependers #{prependers.inspect}"
|
76
|
+
#puts "terminations #{terminations.inspect}"
|
77
|
+
prependers.join + rval + terminations.join
|
78
|
+
else
|
79
|
+
rval.gsub( /(#{highlight_regex})/, prependers.join + "\\1" + terminations.join )
|
80
|
+
end
|
65
81
|
else
|
66
|
-
self
|
82
|
+
self.dup # Since it returns a duplicate of the original when in paint mode, this is more consistent behavior
|
67
83
|
end
|
68
84
|
end
|
69
85
|
|
@@ -38,4 +38,16 @@ class TestFunWithStringColors < FunWith::StringColors::TestCase
|
|
38
38
|
should "not alter output when .paint() receives nil/unrecognized" do
|
39
39
|
assert_equal "hello", "hello".paint(nil)
|
40
40
|
end
|
41
|
+
|
42
|
+
should "highlight!" do
|
43
|
+
str = "Should highlight the number in brackets: 0 1 2 3 (4) 5"
|
44
|
+
puts str.paint( /4/, :bg_red, :bold )
|
45
|
+
|
46
|
+
str = "Should highlight the numbers in brackets: 0 1 2 3 (4) 5 6 (7)"
|
47
|
+
puts str.paint( /4/, :bg_red, :bold ).paint( /7/, :bg_blue )
|
48
|
+
|
49
|
+
str = "Should highlight all the numbers: 0 1 2 3 4 5 6 7"
|
50
|
+
puts str.paint( /\d+/, :bg_red, :bold ).paint( /7/, :bg_blue )
|
51
|
+
|
52
|
+
end
|
41
53
|
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.3
|
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-04-
|
11
|
+
date: 2014-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fun_with_testing
|
@@ -34,6 +34,7 @@ extra_rdoc_files:
|
|
34
34
|
- README.rdoc
|
35
35
|
files:
|
36
36
|
- .document
|
37
|
+
- CHANGELOG.markdown
|
37
38
|
- Gemfile
|
38
39
|
- LICENSE.txt
|
39
40
|
- README.rdoc
|