Class: Vic::Colorscheme::Highlight
- Inherits:
-
Object
- Object
- Vic::Colorscheme::Highlight
- Defined in:
- lib/vic/colorscheme/highlight.rb
Defined Under Namespace
Classes: Argument, ArgumentSet
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
Instance Method Summary collapse
-
#argument_set ⇒ Vic::Colorscheme::Highlight::ArgumentSet
(also: #arguments)
Returns the set of arguments for the given highlight.
-
#bg=(color) ⇒ Object
Sets guibg and ctermbg simultaneously.
-
#fg=(color) ⇒ Object
Sets guifg and ctermfg simultaneously.
-
#initialize(group, args = {}) ⇒ Vic::Colorscheme::Highlight
constructor
Creates an instance of Vic::Colorscheme::Highlight.
-
#update_arguments!(args = {}) ⇒ Vic::Colorscheme::Highlight::ArgumentSet
Updates/sets the current highlight’s arguments.
-
#write ⇒ String
Writes the highlight contents.
Constructor Details
#initialize(group, args = {}) ⇒ Vic::Colorscheme::Highlight
Creates an instance of Vic::Colorscheme::Highlight. Uses ‘update_arguments!` to set the arguments.
12 13 14 15 16 |
# File 'lib/vic/colorscheme/highlight.rb', line 12 def initialize(group, args={}) # Convert to group name to symbol to ensure consistency @group = group.to_sym update_arguments!(args) end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
4 5 6 |
# File 'lib/vic/colorscheme/highlight.rb', line 4 def group @group end |
Instance Method Details
#argument_set ⇒ Vic::Colorscheme::Highlight::ArgumentSet Also known as: arguments
Returns the set of arguments for the given highlight
85 86 87 |
# File 'lib/vic/colorscheme/highlight.rb', line 85 def argument_set @argument_set ||= ArgumentSet.new end |
#bg=(color) ⇒ Object
Sets guibg and ctermbg simultaneously. ‘hex` is automatically converted to the 256 color code for ctermbg.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vic/colorscheme/highlight.rb', line 61 def bg=(color) if color == 'NONE' self.ctermbg = color elsif Color.is_hexadecimal?(color) self.ctermbg = Color.hex_to_256(color) else raise ColorError.new "invalid hexadecimal color #{color}" end self.guibg = color end |
#fg=(color) ⇒ Object
Sets guifg and ctermfg simultaneously. ‘hex` is automatically converted to the 256 color code for ctermfg.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vic/colorscheme/highlight.rb', line 45 def fg=(color) if color == 'NONE' self.ctermfg = color elsif Color.is_hexadecimal?(color) self.ctermfg = Color.hex_to_256(color) else raise ColorError.new "invalid hexadecimal color #{color}" end self.guifg = color end |
#update_arguments!(args = {}) ⇒ Vic::Colorscheme::Highlight::ArgumentSet
Updates/sets the current highlight’s arguments.
77 78 79 80 |
# File 'lib/vic/colorscheme/highlight.rb', line 77 def update_arguments!(args={}) args.each {|key, val| send("#{key}=", val)} arguments end |
#write ⇒ String
Writes the highlight contents.
93 94 95 |
# File 'lib/vic/colorscheme/highlight.rb', line 93 def write "hi #{group} #{arguments.sort_by_key.map(&:write).compact.join(' ')}" end |