colorer 0.4.0 → 0.5.0
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.
- data/README.rdoc +14 -14
- data/VERSION +1 -1
- data/colorer.gemspec +1 -1
- data/lib/colorer.rb +29 -10
- data/test/basic.irt +1 -1
- data/test/custom.irt +1 -1
- data/test/selected_basic.irt +2 -2
- data/test/sgr.irt +3 -2
- metadata +7 -7
data/README.rdoc
CHANGED
@@ -5,9 +5,9 @@ Easy ANSI code coloring for strings.
|
|
5
5
|
== Synopsis
|
6
6
|
|
7
7
|
require 'colorer'
|
8
|
-
Colorer.
|
9
|
-
|
10
|
-
|
8
|
+
Colorer.def_basic_styles
|
9
|
+
Colorer.def_custom_styles :errorize => [ :red, :bold, :underline ],
|
10
|
+
:mysgr => [ :red, 8 ]
|
11
11
|
|
12
12
|
"a red bold underlined text on white background".red.bold.underline.onwhite
|
13
13
|
"an error string".errorize
|
@@ -22,20 +22,22 @@ Easy ANSI code coloring for strings.
|
|
22
22
|
|
23
23
|
=== Basic Styles
|
24
24
|
|
25
|
-
You can define the basic styles for any string by using the
|
25
|
+
You can define the basic styles for any string by using the def_basic_styles method:
|
26
26
|
|
27
27
|
# all basic styles
|
28
|
-
Colorer.
|
28
|
+
Colorer.def_basic_styles
|
29
29
|
"a string".green.bold.reversed.underline...
|
30
30
|
|
31
31
|
# a few basic styles
|
32
|
-
Colorer.define_styles
|
32
|
+
Colorer.define_styles [:bold, :reversed]
|
33
33
|
"a string".bold.reversed
|
34
34
|
|
35
35
|
# one basic style
|
36
|
-
Colorer.define_styles :
|
36
|
+
Colorer.define_styles :red
|
37
37
|
"a string".red
|
38
38
|
|
39
|
+
==== Basic Styles List
|
40
|
+
|
39
41
|
* clear
|
40
42
|
* bold
|
41
43
|
* underline
|
@@ -62,11 +64,11 @@ You can define the basic styles for any string by using the reserved name :basic
|
|
62
64
|
|
63
65
|
=== Custom Styles
|
64
66
|
|
65
|
-
You can define your own custom styles:
|
67
|
+
You can define your own custom styles by aggregating any basic styles names:
|
66
68
|
|
67
|
-
Colorer.
|
68
|
-
|
69
|
-
|
69
|
+
Colorer.def_custom_styles :errorize => [ :red, :bold, :underline ],
|
70
|
+
:okize => [ :green, :bold ],
|
71
|
+
:crazyize => [ :magenta, :onyellow, :bold, :underline ]
|
70
72
|
|
71
73
|
error_string.errorize
|
72
74
|
# same as
|
@@ -78,13 +80,11 @@ You can define your own custom styles:
|
|
78
80
|
# same as
|
79
81
|
crazy_string.magenta.onyellow.bold.underline
|
80
82
|
|
81
|
-
Notice: you cannot use :basic as a custom name, since it is the reserved name used to define the basic styles.
|
82
|
-
|
83
83
|
=== SGR Styles
|
84
84
|
|
85
85
|
You can also add native SGR (Select Graphic Rendition) parameters (0..109) to any style:
|
86
86
|
|
87
|
-
Colorer.
|
87
|
+
Colorer.def_custom_styles :mysgr => [ :red, 8 ]
|
88
88
|
|
89
89
|
See http://en.wikipedia.org/wiki/ANSI_colors for a complete list
|
90
90
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/colorer.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.summary = 'Easy ANSI code coloring for strings'
|
10
10
|
s.description = 'Colorer adds the basic ANSI styles to any string, allowing also to define your own stiles'
|
11
11
|
|
12
|
-
s.add_development_dependency('irt', [">= 0.7.
|
12
|
+
s.add_development_dependency('irt', [">= 0.7.7"])
|
13
13
|
|
14
14
|
s.files = `git ls-files -z`.split("\0")
|
15
15
|
|
data/lib/colorer.rb
CHANGED
@@ -46,18 +46,22 @@ module Colorer
|
|
46
46
|
@color = true
|
47
47
|
attr_accessor :color
|
48
48
|
|
49
|
+
def def_basic_styles(basic=true, force=false)
|
50
|
+
define_styles basic_styles(basic), force
|
51
|
+
end
|
52
|
+
|
53
|
+
def def_custom_styles(styles, force=false)
|
54
|
+
define_styles styles, force
|
55
|
+
end
|
56
|
+
|
49
57
|
def define_styles(styles, force=false)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
when Array
|
56
|
-
basic.each{|k| basic_styles[k] = BASIC_SGR[k]}
|
57
|
-
when Symbol
|
58
|
-
basic_styles[basic] = BASIC_SGR[basic]
|
58
|
+
unless caller[0].match(/def_basic_styles|def_custom_styles/)
|
59
|
+
puts 'DEPRECATION WARNING: :define_styles has been deprecated. Use def_basic_styles and def_custom_styles instead'
|
60
|
+
if styles.keys.include?(:basic)
|
61
|
+
puts 'DEPRECATION WARNING: :basic is not a reserved name anymore: please use def_basic_styles to define the basic methods'
|
62
|
+
styles = basic_styles(styles.delete(:basic)).merge(styles)
|
59
63
|
end
|
60
|
-
|
64
|
+
puts " #{caller[0]}"
|
61
65
|
end
|
62
66
|
styles.each_pair do |meth, style|
|
63
67
|
style = [style] unless style.is_a?(Array)
|
@@ -78,4 +82,19 @@ module Colorer
|
|
78
82
|
end
|
79
83
|
end
|
80
84
|
|
85
|
+
private
|
86
|
+
|
87
|
+
def basic_styles(basic)
|
88
|
+
styles = {}
|
89
|
+
case basic
|
90
|
+
when TrueClass
|
91
|
+
styles = BASIC_SGR
|
92
|
+
when Array
|
93
|
+
basic.each{|k| styles[k] = BASIC_SGR[k]}
|
94
|
+
when Symbol
|
95
|
+
styles[basic] = BASIC_SGR[basic]
|
96
|
+
end
|
97
|
+
styles
|
98
|
+
end
|
99
|
+
|
81
100
|
end
|
data/test/basic.irt
CHANGED
data/test/custom.irt
CHANGED
data/test/selected_basic.irt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'colorer'
|
2
2
|
|
3
|
-
Colorer.
|
3
|
+
Colorer.def_basic_styles([:bold, :red], true)
|
4
4
|
|
5
5
|
desc "red"
|
6
6
|
'red'.red
|
@@ -13,7 +13,7 @@ puts _
|
|
13
13
|
test_value_eql? "\e[0;31;1mred bold\e[0m"
|
14
14
|
|
15
15
|
desc "onwhite"
|
16
|
-
Colorer.
|
16
|
+
Colorer.def_basic_styles([:onwhite], true)
|
17
17
|
'onwhite'.onwhite
|
18
18
|
puts _
|
19
19
|
test_value_eql? "\e[0;47monwhite\e[0m"
|
data/test/sgr.irt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'colorer'
|
2
2
|
|
3
|
-
Colorer.
|
3
|
+
Colorer.def_custom_styles :mixed_sgr => [ :bold, 7 ]
|
4
4
|
|
5
5
|
|
6
6
|
desc "Mixed SGR parameters"
|
@@ -9,7 +9,8 @@ puts _
|
|
9
9
|
test_value_eql? "\e[0;1;7mMixed SGR parameters\e[0m"
|
10
10
|
|
11
11
|
desc "Basic and custom definition"
|
12
|
-
Colorer.
|
12
|
+
Colorer.def_basic_styles true, true
|
13
|
+
Colorer.def_custom_styles({:goo => [7], :guu => 4}, 1)
|
13
14
|
"Basic and custom definition".green.goo.guu
|
14
15
|
puts _
|
15
16
|
test_value_eql? "\e[0;32;7;4mBasic and custom definition\e[0m"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Domizio Demichelis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-21 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 13
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 7
|
33
|
-
-
|
34
|
-
version: 0.7.
|
33
|
+
- 7
|
34
|
+
version: 0.7.7
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
37
|
description: Colorer adds the basic ANSI styles to any string, allowing also to define your own stiles
|