term-colorizer 0.1.3 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +0 -1
- data/CHANGELOG.md +15 -1
- data/README.md +47 -7
- data/lib/term-colorizer/colorizer.rb +151 -31
- data/lib/term-colorizer/version.rb +1 -1
- data/screenshot_1.png +0 -0
- data/screenshot_2.png +0 -0
- data/spec/term-colorizer/colorizer_spec.rb +137 -7
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWQ4ZTgwNWEyNGZmYmVlMGMyYTU5ZTIzOTJiNzEyYzg5MmEzNDJkZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmIyNGJiODRiMjhiMDYxMzM5ZTkwOGU0ZGM0ZDAxMGI2MDYwZTM4OQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzUyMThjYjliNGE2NmQ0YTA4NjE1NTU4N2M3MDZiYzUzNDFjYWUxN2IxMjk1
|
10
|
+
NjFlOWRlNDZlMjRiNTRjZmEyYWUyNGM1M2M4NTJhOTdiOTMwNGU4YTk2ZmNj
|
11
|
+
ZWY5MTg2NTY5YjQyMmMyMTAyZDlkNWVlNThiYjBmZDg3NDA4YjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODdiZmM2MmUxMWNjNjg0ZjE2MGZkOWUwYjgwY2JlOTI4YTg0MGM3ZmY4MDAy
|
14
|
+
NGQ5ODk1NDgxZWRkZTA5MmM1OGU1MDUyZjhlZWNjNDFkMzYyZThjMTJjNTU2
|
15
|
+
N2RhZmUwZWNmNDQwNDhmYTI5Mjg4OWUxODc4NjJkZTNkYjY2NGY=
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,21 @@
|
|
1
|
-
### 0.
|
1
|
+
### 0.2.2 (Next Release)
|
2
2
|
|
3
3
|
* Your contribution here.
|
4
4
|
|
5
|
+
### 0.2.1 (8/25/2013)
|
6
|
+
|
7
|
+
* Nothing special added, just updated readme! ;-) - [@vishaltelangre](https://github.com/vishaltelangre).
|
8
|
+
* Stable release till date.
|
9
|
+
|
10
|
+
### 0.2.0 (8/25/2013)
|
11
|
+
|
12
|
+
* NOTE: This version had been mistakenly yanked by me.
|
13
|
+
* Added background color methods, see available background_methods using `bg_color_methods` - [@vishaltelangre](https://github.com/vishaltelangre).
|
14
|
+
* Added bonus methods such as `underline`, and `strikethrough`. - [@vishaltelangre](https://github.com/vishaltelangre).
|
15
|
+
* Added reset methods such as `no_color`, `no_bg_color`, `no_underline`, `no_strikethrough`, `plain_text`, `reset_fancyness` - [@vishaltelangre](https://github.com/vishaltelangre).
|
16
|
+
* Added `fancy_color_methods` which is alias of `term_colorizer_methods` to see all public methods availed by term-colorizer gem. - [@vishaltelangre](https://github.com/vishaltelangre).
|
17
|
+
* Added a lot many test cases for testing scenarios caused by implementation of new features. Run `rspec` command to run the tests. - [@vishaltelangre](https://github.com/vishaltelangre).
|
18
|
+
|
5
19
|
### 0.1.3 (7/24/2013)
|
6
20
|
|
7
21
|
* Added `color_methods` method to see avialable color methods. Also added more rspec test cases - [@vishaltelangre](https://github.com/vishaltelangre).
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Term::Colorizer
|
|
6
6
|
|
7
7
|
Print colorized strings on terminal (Useful for printing fancy logs)
|
8
8
|
|
9
|
-
##
|
9
|
+
## Installation
|
10
10
|
|
11
11
|
Install gem by using following command:
|
12
12
|
|
@@ -18,23 +18,62 @@ or add it to your Gemfile as:
|
|
18
18
|
gem 'term-colorizer', require: 'term-colorizer'
|
19
19
|
```
|
20
20
|
|
21
|
-
|
21
|
+
## Usage
|
22
22
|
|
23
23
|
``` ruby
|
24
24
|
"Duck can quack".green
|
25
25
|
# => "\e[32mDuck can quack\e[0m"
|
26
26
|
|
27
|
-
puts "Wow, that's really " + "hot!".
|
27
|
+
puts "Wow, that's really".underline + " cool ".black.strikethrough + "hot!".bg_red.bright_yellow
|
28
28
|
# guess what it will do?
|
29
29
|
```
|
30
30
|
|
31
|
-
To
|
31
|
+
To see all accessible methods provided by term-colorizer, use:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
>> "Hello".term_colorizer_methods
|
35
|
+
=> [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :bright_black, :bright_red, :bright_green, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white, :bg_black, :bg_red, :bg_green, :bg_yellow, :bg_blue, :bg_magenta, :bg_cyan, :bg_white, :underline, :strikethrough, :term_colorizer_methods, :fancy_color_methods, :no_underline, :no_strikethrough, :no_color, :no_bg_color, :plain_text, :reset_fancyness]
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
To see available color methods only:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
>> "Hello".color_methods
|
43
|
+
=> [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
To see available bright (bold) color methods only:
|
48
|
+
|
32
49
|
```ruby
|
33
|
-
"Hello
|
34
|
-
|
50
|
+
>> "Hello".bright_color_methods
|
51
|
+
=> [:bright_black, :bright_red, :bright_green, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white]
|
35
52
|
```
|
36
53
|
|
37
|
-
|
54
|
+
|
55
|
+
To see available background color methods only:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
>> "Hello".bg_color_methods
|
59
|
+
=> [:bg_black, :bg_red, :bg_green, :bg_yellow, :bg_blue, :bg_magenta, :bg_cyan, :bg_white]
|
60
|
+
```
|
61
|
+
|
62
|
+
## Screenshots
|
63
|
+
|
64
|
+
![term-colorizer-screenshot-1!](https://raw.github.com/vishaltelangre/term-colorizer/master/screenshot_1.png)
|
65
|
+
|
66
|
+
And, for sake -- also added bunch of reset methods, viz. `plain_text`, `reset_fancyness`, `no_color`, `no_bg_color`, `no_underline`, `no_strikethrough`.
|
67
|
+
You can use 'em as:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
>> "That's it, boy!".green.bg_yellow.plain_text
|
71
|
+
=> "That's it, boy!"
|
72
|
+
```
|
73
|
+
|
74
|
+
![term-colorizer-screenshot-2!](https://raw.github.com/vishaltelangre/term-colorizer/master/screenshot_2.png)
|
75
|
+
|
76
|
+
:yum:
|
38
77
|
|
39
78
|
## Contributing
|
40
79
|
|
@@ -42,6 +81,7 @@ You're encouraged to contribute to this gem.
|
|
42
81
|
|
43
82
|
* Fork this project.
|
44
83
|
* Make changes, write tests.
|
84
|
+
* Report bugs, comment on and close open issues.
|
45
85
|
* Updated [CHANGELOG](CHANGELOG.md).
|
46
86
|
* Make a pull request, bonus points for topic branches.
|
47
87
|
|
@@ -1,50 +1,170 @@
|
|
1
1
|
module Term
|
2
2
|
module Colorizer
|
3
|
-
|
4
|
-
|
5
|
-
:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
:
|
11
|
-
:white => "\e[37mSTR\e[0m",
|
12
|
-
:bright_black => "\e[1m\e[30mSTR\e[0m",
|
13
|
-
:bright_red => "\e[1m\e[31mSTR\e[0m",
|
14
|
-
:bright_green => "\e[1m\e[32mSTR\e[0m",
|
15
|
-
:bright_yellow => "\e[1m\e[33mSTR\e[0m",
|
16
|
-
:bright_blue => "\e[1m\e[34mSTR\e[0m",
|
17
|
-
:bright_magenta => "\e[1m\e[35mSTR\e[0m",
|
18
|
-
:bright_cyan => "\e[1m\e[36mSTR\e[0m",
|
19
|
-
:bright_white => "\e[1m\e[37mSTR\e[0m"
|
3
|
+
# Standard ANSI color-codes configuration.
|
4
|
+
TC_CONFIG = {
|
5
|
+
:colors => {
|
6
|
+
:black => 30, :red => 31, :green => 32,
|
7
|
+
:yellow => 33, :blue => 34, :magenta => 35,
|
8
|
+
:cyan => 36, :white => 37
|
9
|
+
},
|
10
|
+
:bg_colors => {}
|
20
11
|
}
|
21
|
-
|
12
|
+
|
13
|
+
TC_CONFIG[:colors].map do |key, value|
|
14
|
+
TC_CONFIG[:bg_colors][key] = value + 10
|
22
15
|
end
|
23
16
|
|
24
17
|
module InstanceMethods
|
25
|
-
#
|
18
|
+
# Returns list of normal color methods.
|
26
19
|
def color_methods
|
27
|
-
|
20
|
+
TC_CONFIG[:colors].keys
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns list of bright (bold) color methods.
|
24
|
+
def bright_color_methods
|
25
|
+
color_methods.collect do |color|
|
26
|
+
"bright_#{color}".to_sym
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns list of background color methods.
|
31
|
+
def bg_color_methods
|
32
|
+
color_methods.collect do |color|
|
33
|
+
"bg_#{color}".to_sym
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
# Returns list of all public methods provided by term-colorizer gem.
|
38
|
+
def term_colorizer_methods
|
39
|
+
methods = []
|
40
|
+
methods += color_methods
|
41
|
+
methods += bright_color_methods
|
42
|
+
methods += bg_color_methods
|
43
|
+
methods += [
|
44
|
+
:underline, :strikethrough, :term_colorizer_methods,
|
45
|
+
:fancy_color_methods, :no_underline, :no_strikethrough,
|
46
|
+
:no_color, :no_bg_color, :plain_text, :reset_fancyness
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
# Alias of `term_colorizer_methods` method.
|
51
|
+
def fancy_color_methods
|
52
|
+
self.term_colorizer_methods
|
53
|
+
end
|
54
|
+
|
55
|
+
# Overrides `method_missing` method's default behaviour to define the
|
56
|
+
# term colorizer methods on the fly when called.
|
57
|
+
def method_missing(method, *args, &block)
|
58
|
+
super unless term_colorizer_methods.include? method
|
34
59
|
self.class.send(:define_method, method) do
|
35
|
-
|
60
|
+
str = self
|
61
|
+
str = add_normal_color(str, method) if color_methods.include? method
|
62
|
+
str = add_bright_color(str, method) if bright_color_methods.include? method
|
63
|
+
str = add_bg_color(str, method) if bg_color_methods.include? method
|
64
|
+
str = add_underline(str) if "underline".eql? method.to_s
|
65
|
+
str = add_strikethrough_effect(str) if "strikethrough".eql? method.to_s
|
66
|
+
str = str + "\e[0m" unless str.end_with? "\e[0m"
|
67
|
+
str
|
36
68
|
end and self.send(method, *args)
|
37
69
|
end
|
38
70
|
|
39
|
-
#
|
40
|
-
#
|
41
|
-
def respond_to_missing?(method, include_private = false)
|
42
|
-
|
71
|
+
# Overrides `respond_to?` method so as to it will return true when asked
|
72
|
+
# for any of term colorizer methods.
|
73
|
+
def respond_to_missing?(method, include_private = false)
|
74
|
+
term_colorizer_methods.include? method || super
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns original plain text string by cleaning all the fancyness added
|
78
|
+
# to it by term colorizer methods.
|
79
|
+
def plain_text
|
80
|
+
self.gsub(/\e\[[0-9]m|\e\[[34][0-7]m/, '')
|
81
|
+
end
|
82
|
+
|
83
|
+
# Alias of `plain_text` method.
|
84
|
+
def reset_fancyness
|
85
|
+
self.plain_text
|
86
|
+
end
|
87
|
+
|
88
|
+
# Returns string by cleaning off colors added to it by term colorizer
|
89
|
+
# methods.
|
90
|
+
def no_color
|
91
|
+
reset_prev_formatting self, :color
|
92
|
+
end
|
93
|
+
|
94
|
+
# Returns string by cleaning off background colors added to it by term
|
95
|
+
# colorizer methods.
|
96
|
+
def no_bg_color
|
97
|
+
reset_prev_formatting self, :bg_color
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns string by removing underlines in it.
|
101
|
+
def no_underline
|
102
|
+
reset_prev_formatting self, :underline
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns string by removing strikethrough effect(s) added to it.
|
106
|
+
def no_strikethrough
|
107
|
+
reset_prev_formatting self, :strikethrough
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
# Private method returns string by adding normal color effect
|
113
|
+
def add_normal_color(str, color)
|
114
|
+
str = reset_prev_formatting str, :color
|
115
|
+
"\e[#{TC_CONFIG[:colors][color].to_s}m#{str}"
|
116
|
+
end
|
117
|
+
|
118
|
+
# Private method returns string by adding bright (bold) color effect
|
119
|
+
def add_bright_color(str, color)
|
120
|
+
color = color.to_s.sub("bright_", "").to_sym
|
121
|
+
str = reset_prev_formatting str, :color
|
122
|
+
"\e[1m\e[#{TC_CONFIG[:colors][color].to_s}m#{str}"
|
123
|
+
end
|
124
|
+
|
125
|
+
# Private method returns string by adding background color effect
|
126
|
+
def add_bg_color(str, color)
|
127
|
+
color = color.to_s.sub("bg_", "").to_sym
|
128
|
+
str = reset_prev_formatting str, :bg_color
|
129
|
+
"\e[#{TC_CONFIG[:bg_colors][color].to_s}m#{str}"
|
130
|
+
end
|
131
|
+
|
132
|
+
def add_underline(str)
|
133
|
+
"\e[4m#{str}"
|
134
|
+
end
|
135
|
+
|
136
|
+
def add_strikethrough_effect(str)
|
137
|
+
"\e[9m#{str}"
|
138
|
+
end
|
139
|
+
|
140
|
+
# Cleans off string formatting for colors or background colors added by
|
141
|
+
# term colorizer methods previously
|
142
|
+
def reset_prev_formatting(str, type)
|
143
|
+
case type
|
144
|
+
when :color
|
145
|
+
str = str.gsub("\e[1m", '').gsub(/\e\[[3][0-7]m/, '')
|
146
|
+
when :bg_color
|
147
|
+
str = str.gsub(/\e\[[4][0-7]m/, '')
|
148
|
+
when :underline
|
149
|
+
str = str.gsub("\e[4m", '')
|
150
|
+
when :strikethrough
|
151
|
+
str = str.gsub("\e[9m", '')
|
152
|
+
end
|
153
|
+
|
154
|
+
# Remove ANSI termination characters from `str`.
|
155
|
+
str = str.gsub("\e[0m", '')
|
156
|
+
|
157
|
+
# Hack! Add ANSI termination character at the end of `str` if `str`
|
158
|
+
# contains any fancy stuff added by term colorizer methods before.
|
159
|
+
if str.scan(/\e\[[1-9]/).any?
|
160
|
+
str = str + "\e[0m" unless str.end_with? "\e[0m"
|
161
|
+
end
|
162
|
+
|
163
|
+
return str
|
43
164
|
end
|
44
165
|
end
|
45
166
|
|
46
167
|
def self.included(base)
|
47
|
-
base.extend ClassMethods
|
48
168
|
base.send :include, InstanceMethods
|
49
169
|
end
|
50
170
|
end
|
@@ -52,4 +172,4 @@ end
|
|
52
172
|
|
53
173
|
class String
|
54
174
|
include Term::Colorizer
|
55
|
-
end
|
175
|
+
end
|
data/screenshot_1.png
ADDED
Binary file
|
data/screenshot_2.png
ADDED
Binary file
|
@@ -1,16 +1,146 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Term::Colorizer do
|
4
|
-
|
5
|
-
|
4
|
+
string = "It's a very simple sentence!"
|
5
|
+
|
6
|
+
context "Testing methods' availability..." do
|
7
|
+
it "check color methods" do
|
8
|
+
methods = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
|
9
|
+
methods.map do |method|
|
10
|
+
expect(string.color_methods).to include(method)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "check bright_color_methods" do
|
15
|
+
methods = [:bright_black, :bright_red, :bright_green, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white]
|
16
|
+
methods.map do |method|
|
17
|
+
expect(string.bright_color_methods).to include(method)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "check bg_color_methods" do
|
22
|
+
methods = [:bg_black, :bg_red, :bg_green, :bg_yellow, :bg_blue, :bg_magenta, :bg_cyan, :bg_white]
|
23
|
+
methods.map do |method|
|
24
|
+
expect(string.bg_color_methods).to include(method)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "check all public methods availed by term colorizer gem" do
|
29
|
+
methods = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :bright_black, :bright_red, :bright_green, :bright_yellow, :bright_blue, :bright_magenta, :bright_cyan, :bright_white, :bg_black, :bg_red, :bg_green, :bg_yellow, :bg_blue, :bg_magenta, :bg_cyan, :bg_white, :underline, :strikethrough, :term_colorizer_methods, :fancy_color_methods, :no_underline, :no_strikethrough, :no_color, :no_bg_color, :plain_text, :reset_fancyness]
|
30
|
+
methods.map do |method|
|
31
|
+
expect(string.term_colorizer_methods).to include(method)
|
32
|
+
string.should respond_to(method)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "`term_colorizer_methods` should display combined output of `color_methods`+`bright_color_methods`+`bg_color_methods`" do
|
37
|
+
expected_methods = string.color_methods + string.bright_color_methods + string.bg_color_methods
|
38
|
+
expected_methods.map do |method|
|
39
|
+
expect(string.term_colorizer_methods).to include(method)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "check whether `fancy_color_methods` is an alias method of `term_colorizer_methods`" do
|
44
|
+
string.fancy_color_methods.should == string.term_colorizer_methods
|
45
|
+
end
|
6
46
|
end
|
7
47
|
|
8
|
-
|
9
|
-
"
|
48
|
+
context "Testing color & background color methods..." do
|
49
|
+
context "Testing normal color methods..." do
|
50
|
+
it "check all normal color methods' responses" do
|
51
|
+
string.black.should eq("\e[30mIt's a very simple sentence!\e[0m")
|
52
|
+
string.red.should eq("\e[31mIt's a very simple sentence!\e[0m")
|
53
|
+
string.green.should eq("\e[32mIt's a very simple sentence!\e[0m")
|
54
|
+
string.yellow.should eq("\e[33mIt's a very simple sentence!\e[0m")
|
55
|
+
string.blue.should eq("\e[34mIt's a very simple sentence!\e[0m")
|
56
|
+
string.magenta.should eq("\e[35mIt's a very simple sentence!\e[0m")
|
57
|
+
string.cyan.should eq("\e[36mIt's a very simple sentence!\e[0m")
|
58
|
+
string.white.should eq("\e[37mIt's a very simple sentence!\e[0m")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "check resultant string when chained normal color methods applied on same string" do
|
62
|
+
string.red.should eq "\e[31mIt's a very simple sentence!\e[0m"
|
63
|
+
string.red.cyan.should eq "\e[36mIt's a very simple sentence!\e[0m"
|
64
|
+
string.red.cyan.green.white.black.black.yellow.should eq "\e[33mIt's a very simple sentence!\e[0m"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "Testing bright color methods..." do
|
69
|
+
it "check all bright color methods' responses" do
|
70
|
+
string.bright_black.should eq("\e[1m\e[30mIt's a very simple sentence!\e[0m")
|
71
|
+
string.bright_red.should eq("\e[1m\e[31mIt's a very simple sentence!\e[0m")
|
72
|
+
string.bright_green.should eq("\e[1m\e[32mIt's a very simple sentence!\e[0m")
|
73
|
+
string.bright_yellow.should eq("\e[1m\e[33mIt's a very simple sentence!\e[0m")
|
74
|
+
string.bright_blue.should eq("\e[1m\e[34mIt's a very simple sentence!\e[0m")
|
75
|
+
string.bright_magenta.should eq("\e[1m\e[35mIt's a very simple sentence!\e[0m")
|
76
|
+
string.bright_cyan.should eq("\e[1m\e[36mIt's a very simple sentence!\e[0m")
|
77
|
+
string.bright_white.should eq("\e[1m\e[37mIt's a very simple sentence!\e[0m")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "check resultant string when chained color methods applied on same string" do
|
81
|
+
string.bright_red.should eq "\e[1m\e[31mIt's a very simple sentence!\e[0m"
|
82
|
+
string.bright_red.bright_cyan.should eq "\e[1m\e[36mIt's a very simple sentence!\e[0m"
|
83
|
+
string.bright_red.bright_cyan.bright_green.bright_white.bright_black.bright_black.bright_yellow.should eq "\e[1m\e[33mIt's a very simple sentence!\e[0m"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "Testing background color methods..." do
|
88
|
+
it "check all background color methods' responses" do
|
89
|
+
string.bg_black.should eq("\e[40mIt's a very simple sentence!\e[0m")
|
90
|
+
string.bg_red.should eq("\e[41mIt's a very simple sentence!\e[0m")
|
91
|
+
string.bg_green.should eq("\e[42mIt's a very simple sentence!\e[0m")
|
92
|
+
string.bg_yellow.should eq("\e[43mIt's a very simple sentence!\e[0m")
|
93
|
+
string.bg_blue.should eq("\e[44mIt's a very simple sentence!\e[0m")
|
94
|
+
string.bg_magenta.should eq("\e[45mIt's a very simple sentence!\e[0m")
|
95
|
+
string.bg_cyan.should eq("\e[46mIt's a very simple sentence!\e[0m")
|
96
|
+
string.bg_white.should eq("\e[47mIt's a very simple sentence!\e[0m")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "check resultant string when chained background methods applied on same string" do
|
100
|
+
string.bg_red.should eq "\e[41mIt's a very simple sentence!\e[0m"
|
101
|
+
string.bg_red.bg_cyan.should eq "\e[46mIt's a very simple sentence!\e[0m"
|
102
|
+
string.bg_red.bg_cyan.bg_green.bg_white.bg_black.bg_black.bg_yellow.should eq "\e[43mIt's a very simple sentence!\e[0m"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "Testing reset methods for color & background..." do
|
107
|
+
it "check `no_color` and `no_bg_color` methods' behaviours" do
|
108
|
+
string.magenta.should respond_to(:no_color)
|
109
|
+
string.should respond_to(:no_bg_color)
|
110
|
+
string.magenta.no_color.should eq(string)
|
111
|
+
string.magenta.no_color.no_bg_color.should eq(string)
|
112
|
+
string.bright_magenta.bg_green.red.no_bg_color.no_color.no_color.should eq(string)
|
113
|
+
string.bg_yellow.bright_white.no_color.should eq(string.bg_yellow)
|
114
|
+
string.bg_black.magenta.bright_black.red.red.red.white.no_bg_color.bright_cyan.no_color.should eq(string)
|
115
|
+
end
|
116
|
+
end
|
10
117
|
end
|
11
118
|
|
12
|
-
|
13
|
-
"
|
119
|
+
context "Testing bonus methods..." do
|
120
|
+
it "check `underline` method's behaviour" do
|
121
|
+
string.red.underline.underline.green.should eq("\e[32m\e[4m\e[4mIt's a very simple sentence!\e[0m")
|
122
|
+
string.sub(/(simple)/, '\1'.red.underline.underline.green.yellow).should eq("It's a very \e[33m\e[4m\e[4msimple\e[0m sentence!")
|
123
|
+
end
|
124
|
+
|
125
|
+
it "check `strikethrough` method's behaviour" do
|
126
|
+
string.red.strikethrough.green.strikethrough.should eq("\e[9m\e[32m\e[9mIt's a very simple sentence!\e[0m")
|
127
|
+
string.sub(/(simple)/, '\1'.red.strikethrough.green.yellow).should eq("It's a very \e[33m\e[9msimple\e[0m sentence!")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "check `no_underline` and `no_strikethrough` methods' behaviours" do
|
131
|
+
string.sub(/(simple)/, '\1'.red.bg_yellow.green.yellow.red.underline.no_underline.strikethrough).should eq("It's a very \e[9m\e[31m\e[43msimple\e[0m sentence!")
|
132
|
+
string.sub(/(simple)/, '\1'.red.strikethrough.green.yellow.strikethrough.strikethrough.no_strikethrough.no_color).should eq(string)
|
133
|
+
end
|
14
134
|
end
|
15
135
|
|
16
|
-
|
136
|
+
context "Final Tests..." do
|
137
|
+
it "check resultant string when applied many color, background, bonus methods on different sections of string and also called reset methods on it" do
|
138
|
+
string.sub(/(simple)/, '\1'.red.bg_yellow.green.yellow.red.underline.no_underline.strikethrough.no_bg_color).should eq("It's a very \e[9m\e[31msimple\e[0m sentence!")
|
139
|
+
string.sub(/(simple)/, '\1'.red.bg_yellow.green.yellow.red.underline.no_underline.strikethrough.no_bg_color.no_color.no_strikethrough).should eq(string)
|
140
|
+
complex_string = string.yellow + " It has nothing to do with my ".green + "name,".underline + " but FYI, my name is".bg_magenta.black + " " + "foo".strikethrough.red + " Vishal!".upcase.bright_cyan
|
141
|
+
complex_string.should eq("\e[33mIt's a very simple sentence!\e[0m\e[32m It has nothing to do with my \e[0m\e[4mname,\e[0m\e[30m\e[45m but FYI, my name is\e[0m \e[31m\e[9mfoo\e[0m\e[1m\e[36m VISHAL!\e[0m")
|
142
|
+
complex_string.plain_text.should == "It's a very simple sentence! It has nothing to do with my name, but FYI, my name is foo VISHAL!"
|
143
|
+
complex_string.reset_fancyness.should == complex_string.plain_text
|
144
|
+
end
|
145
|
+
end
|
146
|
+
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.2.1
|
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-
|
11
|
+
date: 2013-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: the@vishaltelangre.com
|
@@ -27,6 +27,8 @@ files:
|
|
27
27
|
- lib/term-colorizer.rb
|
28
28
|
- lib/term-colorizer/colorizer.rb
|
29
29
|
- lib/term-colorizer/version.rb
|
30
|
+
- screenshot_1.png
|
31
|
+
- screenshot_2.png
|
30
32
|
- spec/spec_helper.rb
|
31
33
|
- spec/term-colorizer/colorizer_spec.rb
|
32
34
|
- spec/term-colorizer/version_spec.rb
|