colcolor 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e0f1528e02ce7d5dc2f43daf6d4fa700dd656c2
4
- data.tar.gz: 1a546ff89d31b8656046f4cbe0fbd2c41163e3f2
3
+ metadata.gz: 3967e2969a53a7848538f222ce5cb6e5ab9279fc
4
+ data.tar.gz: 410513740a17f7dd0d4f8f9d8e079b79448fe3da
5
5
  SHA512:
6
- metadata.gz: dfbea0605bd114ac7d298243634977a547029093169236ce8dd3bf3764c02cce1fed224b3c3825c7c5cc268999157d0ff81ad90346cdeec0a5677e1702d70d90
7
- data.tar.gz: 05d54f0949d93d39a1791466327a83d0ed1ebc94ffcee825cde620e6d2d33e0f213db3540a53de8ff1524f3e5937ab24f77f2c53bbf285411de89bca4762654c
6
+ metadata.gz: 18e71204f739c47a34b1c79040b1d5c40a8e54fb47e38f58eae22b1af018b7bfa18761543ec8127cecd930f1ad486a1cadce05a79b0c7dfa159bc4eac5498142
7
+ data.tar.gz: 41fe752d50804abd4e462b9714518004c257fe80cdee42dcc37977661627e2ab5daf2a06e43ec88db2579eac257a5daded240ea39550fde32b431d44782f8096
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Colcolor
2
2
 
3
+ [![Build Status](https://travis-ci.org/melborne/colcolor.svg)](https://travis-ci.org/melborne/colcolor)
4
+
3
5
  Easily colorize terminal text by each column.
4
6
 
5
7
  ## Installation
@@ -94,6 +96,19 @@ Output:
94
96
 
95
97
  ![sample4](https://github.com/melborne/colcolor/raw/screenshot/sample4.png)
96
98
 
99
+ If you want to apply colors periodically to a text, set `cyclic` option to true.
100
+
101
+ ```ruby
102
+ "H E L L O W O R L D".colco(:red, :green, :yellow, cycle:true)
103
+
104
+ ```
105
+
106
+ Output:
107
+
108
+
109
+ ![sample5](https://github.com/melborne/colcolor/raw/screenshot/sample5.png)
110
+
111
+
97
112
  ## Contributing
98
113
 
99
114
  1. Fork it ( https://github.com/[my-github-username]/colcolor/fork )
@@ -5,21 +5,23 @@ module Colcolor
5
5
  Hash[ colors.zip(codes).map { |k, v| [k, "\e[#{v}m"] } ].freeze
6
6
  end
7
7
 
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])
8
+ COLORSET = %i(black red green yellow blue magenta cyan white)
9
+ COLORS = TAGMAP(COLORSET, 30..37)
10
+ BGCOLORS = TAGMAP(COLORSET, 40..47)
11
+ EXTRA = TAGMAP(%i(clear bold underline blink reverse), [0,1,4,5,7])
11
12
 
12
- def colco(*colors, regexp:/\S+/)
13
- cs = colors.dup
13
+ def colco(*colors, regexp:/\S+/, cycle:false)
14
+ cs = cycle ? colors.cycle : colors.to_enum
14
15
  self.gsub(regexp) do
15
- color = build_color_tag(cs.shift)
16
+ cname = cs.next rescue nil
17
+ color = build_color_tag(cname)
16
18
  color.empty? ? $& : (color + $& + EXTRA[:clear])
17
19
  end
18
20
  end
19
21
 
20
22
  private
21
23
  def build_color_tag(name)
22
- if tag = COLORS[name] || BGCOLORS[name] || EXTRA[name]
24
+ if tag = COLORS[name] || EXTRA[name]
23
25
  tag
24
26
  else
25
27
  fore, *ext = name.to_s.split('_').map(&:intern)
@@ -1,3 +1,3 @@
1
1
  module Colcolor
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -70,5 +70,14 @@ describe Colcolor do
70
70
  expect(str.colco(*color_set, regexp:re)).to eq expect
71
71
  end
72
72
  end
73
+
74
+ context "with cycle option" do
75
+ it "applys colors cyclic to the text" do
76
+ str = "a b c d e f"
77
+ expect = "\e[31ma\e[0m \e[32mb\e[0m \e[33mc\e[0m \e[31md\e[0m \e[32me\e[0m \e[33mf\e[0m"
78
+ color_set = [:red, :green, :yellow]
79
+ expect(str.colco(*color_set, cycle:true)).to eq expect
80
+ end
81
+ end
73
82
  end
74
83
  end
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.3
4
+ version: 0.0.4
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-15 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler