colorputs 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHORS.md +6 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +57 -0
- data/colorputs.gemspec +17 -0
- data/lib/colorputs.rb +3 -34
- data/lib/colorputs/main.rb +63 -0
- data/specs/spec_colorputs.rb +122 -0
- data/specs/spec_helper.rb +2 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3341f3b8c950f5e4cffac502ea3d3e1c9692135f
|
4
|
+
data.tar.gz: 5743ea6b1498682d889aa783cd6606718f4ee27d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ea532ed1c779e1eee930a52cba7eef2542c67f4d004e5124658c8356c5e0778361fb931e28a35e7af4e6198d8f9d457ea8667d5b910c4c62b96e561c0a49922
|
7
|
+
data.tar.gz: c8fbc7f87042f17424c3679055da10043637e70222445fa0c3f3593b7b6a3be9ad54cb8166ad3f0ef871947ab4db38a9c4489bc2d9fd2f17fe46ea58ea4572d2
|
data/AUTHORS.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Lautaro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
colorputs
|
2
|
+
=========
|
3
|
+
|
4
|
+
Color in p and puts method!
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Colorputs provides a beatiful color printing for Ruby console-based applications
|
10
|
+
|
11
|
+
Instalation
|
12
|
+
-----------
|
13
|
+
|
14
|
+
gem install colorputs
|
15
|
+
|
16
|
+
Examples of usage
|
17
|
+
-----------------
|
18
|
+
|
19
|
+
p 'Hello world!', :red
|
20
|
+
|
21
|
+
Will print out "Hello world!" colored in red.
|
22
|
+
|
23
|
+
Availables colors and modes
|
24
|
+
---------------------------
|
25
|
+
|
26
|
+
<table>
|
27
|
+
<tr>
|
28
|
+
<th>Symbol</th><th>Color/Mode</th>
|
29
|
+
</tr>
|
30
|
+
<tr>
|
31
|
+
<td>:red</td><td>Red</td>
|
32
|
+
</tr>
|
33
|
+
<tr>
|
34
|
+
<td>:blue</td><td>Blue</td>
|
35
|
+
</tr>
|
36
|
+
<tr>
|
37
|
+
<td>:green</td><td>Green</td>
|
38
|
+
</tr>
|
39
|
+
<tr>
|
40
|
+
<td>:yellow</td><td>Yellow</td>
|
41
|
+
</tr>
|
42
|
+
<tr>
|
43
|
+
<td>:cyan</td><td>Cyan</td>
|
44
|
+
</tr>
|
45
|
+
<tr>
|
46
|
+
<td>:magenta</td><td>Magenta</td>
|
47
|
+
</tr>
|
48
|
+
<tr>
|
49
|
+
<td>:white</td><td>White</td>
|
50
|
+
</tr>
|
51
|
+
<tr>
|
52
|
+
<td>:black</td><td>Black</td>
|
53
|
+
</tr>
|
54
|
+
<tr>
|
55
|
+
<td>:rainbow</td><td>Rainbow colors!</td>
|
56
|
+
</tr>
|
57
|
+
</table>
|
data/colorputs.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
lib = File.expand_path(File.join('..', 'lib'), __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'colorputs'
|
6
|
+
s.version = '0.2.3'
|
7
|
+
s.date = '2013-11-27'
|
8
|
+
s.summary = "Color in puts method!!"
|
9
|
+
s.description = "Enables to use puts and p standard methods with a easy color interface"
|
10
|
+
s.authors = ["Agustín Beamurguía, Lautaro De León"]
|
11
|
+
s.email = ['agus.beam@gmail.com, laudleon@gmail.com']
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files | grep specs/`.split("\n")
|
14
|
+
s.require_paths = ["lib/"]
|
15
|
+
s.homepage = 'http://github.com/lndl/colorputs'
|
16
|
+
s.license = 'MIT'
|
17
|
+
end
|
data/lib/colorputs.rb
CHANGED
@@ -1,36 +1,5 @@
|
|
1
|
-
|
1
|
+
require 'colorputs/main.rb'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
std_coloring = proc do |color_code, str|
|
6
|
-
"\e#{color_code}#{str}\e[0m"
|
7
|
-
end.curry()
|
8
|
-
|
9
|
-
rainbow_coloring = proc do |str|
|
10
|
-
str.chars.inject("") { |acc,c| acc + colors.values[rand(colors.size - 2)].(c) }
|
11
|
-
end
|
12
|
-
|
13
|
-
colors.merge!({
|
14
|
-
red: std_coloring.('[91m'),
|
15
|
-
green: std_coloring.('[92m'),
|
16
|
-
yellow: std_coloring.('[93m'),
|
17
|
-
blue: std_coloring.('[94m'),
|
18
|
-
magenta: std_coloring.('[95m'),
|
19
|
-
cyan: std_coloring.('[96m'),
|
20
|
-
white: std_coloring.('[37m'),
|
21
|
-
black: std_coloring.('[30m'),
|
22
|
-
rainbow: rainbow_coloring
|
23
|
-
})
|
24
|
-
|
25
|
-
old_puts = method :puts
|
26
|
-
|
27
|
-
p_color_body = proc do |print_m_sym, obj, *args|
|
28
|
-
maybe_color = args.last
|
29
|
-
fancy_str = colors[maybe_color].(obj.send(print_m_sym)) rescue obj
|
30
|
-
args.pop unless fancy_str == obj
|
31
|
-
old_puts.(fancy_str, args)
|
32
|
-
end.curry()
|
33
|
-
|
34
|
-
define_method :puts, p_color_body.(:to_s)
|
35
|
-
define_method :p, p_color_body.(:inspect)
|
3
|
+
class Object
|
4
|
+
include Colorputs
|
36
5
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Colorputs
|
2
|
+
|
3
|
+
colors = Hash.new
|
4
|
+
modes = Hash.new
|
5
|
+
|
6
|
+
format_wrapper = ->(start_code, str, end_code) { "\e[#{start_code}m#{str}\e[#{end_code}m" }
|
7
|
+
|
8
|
+
std_mode = proc do |start_mode, end_mode, str|
|
9
|
+
format_wrapper.(start_mode, str, end_mode)
|
10
|
+
end.curry()
|
11
|
+
|
12
|
+
std_coloring = proc do |color_code, str|
|
13
|
+
format_wrapper.(color_code, str, 39)
|
14
|
+
end.curry()
|
15
|
+
|
16
|
+
rainbow_coloring = proc do |str|
|
17
|
+
str.chars.inject("") { |acc,c| acc + colors.values[rand(colors.size - 2)].(c) }
|
18
|
+
end
|
19
|
+
|
20
|
+
modes.merge!({
|
21
|
+
b: std_mode.(1,21), # Bold
|
22
|
+
bl: std_mode.(5,25), # Blinking
|
23
|
+
u: std_mode.(4,24), # Underlined
|
24
|
+
r: std_mode.(7,27) # Reversed
|
25
|
+
})
|
26
|
+
|
27
|
+
colors.merge!({
|
28
|
+
red: std_coloring.('91'),
|
29
|
+
green: std_coloring.('92'),
|
30
|
+
yellow: std_coloring.('93'),
|
31
|
+
blue: std_coloring.('94'),
|
32
|
+
magenta: std_coloring.('95'),
|
33
|
+
cyan: std_coloring.('96'),
|
34
|
+
white: std_coloring.('37'),
|
35
|
+
black: std_coloring.('30'),
|
36
|
+
rainbow: rainbow_coloring
|
37
|
+
})
|
38
|
+
|
39
|
+
old_puts = Kernel.method :puts
|
40
|
+
|
41
|
+
fancyner = proc do |normal_str, maybe_Cp_code|
|
42
|
+
if maybe_Cp_code.instance_of? Symbol
|
43
|
+
maybe_color, maybe_mode = maybe_Cp_code.to_s.split('_').map(&:to_sym)
|
44
|
+
fancy_str = colors[maybe_color].(normal_str) rescue normal_str
|
45
|
+
fancy_str = modes[maybe_mode].(fancy_str) rescue fancy_str
|
46
|
+
fancy_str
|
47
|
+
else
|
48
|
+
normal_str
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
p_color_body = proc do |print_m_sym, ret_lambda, obj, *args|
|
53
|
+
maybe_Cp_code = args.last # Cp -> Colorputs ;)
|
54
|
+
normal_str = obj.send(print_m_sym)
|
55
|
+
fancy_str = fancyner.(normal_str, maybe_Cp_code)
|
56
|
+
args.pop unless fancy_str == normal_str
|
57
|
+
old_puts.(fancy_str, args)
|
58
|
+
ret_lambda.(obj,args)
|
59
|
+
end.curry()
|
60
|
+
|
61
|
+
define_method :puts, p_color_body.(:to_s, ->(_ , _) { nil })
|
62
|
+
define_method :p, p_color_body.(:inspect, ->(obj, args) { (args == []) ? obj : [obj] + args })
|
63
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require './spec_helper'
|
2
|
+
|
3
|
+
describe 'Colorputs:' do
|
4
|
+
before do
|
5
|
+
class MyColorizedObject
|
6
|
+
include Colorputs
|
7
|
+
end
|
8
|
+
@mco = MyColorizedObject.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '::p ->' do
|
12
|
+
describe 'when no Colorputs specifics args are sent,' do
|
13
|
+
it 'must return like the original p method' do
|
14
|
+
@mco.send(:p, 'Hello').should eql(p 'Hello')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'when some color is sent,' do
|
19
|
+
describe 'when only one argument is sent to print,' do
|
20
|
+
it 'must return like the original p method' do
|
21
|
+
@mco.send(:p, 'Hello', :red).should eql(p 'Hello')
|
22
|
+
end
|
23
|
+
it 'must return only one valid string argument' do
|
24
|
+
@mco.send(:p, 'Hello', :red).should be_a_kind_of String
|
25
|
+
end
|
26
|
+
end
|
27
|
+
describe 'when an argument list is sent to print,' do
|
28
|
+
it 'must return like the original p method' do
|
29
|
+
@mco.send(:p, 'Hello','How','Are','You', :blue, :red).should eql(p 'Hello', 'How', 'Are', 'You', :blue)
|
30
|
+
end
|
31
|
+
it 'must return the whole argument list, except the color' do
|
32
|
+
@mco.send(:p, 'Hello','How','Are','You', :blue, :red).should be_a_kind_of Array
|
33
|
+
@mco.send(:p, 'Hello','How','Are','You', :blue, :red).size.should eql(5)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'when a wrong color is sent,' do
|
39
|
+
it 'safely ignore it and returns like an ordinary p method' do
|
40
|
+
@mco.send(:p, 'Hello', :wrong).should eql(p 'Hello', :wrong)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'must return the whole argument list, including the wrong color label' do
|
44
|
+
@mco.send(:p, 'Hello', :wrong).should be_a_kind_of Array
|
45
|
+
@mco.send(:p, 'Hello', :wrong).size.should eql(2)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'when a valid color/mode string is sent, ' do
|
50
|
+
it 'must ignore it (only symboles are accepted)' do
|
51
|
+
@mco.send(:p, 'Hello', 'green_b').should eql(p 'Hello', 'green_b')
|
52
|
+
@mco.send(:p, 'Hello', 'green_b').size.should eql(2)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'when mode suffix is sent,' do
|
57
|
+
describe 'when is used in combination with color' do
|
58
|
+
it 'must return like the original p method' do
|
59
|
+
@mco.send(:p, 'Hello', :red_b).should eql(p 'Hello')
|
60
|
+
end
|
61
|
+
it 'must return only one valid string argument' do
|
62
|
+
@mco.send(:p, 'Hello', :red_b).should be_a_kind_of String
|
63
|
+
end
|
64
|
+
end
|
65
|
+
describe 'when is not used in combination with color' do
|
66
|
+
it 'must return like the original p method' do
|
67
|
+
@mco.send(:p, 'Hello', :_b).should eql(p 'Hello')
|
68
|
+
end
|
69
|
+
it 'must return only one valid string argument' do
|
70
|
+
@mco.send(:p, 'Hello', :_b).should be_a_kind_of String
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '::puts ->' do
|
77
|
+
describe 'when no Colorputs specifics args are sent,' do
|
78
|
+
it 'must return like the original puts method' do
|
79
|
+
@mco.send(:puts, 'Hello').should eql(puts 'Hello')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'when some color is sent,' do
|
84
|
+
describe 'when only one argument is sent to print,' do
|
85
|
+
it 'must return like the original puts method' do
|
86
|
+
@mco.send(:puts, 'Hello', :red).should eql(puts 'Hello')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
describe 'when an argument list is sent to print,' do
|
90
|
+
it 'must return like the original puts method' do
|
91
|
+
@mco.send(:puts, 'Hello','How','Are','You', :blue, :red).should eql(puts 'Hello', 'How', 'Are', 'You', :blue)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'when a wrong color is sent,' do
|
97
|
+
it 'safely ignore it and returns like an ordinary puts method' do
|
98
|
+
@mco.send(:puts, 'Hello', :wrong).should eql(puts 'Hello', :wrong)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'when a valid color/mode string is sent, ' do
|
103
|
+
it 'must ignore it (only symboles are accepted)' do
|
104
|
+
@mco.send(:puts, 'Hello', 'green_b').should eql(puts 'Hello', 'green_b')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'when mode suffix is sent,' do
|
109
|
+
describe 'when is used in combination with color' do
|
110
|
+
it 'must return like the original p method' do
|
111
|
+
@mco.send(:puts, 'Hello', :red_b).should eql(puts 'Hello')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
describe 'when is not used in combination with color' do
|
115
|
+
it 'must return like the original p method' do
|
116
|
+
@mco.send(:puts, 'Hello', :_b).should eql(puts 'Hello')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorputs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agustín Beamurguía, Lautaro De León
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Enables to use puts and p standard methods with a easy color interface
|
14
14
|
email:
|
@@ -17,7 +17,15 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- AUTHORS.md
|
21
|
+
- Gemfile
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- colorputs.gemspec
|
20
25
|
- lib/colorputs.rb
|
26
|
+
- lib/colorputs/main.rb
|
27
|
+
- specs/spec_colorputs.rb
|
28
|
+
- specs/spec_helper.rb
|
21
29
|
homepage: http://github.com/lndl/colorputs
|
22
30
|
licenses:
|
23
31
|
- MIT
|
@@ -42,4 +50,6 @@ rubygems_version: 2.0.3
|
|
42
50
|
signing_key:
|
43
51
|
specification_version: 4
|
44
52
|
summary: Color in puts method!!
|
45
|
-
test_files:
|
53
|
+
test_files:
|
54
|
+
- specs/spec_colorputs.rb
|
55
|
+
- specs/spec_helper.rb
|