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
113
114
115
116
117
118
119
|
# File 'lib/glark/util/colors/options.rb', line 113
def colorize field, str
if field
field + str + Sickill::Rainbow::TERM_EFFECTS[:reset]
else
str
end
end
|
#config_fields ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/glark/util/colors/options.rb', line 97
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
105
106
107
108
109
110
111
|
# File 'lib/glark/util/colors/options.rb', line 105
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
93
94
95
|
# File 'lib/glark/util/colors/options.rb', line 93
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.to_codes color
end
|
#make_colors(limit = -1) ⇒ Object
52
53
54
55
56
|
# File 'lib/glark/util/colors/options.rb', line 52
def make_colors limit = -1
DEFAULT_COLORS[0 .. limit].collect do |color|
make_color color
end
end
|
#multi_colors ⇒ Object
58
59
60
|
# File 'lib/glark/util/colors/options.rb', line 58
def multi_colors
make_colors
end
|
#set_text_color(index, color) ⇒ Object
89
90
91
|
# File 'lib/glark/util/colors/options.rb', line 89
def set_text_color index, color
@text_colors[index] = color
end
|
#single_color ⇒ Object
62
63
64
|
# File 'lib/glark/util/colors/options.rb', line 62
def single_color
make_colors 0
end
|
#update_fields(fields) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/glark/util/colors/options.rb', line 121
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
|