color_me_rad 0.0.1
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 +7 -0
- data/.cane +6 -0
- data/.tool-versions +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/color_me_rad.gemspec +27 -0
- data/lib/color_me_rad.rb +4 -0
- data/lib/color_me_rad/color_helper.rb +142 -0
- data/lib/color_me_rad/colorize.rb +69 -0
- data/lib/color_me_rad/configuration.rb +149 -0
- data/lib/color_me_rad/core.rb +76 -0
- data/rakefile +18 -0
- data/readme.md +146 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f60003287d1971131377f2d97340241dceebfd08f15d9b1ea1136bb12c20f5e6
|
4
|
+
data.tar.gz: f547c73a02f943b9dae8394f7bdedb23117d0d8b88b66edb4291f8c53aa707c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91c890b6bd3bd4cff5ceb25fc56bf0e34cd6345002411de296da6d4faa8514b96f7d8fe74ba1572f856248afdbf3961575edcfeccbc2f0c2c17ad096722aaae4
|
7
|
+
data.tar.gz: 865b0b3b7152abe2c6f885d58dd7f378c881f4efe512c84bd1e0dc0ce86b891c8f1e1ef1aca9a2e51a1e3379cc710e090f40c88c60f70be561c1b391b9025526
|
data/.cane
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.5.1
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
color_me_rad (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
cane (3.0.0)
|
10
|
+
parallel
|
11
|
+
diff-lcs (1.3)
|
12
|
+
gems (1.1.1)
|
13
|
+
json
|
14
|
+
json (2.2.0)
|
15
|
+
parallel (1.14.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rake_tasks (5.1.0)
|
18
|
+
rake
|
19
|
+
rspec (3.8.0)
|
20
|
+
rspec-core (~> 3.8.0)
|
21
|
+
rspec-expectations (~> 3.8.0)
|
22
|
+
rspec-mocks (~> 3.8.0)
|
23
|
+
rspec-core (3.8.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-expectations (3.8.2)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.8.0)
|
28
|
+
rspec-mocks (3.8.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-support (3.8.0)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
cane
|
38
|
+
color_me_rad!
|
39
|
+
gems
|
40
|
+
rake
|
41
|
+
rake_tasks
|
42
|
+
rspec
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
1.16.3
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "color_me_rad"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'color_me_rad'
|
3
|
+
spec.version = '0.0.1'
|
4
|
+
spec.authors = ['Travis Herrick']
|
5
|
+
spec.email = ['tthetoad@gmail.com']
|
6
|
+
|
7
|
+
spec.summary = 'Simple color console output'
|
8
|
+
spec.description = 'Color console output in a radically simple way'
|
9
|
+
spec.homepage = 'https://bitbucket.org/toadjamb/gems_color_me_rad'
|
10
|
+
|
11
|
+
# Specify which files should be added to the gem when it is released.
|
12
|
+
# The `git ls-files -z` loads the files that have been added into git.
|
13
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
14
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rake_tasks'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'cane'
|
26
|
+
spec.add_development_dependency 'gems'
|
27
|
+
end
|
data/lib/color_me_rad.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
module ColorMeRad
|
2
|
+
module ColorHelper
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def data(data)
|
6
|
+
return hash(data) if data.is_a?(Hash)
|
7
|
+
return array(data) if enumerable?(data)
|
8
|
+
return ar_data(data) if active_record?(data)
|
9
|
+
return ruby_ivars(data) if ivars?(data)
|
10
|
+
|
11
|
+
colorize_data data
|
12
|
+
end
|
13
|
+
|
14
|
+
def key(data, key)
|
15
|
+
color = ColorMeRad.color_for_key(key)
|
16
|
+
add_color data, color
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def hash(hash)
|
22
|
+
string = key('{', 'Hash')
|
23
|
+
string += map_hash_data(hash)
|
24
|
+
string + key('}', 'Hash')
|
25
|
+
end
|
26
|
+
|
27
|
+
def array(array)
|
28
|
+
string = key('[', 'Array')
|
29
|
+
|
30
|
+
string += array.each.map do |value|
|
31
|
+
data value
|
32
|
+
end.join(key(',', :syntax))
|
33
|
+
|
34
|
+
string + key(']', 'Array')
|
35
|
+
end
|
36
|
+
|
37
|
+
def ruby_ivars(data)
|
38
|
+
as_object(data) do
|
39
|
+
map_ivars data
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def ar_data(data)
|
44
|
+
as_object(data) do
|
45
|
+
map_ar_attributes data.attributes
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def as_object(data, &block)
|
50
|
+
string = data.to_s
|
51
|
+
strings = string.match(/(#<)(\S+)(:)(\w+)(>)/)
|
52
|
+
|
53
|
+
'%s%s%s%s %s%s' % [
|
54
|
+
key(strings[1], :syntax),
|
55
|
+
key(strings[2], :constant),
|
56
|
+
key(strings[3], :syntax),
|
57
|
+
key(strings[4], 'Integer'),
|
58
|
+
yield,
|
59
|
+
key(strings[5], :syntax),
|
60
|
+
]
|
61
|
+
end
|
62
|
+
|
63
|
+
def colorize_data(data)
|
64
|
+
color ||= color_for_data_class(data)
|
65
|
+
data = data.inspect if [String].include?(data.class)
|
66
|
+
|
67
|
+
add_color data, color
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_color(data, color)
|
71
|
+
data = data.inspect if [NilClass, Symbol].include?(data.class)
|
72
|
+
data = data.to_s unless data.is_a?(String)
|
73
|
+
|
74
|
+
ColorMeRad.colorize data, color
|
75
|
+
end
|
76
|
+
|
77
|
+
def colorize(text, foreground = nil, background = nil)
|
78
|
+
ColorMeRad.colorize text, foreground, background
|
79
|
+
end
|
80
|
+
|
81
|
+
def map_hash_data(hash)
|
82
|
+
hash.each.map do |key, value|
|
83
|
+
'%s%s%s' % [
|
84
|
+
data(key),
|
85
|
+
key('=>', :syntax),
|
86
|
+
data(value),
|
87
|
+
]
|
88
|
+
end.join(key(',', :syntax))
|
89
|
+
end
|
90
|
+
|
91
|
+
def map_ivars(data)
|
92
|
+
data.instance_variables.map do |var|
|
93
|
+
value = data.instance_variable_get(var)
|
94
|
+
format_ivar var, value
|
95
|
+
end.join(' ')
|
96
|
+
end
|
97
|
+
|
98
|
+
def format_ivar(var, value)
|
99
|
+
'%s%s%s' % [
|
100
|
+
key(var.to_s, :ivar),
|
101
|
+
key('=', :syntax),
|
102
|
+
data(value),
|
103
|
+
]
|
104
|
+
end
|
105
|
+
|
106
|
+
def map_ar_attributes(attrs)
|
107
|
+
attrs.map do |key, value|
|
108
|
+
'%s%s%s' % [
|
109
|
+
key("@#{key}", :ivar),
|
110
|
+
key('=', :syntax),
|
111
|
+
data(value),
|
112
|
+
]
|
113
|
+
end.join(' ')
|
114
|
+
end
|
115
|
+
|
116
|
+
def color_for_data_class(data)
|
117
|
+
ColorMeRad.color_for_class data.class
|
118
|
+
end
|
119
|
+
|
120
|
+
def ivars?(data)
|
121
|
+
return false unless ColorMeRad.ivars?
|
122
|
+
return false unless data.respond_to?(:instance_variables)
|
123
|
+
if defined?(ActiveRecord) && data.is_a?(ActiveRecord::Base)
|
124
|
+
return false
|
125
|
+
end
|
126
|
+
return false if data.instance_variables.empty?
|
127
|
+
true
|
128
|
+
end
|
129
|
+
|
130
|
+
def active_record?(data)
|
131
|
+
return false unless ColorMeRad.active_record?
|
132
|
+
return false unless defined?(ActiveRecord)
|
133
|
+
data.is_a? ActiveRecord::Base
|
134
|
+
end
|
135
|
+
|
136
|
+
def enumerable?(data)
|
137
|
+
return false unless data.respond_to?(:each)
|
138
|
+
return false if data.respond_to?(:keys)
|
139
|
+
true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module ColorMeRad
|
2
|
+
module Colorize
|
3
|
+
extend self
|
4
|
+
|
5
|
+
CODES = {
|
6
|
+
:black => 0, :light_black => 60,
|
7
|
+
:red => 1, :light_red => 61,
|
8
|
+
:green => 2, :light_green => 62,
|
9
|
+
:yellow => 3, :light_yellow => 63,
|
10
|
+
:blue => 4, :light_blue => 64,
|
11
|
+
:magenta => 5, :light_magenta => 65,
|
12
|
+
:cyan => 6, :light_cyan => 66,
|
13
|
+
:white => 7, :light_white => 67,
|
14
|
+
:default => 9
|
15
|
+
}
|
16
|
+
|
17
|
+
def colorize(text, foreground, background)
|
18
|
+
return text unless ColorMeRad.enabled?
|
19
|
+
|
20
|
+
text = set_foreground(text, foreground) if foreground
|
21
|
+
text = set_background(text, background) if background
|
22
|
+
|
23
|
+
text
|
24
|
+
end
|
25
|
+
|
26
|
+
def show_samples
|
27
|
+
CODES.keys.permutation(2).each do |background, foreground|
|
28
|
+
message = sample_message(background, foreground, 13)
|
29
|
+
puts colorize(message, foreground, background)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def enable_color=(value)
|
34
|
+
@enable_color = !!value
|
35
|
+
end
|
36
|
+
|
37
|
+
def colorized?
|
38
|
+
return @enable_color if defined?(@enable_color)
|
39
|
+
@enable_color = true
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def set_foreground(text, color)
|
45
|
+
return text unless CODES[color]
|
46
|
+
|
47
|
+
code = CODES[color] + 30
|
48
|
+
text = text.split("\e[0m").map do |string|
|
49
|
+
"\033[#{code}m#{string}\e[0m"
|
50
|
+
end.join
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_background(text, color)
|
54
|
+
return text unless CODES[color]
|
55
|
+
|
56
|
+
code = CODES[color] + 40
|
57
|
+
text = text.split("\e[0m").map do |string|
|
58
|
+
"\033[#{code}m#{string}\e[0m"
|
59
|
+
end.join
|
60
|
+
end
|
61
|
+
|
62
|
+
def sample_message(background, foreground, pad)
|
63
|
+
' example of %s on %s ' % [
|
64
|
+
foreground.to_s.ljust(pad),
|
65
|
+
background.to_s.ljust(pad),
|
66
|
+
]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
module ColorMeRad
|
2
|
+
class Configuration
|
3
|
+
attr_reader :classes, :keys
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def current_config
|
7
|
+
@configuration ||= new
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
self.enabled = true
|
13
|
+
self.ivars = false
|
14
|
+
self.active_record = false
|
15
|
+
|
16
|
+
@keys = {
|
17
|
+
:constant => :yellow,
|
18
|
+
:ivar => :light_green,
|
19
|
+
:syntax => :light_black,
|
20
|
+
}
|
21
|
+
|
22
|
+
@classes = {
|
23
|
+
'Fixnum' => :red,
|
24
|
+
"#{Integer}" => :red,
|
25
|
+
"#{String}" => :black,
|
26
|
+
'Date' => :light_magenta,
|
27
|
+
'DateTime' => :light_cyan,
|
28
|
+
"#{Time}" => :light_cyan,
|
29
|
+
'BigDecimal' => :red,
|
30
|
+
"#{TrueClass}" => :cyan,
|
31
|
+
"#{FalseClass}" => :cyan,
|
32
|
+
"#{NilClass}" => :yellow,
|
33
|
+
"#{Symbol}" => :light_green,
|
34
|
+
"#{Hash}" => :yellow,
|
35
|
+
"#{Array}" => :yellow,
|
36
|
+
"#{Float}" => :red,
|
37
|
+
"#{Class}" => :yellow,
|
38
|
+
"#{Module}" => :yellow,
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def enabled=(value)
|
43
|
+
@enabled = !!value
|
44
|
+
end
|
45
|
+
|
46
|
+
def enabled?
|
47
|
+
@enabled
|
48
|
+
end
|
49
|
+
|
50
|
+
def ivars=(value)
|
51
|
+
@ivars = !!value
|
52
|
+
end
|
53
|
+
|
54
|
+
def ivars?
|
55
|
+
@ivars
|
56
|
+
end
|
57
|
+
|
58
|
+
def active_record=(value)
|
59
|
+
@active_record = !!value
|
60
|
+
end
|
61
|
+
|
62
|
+
def active_record?
|
63
|
+
@active_record
|
64
|
+
end
|
65
|
+
|
66
|
+
def color_for_class(klass)
|
67
|
+
color_for_key klass.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
def color_for_key(key)
|
71
|
+
color = @classes[key] || @keys[key]
|
72
|
+
color ||= key if Colorize::CODES[key]
|
73
|
+
color
|
74
|
+
end
|
75
|
+
|
76
|
+
def set_colors(keys)
|
77
|
+
validate_hash keys
|
78
|
+
keys.each do |key, color|
|
79
|
+
set_color key, color
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def set_color(key, color)
|
84
|
+
validate_key key, color
|
85
|
+
@keys.merge! key => color
|
86
|
+
end
|
87
|
+
|
88
|
+
def set_class_colors(keys)
|
89
|
+
validate_hash keys
|
90
|
+
keys.each do |key, color|
|
91
|
+
set_class_color key, color
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def set_class_color(key, color)
|
96
|
+
validate_class_key key, color
|
97
|
+
@classes.merge! key => color
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def validate_hash(value)
|
103
|
+
return if value.is_a?(Hash)
|
104
|
+
errors = []
|
105
|
+
errors << "Not a hash: #{value.inspect}"
|
106
|
+
show_errors errors
|
107
|
+
end
|
108
|
+
|
109
|
+
def validate_key(key, color)
|
110
|
+
errors = []
|
111
|
+
|
112
|
+
validate_color color, errors
|
113
|
+
validate_unique_key key, errors
|
114
|
+
|
115
|
+
show_errors errors
|
116
|
+
end
|
117
|
+
|
118
|
+
def validate_class_key(key, color)
|
119
|
+
errors = []
|
120
|
+
|
121
|
+
validate_color color, errors
|
122
|
+
validate_used_key key, errors
|
123
|
+
|
124
|
+
show_errors errors
|
125
|
+
end
|
126
|
+
|
127
|
+
def validate_color(color, errors)
|
128
|
+
return if ColorMeRad::Colorize::CODES.keys.include?(color)
|
129
|
+
errors << "#{color} is not a valid color"
|
130
|
+
end
|
131
|
+
|
132
|
+
def validate_unique_key(key, errors)
|
133
|
+
return unless @classes[key]
|
134
|
+
errors << '%s is used in class settings: use #set_class_color instead' % [
|
135
|
+
key.inspect,
|
136
|
+
]
|
137
|
+
end
|
138
|
+
|
139
|
+
def validate_used_key(key, errors)
|
140
|
+
return if @classes.keys.include?(key)
|
141
|
+
errors << "key is not expected in class settings: #{key.inspect}"
|
142
|
+
end
|
143
|
+
|
144
|
+
def show_errors(errors)
|
145
|
+
return if errors.empty?
|
146
|
+
raise "#{ColorMeRad::Configuration}: " + errors.join('. ') + '.'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module ColorMeRad
|
2
|
+
module Core
|
3
|
+
# configuration methods
|
4
|
+
|
5
|
+
def configure(&block)
|
6
|
+
yield Configuration.current_config
|
7
|
+
end
|
8
|
+
|
9
|
+
def enabled=(value)
|
10
|
+
configuration.enabled = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def enable!
|
14
|
+
configuration.enabled = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def disable!
|
18
|
+
configuration.enabled = false
|
19
|
+
end
|
20
|
+
|
21
|
+
def enabled?
|
22
|
+
configuration.enabled?
|
23
|
+
end
|
24
|
+
|
25
|
+
def ivars?
|
26
|
+
configuration.ivars?
|
27
|
+
end
|
28
|
+
|
29
|
+
def active_record?
|
30
|
+
configuration.active_record?
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# examples and samples
|
35
|
+
|
36
|
+
def show_color_samples
|
37
|
+
Colorize.show_samples
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# colorization methods
|
42
|
+
|
43
|
+
# TODO: test (officially)
|
44
|
+
def colorize(data, foreground = nil, background = nil)
|
45
|
+
Colorize.colorize data, foreground, background
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO: test (officially)
|
49
|
+
def data(data)
|
50
|
+
ColorHelper.data data
|
51
|
+
end
|
52
|
+
|
53
|
+
# TODO: test (officially)
|
54
|
+
def key(data, key)
|
55
|
+
ColorHelper.key data, key
|
56
|
+
end
|
57
|
+
|
58
|
+
# TODO: test
|
59
|
+
def color_for_key(key)
|
60
|
+
configuration.color_for_key key
|
61
|
+
end
|
62
|
+
|
63
|
+
# TODO: test
|
64
|
+
def color_for_class(klass)
|
65
|
+
configuration.color_for_class klass
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def configuration
|
71
|
+
Configuration.current_config
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
extend Core
|
76
|
+
end
|
data/rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$VERBOSE = true
|
2
|
+
|
3
|
+
require 'rake_tasks'
|
4
|
+
|
5
|
+
require 'io/console'
|
6
|
+
require 'rake_tasks/tasks/release'
|
7
|
+
|
8
|
+
require 'rake_tasks/tasks/spec'
|
9
|
+
|
10
|
+
$VERBOSE = nil
|
11
|
+
require 'cane'
|
12
|
+
require 'rake_tasks/tasks/cane'
|
13
|
+
$VERBOSE = true
|
14
|
+
|
15
|
+
task :default => [
|
16
|
+
:cane,
|
17
|
+
:specs,
|
18
|
+
]
|
data/readme.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
ColorMeRad
|
2
|
+
==========
|
3
|
+
|
4
|
+
Standardize the way you color your data and messages.
|
5
|
+
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'color_me_rad'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install color_me_rad
|
23
|
+
|
24
|
+
|
25
|
+
Usage
|
26
|
+
-----
|
27
|
+
|
28
|
+
### Basic API
|
29
|
+
|
30
|
+
Print a hash that has keys and values colored according to configuration:
|
31
|
+
|
32
|
+
> puts ColorMeRad.data({:foo => 'bar'}
|
33
|
+
|
34
|
+
Print a string that is colored using a custom setting
|
35
|
+
(must be set using one of the configuration methods below):
|
36
|
+
|
37
|
+
> puts ColorMeRad.key('foo', :title)
|
38
|
+
|
39
|
+
Return the color for a given class:
|
40
|
+
|
41
|
+
> ColorMeRad.color_for_class(String) #=> :black
|
42
|
+
|
43
|
+
Return the color for a given key:
|
44
|
+
|
45
|
+
> ColorMeRad.color_for_key('String') #=> :black
|
46
|
+
|
47
|
+
`key` and `color_for_key` will look in both class settings
|
48
|
+
and custom settings for a color,
|
49
|
+
so give it any key that has a color associated with it
|
50
|
+
and it will give you the color back.
|
51
|
+
|
52
|
+
|
53
|
+
### Configuration
|
54
|
+
|
55
|
+
#### Enabling/Disabling
|
56
|
+
|
57
|
+
```
|
58
|
+
# via configuration
|
59
|
+
ColorMeRad.configure do |config|
|
60
|
+
config.enabled = true #=> turn on all coloring
|
61
|
+
config.enabled = false #=> turn off all coloring
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
# via module api (useful for disabling during testing)
|
66
|
+
|
67
|
+
ColorMeRad.enabled = true #=> turn on all coloring
|
68
|
+
ColorMeRad.enabled? #=> true
|
69
|
+
|
70
|
+
ColorMeRad.enabled = false #=> turn off all coloring
|
71
|
+
ColorMeRad.enabled? #=> false
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
#### Colors
|
77
|
+
|
78
|
+
If you intend to override color settings
|
79
|
+
or add your own, it is intended to happen via the configure block:
|
80
|
+
|
81
|
+
|
82
|
+
##### Override Existing Colors (class names)
|
83
|
+
|
84
|
+
A number of Ruby classes have colors set initially.
|
85
|
+
If you want to override these,
|
86
|
+
it can be done using `set_class_color` or `set_class_colors`.
|
87
|
+
|
88
|
+
Please note that if you attempt to set one of these keys
|
89
|
+
using the `set_color` or `set_colors` api,
|
90
|
+
an error will be raised.
|
91
|
+
|
92
|
+
|
93
|
+
```
|
94
|
+
ColorMeRad.configure do |config|
|
95
|
+
config.set_class_color 'Integer', :green
|
96
|
+
config.set_class_color 'String', :blue
|
97
|
+
|
98
|
+
config.set_class_colors({
|
99
|
+
'TrueClass' => :light_magenta,
|
100
|
+
'FalseClass' => :light_cyan,
|
101
|
+
})
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
|
106
|
+
##### Add new color settings
|
107
|
+
|
108
|
+
Please note that if you attempt to set one of the class keys
|
109
|
+
using the `set_class_color` or `set_class_colors` api,
|
110
|
+
an error will be raised.
|
111
|
+
|
112
|
+
|
113
|
+
```
|
114
|
+
ColorMeRad.configure do |config|
|
115
|
+
config.set_color :title, :green
|
116
|
+
config.set_color :author, :blue
|
117
|
+
|
118
|
+
config.set_colors({
|
119
|
+
:error => :light_red,
|
120
|
+
:warn => :red,
|
121
|
+
})
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
Development
|
127
|
+
-----------
|
128
|
+
|
129
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
130
|
+
Then, run `bundle exec rake spec` to run the tests.
|
131
|
+
You can also run `bin/console` for an interactive prompt
|
132
|
+
that will allow you to experiment.
|
133
|
+
|
134
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
135
|
+
To release a new version, update the version number in `version.rb`,
|
136
|
+
and then run `bundle exec rake release`,
|
137
|
+
which will create a git tag for the version,
|
138
|
+
push git commits and tags,
|
139
|
+
and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
140
|
+
|
141
|
+
|
142
|
+
Contributing
|
143
|
+
------------
|
144
|
+
|
145
|
+
Bug reports and pull requests are welcome on Bitbucket
|
146
|
+
at https://bitbucket.org/toadjamb/gems_color_me_rad.
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: color_me_rad
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Herrick
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake_tasks
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cane
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: gems
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Color console output in a radically simple way
|
84
|
+
email:
|
85
|
+
- tthetoad@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".cane"
|
91
|
+
- ".tool-versions"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- bin/console
|
95
|
+
- bin/setup
|
96
|
+
- color_me_rad.gemspec
|
97
|
+
- lib/color_me_rad.rb
|
98
|
+
- lib/color_me_rad/color_helper.rb
|
99
|
+
- lib/color_me_rad/colorize.rb
|
100
|
+
- lib/color_me_rad/configuration.rb
|
101
|
+
- lib/color_me_rad/core.rb
|
102
|
+
- rakefile
|
103
|
+
- readme.md
|
104
|
+
homepage: https://bitbucket.org/toadjamb/gems_color_me_rad
|
105
|
+
licenses: []
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Simple color console output
|
127
|
+
test_files: []
|