colcolor 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/colcolor.rb +7 -17
- data/lib/colcolor/version.rb +1 -1
- data/spec/colcolor_spec.rb +6 -0
- 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: 2b446b52f24f036ce96faa3871612c17f3c1e283
|
4
|
+
data.tar.gz: 2b86dacefabce35110164cf3a926eaf65d679a90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6892c801857814a2b72b9ee6635b96d999be9364f1015d5166ecacfd5fc770bf67ed8a08384a3c617679ff5972c97199aebd3ebecf3288a6e1f9a7729ce0502
|
7
|
+
data.tar.gz: 0ef2a6ff5fb5946c136a5170e1ad89eb4ba653ace9538e4e4a0af4f1b0ee20839e72b5f15539eff7a16076788987bd879b8ee3fd5dd5d80f9ce5b23b66fdf8ff
|
data/lib/colcolor.rb
CHANGED
@@ -1,23 +1,13 @@
|
|
1
1
|
require "colcolor/version"
|
2
2
|
|
3
3
|
module Colcolor
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
.map { |k,v| [k, "\e[#{v}m"] }
|
8
|
-
].freeze
|
9
|
-
|
10
|
-
BGCOLORS = Hash[
|
11
|
-
%i( black red green yellow blue magenta cyan white )
|
12
|
-
.zip(40..47)
|
13
|
-
.map { |k,v| [k, "\e[#{v}m"] }
|
14
|
-
].freeze
|
4
|
+
def self.TAGMAP(colors, codes)
|
5
|
+
Hash[ colors.zip(codes).map { |k, v| [k, "\e[#{v}m"] } ].freeze
|
6
|
+
end
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
.map { |k,v| [k, "\e[#{v}m"] }
|
20
|
-
].freeze
|
8
|
+
COLORS = TAGMAP( %i(black red green yellow blue magenta cyan white), 30..37)
|
9
|
+
BGCOLORS = TAGMAP( %i( black red green yellow blue magenta cyan white), 40..47)
|
10
|
+
EXTRA = TAGMAP( %i( clear bold underline blink reverse ), [0, 1, 4, 5, 7])
|
21
11
|
|
22
12
|
def colco(*colors, regexp:/\S+/)
|
23
13
|
cs = colors.dup
|
@@ -29,7 +19,7 @@ module Colcolor
|
|
29
19
|
|
30
20
|
private
|
31
21
|
def build_color_tag(name)
|
32
|
-
if tag = COLORS[name] || BGCOLORS[
|
22
|
+
if tag = COLORS[name] || BGCOLORS[name] || EXTRA[name]
|
33
23
|
tag
|
34
24
|
else
|
35
25
|
fore, *ext = name.to_s.split('_').map(&:intern)
|
data/lib/colcolor/version.rb
CHANGED
data/spec/colcolor_spec.rb
CHANGED
@@ -16,6 +16,12 @@ describe Colcolor do
|
|
16
16
|
color_set = [:green, :yellow, :red]
|
17
17
|
expect(@str.colco(*color_set)).to eq expect
|
18
18
|
end
|
19
|
+
|
20
|
+
it "colors background of words" do
|
21
|
+
expect = "\e[42mGeorge\e[0m \e[43m18\e[0m \e[41mguitarist\e[0m"
|
22
|
+
color_set = [:bg_green, :bg_yellow, :bg_red]
|
23
|
+
expect(@str.colco(*color_set)).to eq expect
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
27
|
context "two or more color attributes to a word" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colcolor
|
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
|
- kyoendo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|