Class: Vic::ColorScheme
- Inherits:
-
Object
- Object
- Vic::ColorScheme
- Defined in:
- lib/vic/color_scheme.rb
Instance Attribute Summary collapse
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#add_info(data = {}) ⇒ Hash
Updates the colorscheme information.
-
#background ⇒ NilClass, ...
Return the background setting.
-
#background! ⇒ String
Sets the background automatically.
-
#background=(setting) ⇒ String, Symbol
Sets the background.
-
#highlight(group, attributes = {}) ⇒ Vic::Highlight
(also: #hi)
Add or update a highlight.
-
#highlight!(group, attributes = {}) ⇒ Vic::Highlight
(also: #hi!)
Add or update a forced highlight.
-
#highlights ⇒ Array
Return the colorscheme’s highlights.
-
#info ⇒ Hash
Return the colorscheme information.
-
#info=(data = {}) ⇒ Hash
Set the colorscheme information.
-
#initialize(title, &block) ⇒ ColorScheme
constructor
A new instance of ColorScheme.
-
#language(name = nil) {|the| ... } ⇒ String, Symbol
Return the language.
-
#language=(name) ⇒ String, Symbol
Set a language to prepend new highlight group names with.
-
#link(*from_groups, to_group) ⇒ Array
Add highlight links to the colorscheme.
-
#link!(*from_groups, to_group) ⇒ Array
Add forced highlight links to the colorscheme.
-
#links ⇒ Array
Return the colorscheme’s links.
-
#render ⇒ String
Render the colorscheme.
Constructor Details
#initialize(title, &block) ⇒ ColorScheme
Returns a new instance of ColorScheme.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/vic/color_scheme.rb', line 5 def initialize(title, &block) @title = title @highlights = [] @links = [] @info = OpenStruct.new if block_given? block.arity.zero? ? instance_eval(&block) : yield(self) end end |
Instance Attribute Details
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/vic/color_scheme.rb', line 3 def title @title end |
Instance Method Details
#add_info(data = {}) ⇒ Hash
Updates the colorscheme information
48 49 50 |
# File 'lib/vic/color_scheme.rb', line 48 def add_info(data = {}) self.info = @info.marshal_dump.merge(data) end |
#background ⇒ NilClass, ...
Return the background setting
56 57 58 |
# File 'lib/vic/color_scheme.rb', line 56 def background @background end |
#background! ⇒ String
Sets the background automatically
By default this will return “dark”. If a highlight with the ‘group` “Normal” and a `guibg` setting has been added to the colorscheme, it will determine the setting to use. If the `guibg` is strictly less than “#808080” the background will be set to “dark” otherwise it will be set to “light”.
88 89 90 91 92 |
# File 'lib/vic/color_scheme.rb', line 88 def background! normal = find_highlight(:Normal) return @background = 'dark' unless normal && normal.guibg @background = normal.guibg[1..-1].to_i(16) < 8421504 ? 'dark' : 'light' end |
#background=(setting) ⇒ String, Symbol
Sets the background
69 70 71 72 73 74 |
# File 'lib/vic/color_scheme.rb', line 69 def background=(setting) unless /\A(light|dark)\z/o.match(setting) raise ArgumentError.new("expected 'light' or 'dark'") end @background = setting end |
#highlight(group, attributes = {}) ⇒ Vic::Highlight Also known as: hi
Add or update a highlight
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vic/color_scheme.rb', line 119 def highlight(group, attributes={}) if hilight = find_highlight(group) hilight.update_attributes!(attributes) else hilight = Highlight.new(:"#{ language }#{ group }", attributes) @highlights << hilight end hilight end |
#highlight!(group, attributes = {}) ⇒ Vic::Highlight Also known as: hi!
Add or update a forced highlight
143 144 145 |
# File 'lib/vic/color_scheme.rb', line 143 def highlight!(group, attributes={}) highlight(group, attributes.dup.tap { |hash| hash[:force] = true }) end |
#highlights ⇒ Array
Return the colorscheme’s highlights
100 101 102 |
# File 'lib/vic/color_scheme.rb', line 100 def highlights @highlights.dup end |
#info ⇒ Hash
Return the colorscheme information
22 23 24 |
# File 'lib/vic/color_scheme.rb', line 22 def info @info.marshal_dump end |
#info=(data = {}) ⇒ Hash
Set the colorscheme information
35 36 37 |
# File 'lib/vic/color_scheme.rb', line 35 def info=(data = {}) @info.marshal_load(data) end |
#language(name = nil) {|the| ... } ⇒ String, Symbol
Return the language
If a name and a block is passed the language will be temporarily set to name inside the block.
251 252 253 254 255 256 257 258 |
# File 'lib/vic/color_scheme.rb', line 251 def language(name = nil, &block) return @language unless name and block_given? previous_language = self.language @language = name block.arity == 0 ? instance_eval(&block) : yield(self) @language = previous_language end |
#language=(name) ⇒ String, Symbol
Set a language to prepend new highlight group names with
225 226 227 |
# File 'lib/vic/color_scheme.rb', line 225 def language=(name) @language = name end |
#link(*from_groups, to_group) ⇒ Array
Add highlight links to the colorscheme
173 174 175 176 177 178 179 180 |
# File 'lib/vic/color_scheme.rb', line 173 def link(*from_groups, to_group) from_groups.flatten.map do |from_group| # Don't add anything we don't already have. next if find_link(from_group, to_group) link = Link.new(from_group, to_group) link.tap { |l| @links << l } end.compact end |
#link!(*from_groups, to_group) ⇒ Array
Add forced highlight links to the colorscheme
201 202 203 204 205 206 207 208 209 210 |
# File 'lib/vic/color_scheme.rb', line 201 def link!(*from_groups, to_group) # Use the default method first. self.link(from_groups, to_group) # Then update the links. from_groups.flatten.map do |from_group| link = find_link(from_group, to_group) link.tap(&:force!) end end |
#links ⇒ Array
Return the colorscheme’s links
154 155 156 |
# File 'lib/vic/color_scheme.rb', line 154 def links @links.dup end |
#render ⇒ String
Render the colorscheme
266 267 268 |
# File 'lib/vic/color_scheme.rb', line 266 def render ColorSchemeWriter.write(self) end |