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 =
{}
@@default_foreground =
-1
@@default_background =
-1

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)


45
46
47
48
# File 'lib/textbringer/face.rb', line 45

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:



13
14
15
# File 'lib/textbringer/face.rb', line 13

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:



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

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:



27
28
29
# File 'lib/textbringer/face.rb', line 27

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

.set_default_color_numbers(fg_num, bg_num) ⇒ Object

Set the concrete color numbers substituted for -1 (default color). PDCurses resolves -1 when init_pair is called and assume_default_colors only affects color pair 0, so faces must be re-resolved with concrete colors to get the new default colors.



35
36
37
38
39
40
41
42
43
# File 'lib/textbringer/face.rb', line 35

def self.set_default_color_numbers(fg_num, bg_num)
  return if fg_num == @@default_foreground &&
    bg_num == @@default_background
  @@default_foreground = fg_num
  @@default_background = bg_num
  @@face_table.each_value do |face|
    face.send(:resolve_inheritance)
  end
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:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/textbringer/face.rb', line 53

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