everyday-cli-utils 0.3.0 → 0.4.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8afc8c7cdc6d4d3adffcc15723afa531d4961533
|
4
|
+
data.tar.gz: de9412ebd7b3965986e8fb66821ac94b3057a429
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ba0851f31eee49fa57b74dc5b7e5999a34ebfccd56ca9e8b3446452d8f93ae5ae8dbd1f4e2d5a4f42186df2ce44050f30da8d5d93cffb6f43e1feadd8cd6d8e
|
7
|
+
data.tar.gz: 656476dd69d7b17479d4aba60904a6d3685fac59461f73b9759a4929643e11fac61785a57f85c258b17a47950653b55953a0b2d775b90f6ace73519ba29d66c8
|
@@ -19,4 +19,8 @@ class String
|
|
19
19
|
colors = 'black|red|green|yellow|blue|purple|cyan|white|none'
|
20
20
|
(!(name =~ /format(_bold)?(_underline)?(?:_fg_(#{colors}))?(?:_bg_(#{colors}))?/).nil?) || old_respond_to?(method)
|
21
21
|
end
|
22
|
+
|
23
|
+
def format_all
|
24
|
+
EverydayCliUtils::Format::format_all(self)
|
25
|
+
end
|
22
26
|
end
|
@@ -103,5 +103,19 @@ module EverydayCliUtils
|
|
103
103
|
def self::boldunderline(text, fgcolor = nil, bgcolor = nil)
|
104
104
|
self::format(text, self::build_string(true, true, fgcolor, bgcolor))
|
105
105
|
end
|
106
|
+
|
107
|
+
def self::format_all(text)
|
108
|
+
colors = 'bk|rd|gr|yw|bl|pu|cy|wh|no'
|
109
|
+
color_map = { 'bk' => :black, 'rd' => :red, 'gr' => :green, 'yw' => :yellow, 'bl' => :blue, 'pu' => :purple, 'cy' => :cyan, 'wh' => :white, 'no' => :none }
|
110
|
+
regex = /\{(.+?)\}\((bd)?(ul)?(?:f(#{colors}))?(?:b(#{colors}))?\)/
|
111
|
+
text.gsub(regex) { |m|
|
112
|
+
txt = $1
|
113
|
+
bold = !$2.nil?
|
114
|
+
underline = !$3.nil?
|
115
|
+
fg = $4.nil? ? nil : color_map[$4]
|
116
|
+
bg = $5.nil? ? nil : color_map[$5]
|
117
|
+
format(txt, build_string(bold, underline, fg, bg))
|
118
|
+
}
|
119
|
+
end
|
106
120
|
end
|
107
121
|
end
|
@@ -61,4 +61,10 @@ describe EverydayCliUtils::Format do
|
|
61
61
|
str.respond_to?(:hi).should be_false
|
62
62
|
expect { str.hi }.to raise_error(NameError)
|
63
63
|
end
|
64
|
+
|
65
|
+
it 'allows shorthand for formatting in-string' do
|
66
|
+
str = 'abc {def}(bdulfywbgr) ghi {jkl}(ulfyw) mno'
|
67
|
+
expected = "abc #{'def'.format_bold_underline_fg_yellow_bg_green} ghi #{'jkl'.format_underline_fg_yellow} mno"
|
68
|
+
str.format_all.should eq expected
|
69
|
+
end
|
64
70
|
end
|