Module: Philiprehberger::Color
- Defined in:
- lib/philiprehberger/color.rb,
lib/philiprehberger/color/ansi.rb,
lib/philiprehberger/color/styler.rb,
lib/philiprehberger/color/version.rb,
lib/philiprehberger/color/detection.rb
Defined Under Namespace
Modules: Ansi, Detection
Classes: Styler
Constant Summary
collapse
- ANSI_PATTERN =
/\e\[[0-9;]*m/
- VERSION =
'0.5.0'
Class Method Summary
collapse
Class Method Details
.bg(color_name) ⇒ Object
52
53
54
|
# File 'lib/philiprehberger/color.rb', line 52
def self.bg(color_name)
Styler.new.bg(color_name)
end
|
.bg_hex(hex_string) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/philiprehberger/color.rb', line 60
def self.bg_hex(hex_string)
hex = hex_string.delete('#')
r = hex[0..1].to_i(16)
g = hex[2..3].to_i(16)
b = hex[4..5].to_i(16)
bg_rgb(r, g, b)
end
|
.bg_rgb(red, green, blue) ⇒ Object
56
57
58
|
# File 'lib/philiprehberger/color.rb', line 56
def self.bg_rgb(red, green, blue)
Styler.new.bg_rgb(red, green, blue)
end
|
.bold ⇒ Object
24
25
26
|
# File 'lib/philiprehberger/color.rb', line 24
def self.bold
Styler.new.bold
end
|
.dim ⇒ Object
28
29
30
|
# File 'lib/philiprehberger/color.rb', line 28
def self.dim
Styler.new.dim
end
|
.enabled? ⇒ Boolean
20
21
22
|
# File 'lib/philiprehberger/color.rb', line 20
def self.enabled?
Detection.enabled?
end
|
.hex(hex_string) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/philiprehberger/color.rb', line 44
def self.hex(hex_string)
hex = hex_string.delete('#')
r = hex[0..1].to_i(16)
g = hex[2..3].to_i(16)
b = hex[4..5].to_i(16)
rgb(r, g, b)
end
|
.italic ⇒ Object
32
33
34
|
# File 'lib/philiprehberger/color.rb', line 32
def self.italic
Styler.new.italic
end
|
.rainbow(text) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/philiprehberger/color.rb', line 68
def self.rainbow(text)
return text unless enabled?
colors = [31, 33, 32, 36, 34, 35] text.chars.map.with_index { |c, i| c == ' ' ? c : "\e[#{colors[i % colors.length]}m#{c}\e[0m" }.join
end
|
.rgb(red, green, blue) ⇒ Object
40
41
42
|
# File 'lib/philiprehberger/color.rb', line 40
def self.rgb(red, green, blue)
Styler.new.rgb(red, green, blue)
end
|
.strip(string) ⇒ Object
12
13
14
|
# File 'lib/philiprehberger/color.rb', line 12
def self.strip(string)
string.to_s.gsub(ANSI_PATTERN, '')
end
|
.underline ⇒ Object
36
37
38
|
# File 'lib/philiprehberger/color.rb', line 36
def self.underline
Styler.new.underline
end
|
.visible_length(string) ⇒ Object
16
17
18
|
# File 'lib/philiprehberger/color.rb', line 16
def self.visible_length(string)
strip(string).length
end
|