inkjet 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/inkjet/colors.rb +18 -18
- data/lib/inkjet/string.rb +53 -58
- data/lib/inkjet/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4af8afe6467c85adc6846dad80f5358ae21af5a
|
4
|
+
data.tar.gz: c85db1efd92d913881477a74f08bea7e4afaca06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e04395528ab2ac80135d801afb883c9d2df2d950d8dd99716bce72c816bc17b4cdc412fc1157dc75c20521695a4bcaa79a60179b127cda9cdaf80e2ee45a234
|
7
|
+
data.tar.gz: 3e65522f8da9e88f79cad5d568ea9ba061d6b36e01e9b8cddab01f739717b16c0751fbaacc7d35e314c4962bc967f8fd9a664f55f14cf7cbd68e028ebc126745
|
data/lib/inkjet/colors.rb
CHANGED
@@ -40,37 +40,37 @@ module Inkjet
|
|
40
40
|
base.send :extend, self
|
41
41
|
end
|
42
42
|
|
43
|
-
def colorize(color, str)
|
44
|
-
colorize!(color, str.clone)
|
43
|
+
def colorize(color, str, wrap=false)
|
44
|
+
colorize!(color, str.clone, wrap)
|
45
45
|
end
|
46
46
|
|
47
|
-
def colorize!(color, str)
|
48
|
-
str.apply_inkjet_code!(Inkjet::Colors.foreground(color))
|
47
|
+
def colorize!(color, str, wrap=false)
|
48
|
+
str.apply_inkjet_code!(Inkjet::Colors.foreground(color), wrap)
|
49
49
|
end
|
50
50
|
|
51
|
-
def colorize_background(color, str)
|
52
|
-
colorize_background!(color, str.clone)
|
51
|
+
def colorize_background(color, str, wrap=false)
|
52
|
+
colorize_background!(color, str.clone, wrap)
|
53
53
|
end
|
54
54
|
|
55
|
-
def colorize_background!(color, str)
|
56
|
-
str.apply_inkjet_code!(Inkjet::Colors.background(color))
|
55
|
+
def colorize_background!(color, str, wrap=false)
|
56
|
+
str.apply_inkjet_code!(Inkjet::Colors.background(color), wrap)
|
57
57
|
end
|
58
58
|
|
59
|
-
def colorize_with_background(fg_color, bg_color, str)
|
60
|
-
colorize_with_background!(fg_color, bg_color, str.clone)
|
59
|
+
def colorize_with_background(fg_color, bg_color, str, wrap=false)
|
60
|
+
colorize_with_background!(fg_color, bg_color, str.clone, wrap)
|
61
61
|
end
|
62
62
|
|
63
|
-
def colorize_with_background!(fg_color, bg_color, str)
|
64
|
-
str.apply_inkjet_codes!(Inkjet::Colors.foreground(fg_color), Inkjet::Colors.background(bg_color))
|
63
|
+
def colorize_with_background!(fg_color, bg_color, str, wrap=false)
|
64
|
+
str.apply_inkjet_codes!([Inkjet::Colors.foreground(fg_color), Inkjet::Colors.background(bg_color)], wrap)
|
65
65
|
end
|
66
66
|
|
67
67
|
def method_missing(meth, *args)
|
68
68
|
if meth.match(/\A(#{Inkjet::Colors::Colors.push("default").join("|")})_text(!?)\Z/)
|
69
|
-
colorize($1, args
|
69
|
+
colorize($1, *args)#.map(&:to_s).join(" "))
|
70
70
|
elsif meth.match(/\A(#{Inkjet::Colors::Colors.push("default").join("|")})_(background|bg)(!?)\Z/)
|
71
|
-
colorize_background($1, args
|
71
|
+
colorize_background($1, *args)#.map(&:to_s).join(" "))
|
72
72
|
elsif meth.match(/\A(#{Inkjet::Colors::Colors.push("default").join("|")})_(#{Inkjet::Colors::Colors.push("default").join("|")})(!?)\Z/)
|
73
|
-
colorize_with_background($1, $2, args
|
73
|
+
colorize_with_background($1, $2, *args)#.map(&:to_s).join(" "))
|
74
74
|
else
|
75
75
|
super
|
76
76
|
end
|
@@ -80,11 +80,11 @@ module Inkjet
|
|
80
80
|
module String
|
81
81
|
def method_missing(meth, *args)
|
82
82
|
if meth.match(/\A(#{Inkjet::Colors::Colors.join("|")})(!?)\Z/)
|
83
|
-
Inkjet.send("colorize#{$2}", $1, self)
|
83
|
+
Inkjet.send("colorize#{$2}", $1, self, *args)
|
84
84
|
elsif meth.match(/\A(#{Inkjet::Colors::Colors.join("|")})_(background|bg)(!?)\Z/)
|
85
|
-
Inkjet.send("colorize_background#{$3}", $1, self)
|
85
|
+
Inkjet.send("colorize_background#{$3}", $1, self, *args)
|
86
86
|
elsif meth.match(/\A(#{Inkjet::Colors::Colors.join("|")})_(#{Inkjet::Colors::Colors.join("|")})(!?)\Z/)
|
87
|
-
Inkjet.send("colorize_with_background#{$3}", $1, $2, self)
|
87
|
+
Inkjet.send("colorize_with_background#{$3}", $1, $2, self, *args)
|
88
88
|
else
|
89
89
|
super
|
90
90
|
end
|
data/lib/inkjet/string.rb
CHANGED
@@ -1,85 +1,80 @@
|
|
1
1
|
module Inkjet
|
2
2
|
module String
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
|
4
|
+
def method_missing(meth, *args)
|
5
|
+
if meth.match(/(#{%w(bold dim underline blink invert hidden).join('|')})(!?)/)
|
6
|
+
send "apply_inkjet_code#{$2}", "Inkjet::#{meth.capitalize}".constantize, *args
|
7
|
+
else
|
8
|
+
super
|
9
|
+
end
|
9
10
|
end
|
10
|
-
|
11
|
-
def
|
12
|
-
clone.
|
11
|
+
|
12
|
+
def clean
|
13
|
+
clone.clean!
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
-
|
16
|
+
def clean!
|
17
|
+
gsub!(/\e\[[\d;]+m/, '')
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
clone.
|
20
|
+
def apply_inkjet_code(code, wrap=false)
|
21
|
+
clone.apply_inkjet_code!(code, wrap)
|
21
22
|
end
|
22
23
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def apply_inkjet_code!(code, wrap=false)
|
25
|
+
if inkjet_strings.length > 0
|
26
|
+
replace(inkjet_strings.map do |istr|
|
27
|
+
if wrap # apply the code to every chunk within the string, formatted or unformatted
|
28
|
+
|
29
|
+
(istr[0].empty? ? "" : apply_inkjet_codes_to_substring([code], istr[0])) +
|
30
|
+
apply_inkjet_codes_to_substring(istr[1].push(code), istr[2]) +
|
31
|
+
(istr[3].empty? ? "" : apply_inkjet_codes_to_substring([code], istr[3]))
|
32
|
+
|
33
|
+
elsif !inkjet_codes.empty? && istr[1] == inkjet_codes # apply the code only to the formatted chunks of the 'primary string'
|
34
|
+
|
35
|
+
istr[0] + apply_inkjet_codes_to_substring(istr[1].push(code), istr[2]) + istr[3]
|
36
|
+
|
37
|
+
else # apply the code only to the unformatted chunks of the 'primary string' leaving any formatted substrings untouched
|
38
|
+
|
39
|
+
(istr[0].empty? ? "" : apply_inkjet_codes_to_substring([code], istr[0])) +
|
40
|
+
apply_inkjet_codes_to_substring(istr[1], istr[2]) +
|
41
|
+
(istr[3].empty? ? "" : apply_inkjet_codes_to_substring([code], istr[3]))
|
42
|
+
|
43
|
+
end
|
44
|
+
end.join(""))
|
45
|
+
else # wrap the entire unformatted string w/ the code
|
46
|
+
replace("\e[#{code}m#{self}\e[#{Inkjet::Close}m")
|
47
|
+
end
|
29
48
|
end
|
30
49
|
|
31
|
-
def
|
32
|
-
|
50
|
+
def apply_inkjet_codes(codes, wrap=false)
|
51
|
+
cloned = clone
|
52
|
+
codes.each { |code| cloned.apply_inkjet_code!(code, wrap) }
|
53
|
+
cloned
|
33
54
|
end
|
34
55
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def invert!
|
40
|
-
apply_inkjet_code!(Inkjet::Invert)
|
56
|
+
def apply_inkjet_codes!(codes, wrap=false)
|
57
|
+
codes.each { |code| apply_inkjet_code!(code, wrap) }
|
58
|
+
self
|
41
59
|
end
|
42
60
|
|
43
|
-
|
44
|
-
clone.hidden!
|
45
|
-
end
|
61
|
+
protected
|
46
62
|
|
47
|
-
|
48
|
-
apply_inkjet_code!(Inkjet::Hidden)
|
49
|
-
end
|
50
|
-
|
63
|
+
# return the first set of escape codes found in the string if no pre-string
|
51
64
|
def inkjet_codes
|
52
|
-
|
65
|
+
inkjet_strings.first[0].empty? ? inkjet_strings.first[1] : []
|
53
66
|
rescue
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
def apply_inkjet_code(code)
|
58
|
-
clone.apply_inkjet_code!(c)
|
67
|
+
[]
|
59
68
|
end
|
60
69
|
|
61
|
-
def
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
def apply_inkjet_codes(*codes)
|
66
|
-
sclone = clone
|
67
|
-
codes.each { |code| sclone.apply_inkjet_code!(code) }
|
68
|
-
sclone
|
69
|
-
end
|
70
|
-
|
71
|
-
def apply_inkjet_codes!(*codes)
|
72
|
-
codes.each { |code| apply_inkjet_code!(code) }
|
73
|
-
self
|
70
|
+
def inkjet_strings
|
71
|
+
scan(/([^\e]*)\e\[([\d;]+)m([^\e]*)\e\[#{Inkjet::Close}m([^\e]*)/).map { |pre,codes,str,post| [pre, codes.split(";"), str, post] } # TODO make a class for these
|
74
72
|
end
|
75
73
|
|
76
|
-
def
|
77
|
-
|
74
|
+
def apply_inkjet_codes_to_substring(codes, substr)
|
75
|
+
"\e[#{codes.join(";")}m#{substr}\e[#{Inkjet::Close}m"
|
78
76
|
end
|
79
77
|
|
80
|
-
def clean!
|
81
|
-
gsub!(/\e\[[\d;]+m/, '')
|
82
|
-
end
|
83
78
|
end
|
84
79
|
end
|
85
80
|
|
data/lib/inkjet/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inkjet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|