term-colorizer 0.1.2 → 0.1.3
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 +8 -8
- data/CHANGELOG.md +5 -1
- data/README.md +7 -5
- data/lib/term-colorizer/colorizer.rb +27 -5
- data/lib/term-colorizer/version.rb +1 -1
- data/spec/term-colorizer/colorizer_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmYwMTFhZjFhNWEzZWEzZTI3MTc0YzViNWExYjFmMzIxNWRjODhlMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjI3NmY3NDU2OGViNzMzMTk2ZDAzNDdlN2QxZDY1ZTk4YjU5ODU5MA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWJjZmM4NTExOWEzOGNhNjBhM2I3ZWE4YjVhODBjZjlhZjkwZTJmZTFjNTEz
|
10
|
+
YTM0MzBhMDE0ZDU3MTUxMDZmYzRkM2YzYTUzZmE0ZjEyMjBkMzI2MjU2Y2Vm
|
11
|
+
YTA2MDJhNmQwZTc3ZDlhMWQ5ZmI5ZWYxNWM0ZGRkZTk3ZjBiODQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGYzYmRjY2FmNDk2ZTljNmVlYWUyMThkYmFjMWJjNzUyMWUwOTk3NzM5Yzkx
|
14
|
+
OWM5OGIwOThkMjA4ZGU3ZmMwNGE3ZWU3ZmFmN2ZkYWQyMDI5OTljYzNjMmMy
|
15
|
+
M2U4MWI5OGNkYTU0YmMzNjlmMDUyYTA4ZTAyMTY3YzM2MmVhYWU=
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
### 0.1.
|
1
|
+
### 0.1.4 (Next Release)
|
2
2
|
|
3
3
|
* Your contribution here.
|
4
4
|
|
5
|
+
### 0.1.3 (7/24/2013)
|
6
|
+
|
7
|
+
* Added `color_methods` method to see avialable color methods. Also added more rspec test cases - [@vishaltelangre](https://github.com/vishaltelangre).
|
8
|
+
|
5
9
|
### 0.1.2 (7/22/2013)
|
6
10
|
|
7
11
|
* Created a hash for terminal color, and used it inside method_missing to define color methods on the fly when called. - [@vishaltelangre](https://github.com/vishaltelangre).
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
Term::Colorizer
|
2
2
|
===============
|
3
3
|
|
4
|
+
[](http://badge.fury.io/rb/term-colorizer)
|
4
5
|
[](https://travis-ci.org/vishaltelangre/term-colorizer)
|
5
6
|
|
6
7
|
Print colorized strings on terminal (Useful for printing fancy logs)
|
@@ -14,7 +15,7 @@ Install gem by using following command:
|
|
14
15
|
or add it to your Gemfile as:
|
15
16
|
|
16
17
|
```ruby
|
17
|
-
gem
|
18
|
+
gem 'term-colorizer', require: 'term-colorizer'
|
18
19
|
```
|
19
20
|
|
20
21
|
and use it as:
|
@@ -25,11 +26,12 @@ and use it as:
|
|
25
26
|
|
26
27
|
puts "Wow, that's really " + "hot!".bright_red
|
27
28
|
# guess what it will do?
|
29
|
+
```
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
# bright_green,bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white
|
31
|
+
To know avaialable color methods:
|
32
|
+
```ruby
|
33
|
+
"Hello world!".color_methods
|
34
|
+
# => [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :bright_black, :bright_red, :bright_green, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white]
|
33
35
|
```
|
34
36
|
|
35
37
|
:)
|
@@ -18,12 +18,34 @@ module Term
|
|
18
18
|
:bright_cyan => "\e[1m\e[36mSTR\e[0m",
|
19
19
|
:bright_white => "\e[1m\e[37mSTR\e[0m"
|
20
20
|
}
|
21
|
+
module ClassMethods
|
22
|
+
end
|
23
|
+
|
24
|
+
module InstanceMethods
|
25
|
+
# returns array of available color methods
|
26
|
+
def color_methods
|
27
|
+
TERM_COLORS.keys
|
28
|
+
end
|
29
|
+
|
30
|
+
# overriden method_missing's default behaviour to
|
31
|
+
# define the color methods on the fly when called
|
32
|
+
def method_missing(method, *args, &block) #:nodoc:
|
33
|
+
super unless TERM_COLORS.keys.include? method
|
34
|
+
self.class.send(:define_method, method) do
|
35
|
+
TERM_COLORS[method].sub(/STR/, self.to_s)
|
36
|
+
end and self.send(method, *args)
|
37
|
+
end
|
38
|
+
|
39
|
+
# overriden respond_to? so as to it will return true
|
40
|
+
# when asked for any of available color methods
|
41
|
+
def respond_to_missing?(method, include_private = false) #:nodoc:
|
42
|
+
TERM_COLORS.keys.include? method || super
|
43
|
+
end
|
44
|
+
end
|
21
45
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
TERM_COLORS[method].sub(/STR/, self.to_s)
|
26
|
-
end and self.send(method, *args)
|
46
|
+
def self.included(base)
|
47
|
+
base.extend ClassMethods
|
48
|
+
base.send :include, InstanceMethods
|
27
49
|
end
|
28
50
|
end
|
29
51
|
end
|
@@ -4,4 +4,13 @@ describe Term::Colorizer do
|
|
4
4
|
it "should return a equivalent ANSI formatted string with for red color" do
|
5
5
|
"Duck can quack".red.should eq "\e[31mDuck can quack\e[0m"
|
6
6
|
end
|
7
|
+
|
8
|
+
it "should have `color_methods` method available on String instance" do
|
9
|
+
"Hello world!".should respond_to(:color_methods)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should respond to an available color method, e.g. \"Hello world!\".respond_to?(:bright_green)" do
|
13
|
+
"Hello world!".should respond_to(:bright_green)
|
14
|
+
end
|
15
|
+
|
7
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: term-colorizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vishal Telangre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: the@vishaltelangre.com
|