Class: Vic::Colorscheme::Highlight

Inherits:
Object
  • Object
show all
Defined in:
lib/vic/colorscheme/highlight.rb

Defined Under Namespace

Classes: Argument, ArgumentSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, args = {}) ⇒ Vic::Colorscheme::Highlight

Creates an instance of Vic::Colorscheme::Highlight. Uses ‘update_arguments!` to set the arguments.

Parameters:

  • group (String)

    the group name, ‘Normal’, ‘Function’, etc.

  • args (Hash) (defaults to: {})

    the arguments to set



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

#groupObject

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_setVic::Colorscheme::Highlight::ArgumentSet Also known as: arguments

Returns the set of arguments for the given highlight

Returns:



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.

Parameters:

  • hex (String)

    a hexidecimal color



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.

Parameters:

  • hex (String)

    a hexidecimal color



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.

Parameters:

  • args (Hash) (defaults to: {})

    the arguments to update/set, ‘:guibg => ’#333333’‘

Returns:



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

#writeString

Writes the highlight contents.

Returns:

  • (String)

    the highlight as a string



93
94
95
# File 'lib/vic/colorscheme/highlight.rb', line 93

def write
  "hi #{group} #{arguments.sort_by_key.map(&:write).compact.join(' ')}"
end