Class: Textbringer::Face

Inherits:
Object
  • Object
show all
Defined in:
lib/textbringer/face.rb

Constant Summary collapse

@@face_table =
{}
@@next_color_pair =
1
@@color_pair_cache =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **opts) ⇒ Face

Returns a new instance of Face.



29
30
31
32
# File 'lib/textbringer/face.rb', line 29

def initialize(name, **opts)
  @name = name
  update(**opts)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/textbringer/face.rb', line 5

def attributes
  @attributes
end

#color_pairObject (readonly)

Returns the value of attribute color_pair.



5
6
7
# File 'lib/textbringer/face.rb', line 5

def color_pair
  @color_pair
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/textbringer/face.rb', line 5

def name
  @name
end

#text_attrsObject (readonly)

Returns the value of attribute text_attrs.



5
6
7
# File 'lib/textbringer/face.rb', line 5

def text_attrs
  @text_attrs
end

Class Method Details

.[](name) ⇒ Object



11
12
13
# File 'lib/textbringer/face.rb', line 11

def self.[](name)
  @@face_table[name]
end

.define(name, **opts) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/textbringer/face.rb', line 15

def self.define(name, **opts)
  if @@face_table.key?(name)
    @@face_table[name].update(**opts)
  else
    @@face_table[name] = new(name, **opts)
  end
  resolve_dependents(name)
  @@face_table[name]
end

.delete(name) ⇒ Object



25
26
27
# File 'lib/textbringer/face.rb', line 25

def self.delete(name)
  @@face_table.delete(name)
end

Instance Method Details

#update(foreground: nil, background: nil, bold: nil, underline: nil, reverse: nil, inherit: UNSET) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/textbringer/face.rb', line 37

def update(foreground: nil, background: nil,
           bold: nil, underline: nil, reverse: nil,
           inherit: UNSET)
  unless inherit.equal?(UNSET)
    if inherit && !inherit.is_a?(Symbol)
      raise EditorError,
            "Face inherit: must be a Symbol, got #{inherit.inspect}"
    end
    if inherit && cyclic_inheritance?(@name, inherit)
      raise EditorError,
            "Cyclic face inheritance: #{@name} inherits from #{inherit}"
    end
    @inherit = inherit
  end
  @explicit_foreground = foreground
  @explicit_background = background
  @explicit_bold = bold
  @explicit_underline = underline
  @explicit_reverse = reverse
  resolve_inheritance
  self
end