Class: Glark::ColorOptions
Constant Summary
collapse
- DEFAULT_COLORS =
[
"black on yellow",
"black on green",
"black on magenta",
"yellow on black",
"magenta on black",
"green on black",
"cyan on black",
"blue on yellow",
"blue on magenta",
"blue on green",
"blue on cyan",
"yellow on blue",
"magenta on blue",
"green on blue",
"cyan on blue",
]
Instance Attribute Summary collapse
Attributes inherited from ColorSpec
#file_name_color, #line_number_color, #text_colors
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ColorOptions.
29
30
31
32
33
|
# File 'lib/glark/util/colors/options.rb', line 29
def initialize
super
@highlighter = nil
@text_color_style = "multi"
end
|
Instance Attribute Details
#text_color_style ⇒ Object
single, multi, or nil (no text highlights)
27
28
29
|
# File 'lib/glark/util/colors/options.rb', line 27
def text_color_style
@text_color_style
end
|
Instance Method Details
#colorize(field, str) ⇒ Object
117
118
119
120
121
122
123
|
# File 'lib/glark/util/colors/options.rb', line 117
def colorize field, str
if field
field + str + Sickill::Rainbow::TERM_EFFECTS[:reset]
else
str
end
end
|
#config_fields ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/glark/util/colors/options.rb', line 101
def config_fields
{
"file-color" => @file_name_color,
"highlight" => @text_color_style,
"line-number-color" => @line_number_color,
}
end
|
#create_color(opt, value) ⇒ Object
creates a color for the given option, based on its value
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/glark/util/colors/options.rb', line 36
def create_color opt, value
if @highlighter
if value
make_color value
else
raise "error: '" + opt + "' requires a color"
end
else
log { "no highlighter defined" }
end
end
|
#dump_fields ⇒ Object
109
110
111
112
113
114
115
|
# File 'lib/glark/util/colors/options.rb', line 109
def dump_fields
{
"file_name_color" => colorize(@file_name_color, "filename"),
"highlight" => @text_color_style,
"line_number_color" => colorize(@line_number_color, "12345"),
}
end
|
#highlight_multi?(str) ⇒ Boolean
97
98
99
|
# File 'lib/glark/util/colors/options.rb', line 97
def highlight_multi? str
%w{ multi on true yes }.detect { |x| str == x }
end
|
#make_color(color) ⇒ Object
48
49
50
|
# File 'lib/glark/util/colors/options.rb', line 48
def make_color color
@highlighter.make_color color
end
|
#make_colors(limit = -1) ⇒ Object
56
57
58
59
60
|
# File 'lib/glark/util/colors/options.rb', line 56
def make_colors limit = -1
DEFAULT_COLORS[0 .. limit].collect do |color|
make_color color
end
end
|
#make_rgb_color(red, green, blue, fgbg) ⇒ Object
52
53
54
|
# File 'lib/glark/util/colors/options.rb', line 52
def make_rgb_color red, green, blue, fgbg
@highlighter.make_rgb_color red, green, blue, fgbg
end
|
#multi_colors ⇒ Object
62
63
64
|
# File 'lib/glark/util/colors/options.rb', line 62
def multi_colors
make_colors
end
|
#set_text_color(index, color) ⇒ Object
93
94
95
|
# File 'lib/glark/util/colors/options.rb', line 93
def set_text_color index, color
@text_colors[index] = color
end
|
#single_color ⇒ Object
66
67
68
|
# File 'lib/glark/util/colors/options.rb', line 66
def single_color
make_colors 0
end
|
#update_fields(fields) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/glark/util/colors/options.rb', line 125
def update_fields fields
fields.each do |name, values|
case name
when "file-color"
@file_name_color = create_color name, values.last
when "highlight"
self.text_color_style = values.last
when "line-number-color"
@line_number_color = create_color name, values.last
when "text-color"
@text_colors = [ create_color(name, values.last) ]
when %r{^text\-color\-(\d+)$}
set_text_color $1.to_i, create_color(name, values.last)
end
end
end
|