Class: Textbringer::Face

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

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(arg0, arg1) ⇒ void #initialize(arg0, arg1) ⇒ void #initialize(arg0, arg1) ⇒ void #initialize(arg0, arg1) ⇒ void

Returns a new instance of Face.

Overloads:

  • #initialize(arg0, arg1) ⇒ void

    Parameters:

    • arg0 (Symbol)
    • arg1 (Boolean)
  • #initialize(arg0, arg1) ⇒ void

    Parameters:

    • arg0 (Symbol)
    • arg1 (String, bool)
  • #initialize(arg0, arg1) ⇒ void

    Parameters:

    • arg0 (Symbol)
    • arg1 (nil)
  • #initialize(arg0, arg1) ⇒ void

    Parameters:

    • arg0 (Symbol)
    • arg1 (String)


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) ⇒ Textbringer::Face

Parameters:

  • (Symbol)

Returns:



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

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

.define(arg0, arg1) ⇒ Textbringer::Face .define(arg0, arg1) ⇒ Textbringer::Face .define(arg0, arg1) ⇒ Textbringer::Face .define(arg0, arg1) ⇒ Textbringer::Face

Overloads:



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) ⇒ Textbringer::Face

Parameters:

  • (Symbol)

Returns:



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

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

Instance Method Details

#update(foreground:, background:, bold:, underline:, reverse:) ⇒ Textbringer::Face #update(foreground:, background:, bold:, underline:, reverse:) ⇒ Textbringer::Face #update(foreground:, background:, bold:, underline:, reverse:) ⇒ Textbringer::Face

Overloads:

  • #update(foreground:, background:, bold:, underline:, reverse:) ⇒ Textbringer::Face

    Parameters:

    • foreground: (Integer)
    • background: (Integer)
    • bold: (Boolean)
    • underline: (Boolean)
    • reverse: (Boolean)

    Returns:

  • #update(foreground:, background:, bold:, underline:, reverse:) ⇒ Textbringer::Face

    Parameters:

    • foreground: (String)
    • background: (Integer)
    • bold: (Boolean)
    • underline: (Boolean)
    • reverse: (Boolean)

    Returns:

  • #update(foreground:, background:, bold:, underline:, reverse:) ⇒ Textbringer::Face

    Parameters:

    • foreground: (String)
    • background: (String)
    • bold: (Boolean)
    • underline: (Boolean)
    • reverse: (Boolean)

    Returns:



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