Class: Textbringer::Face
- Inherits:
-
Object
- Object
- Textbringer::Face
- 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
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#color_pair ⇒ Object
readonly
Returns the value of attribute color_pair.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#text_attrs ⇒ Object
readonly
Returns the value of attribute text_attrs.
Class Method Summary collapse
- .[](name) ⇒ Textbringer::Face
- .define(name, **opts) ⇒ Object
- .delete(name) ⇒ Textbringer::Face
-
.set_default_color_numbers(fg_num, bg_num) ⇒ Object
Set the concrete color numbers substituted for -1 (default color).
Instance Method Summary collapse
-
#initialize(name, **opts) ⇒ Face
constructor
A new instance of Face.
- #update(foreground: nil, background: nil, bold: nil, underline: nil, reverse: nil, inherit: UNSET) ⇒ Object
Constructor Details
#initialize(arg0, arg1) ⇒ void #initialize(arg0, arg1) ⇒ void #initialize(arg0, arg1) ⇒ void #initialize(arg0, arg1) ⇒ void
Returns a new instance of Face.
45 46 47 48 |
# File 'lib/textbringer/face.rb', line 45 def initialize(name, **opts) @name = name update(**opts) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/textbringer/face.rb', line 5 def attributes @attributes end |
#color_pair ⇒ Object (readonly)
Returns the value of attribute color_pair.
5 6 7 |
# File 'lib/textbringer/face.rb', line 5 def color_pair @color_pair end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/textbringer/face.rb', line 5 def name @name end |
#text_attrs ⇒ Object (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
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
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
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
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 |