Class: Textbringer::Face
- Inherits:
-
Object
- Object
- Textbringer::Face
- Defined in:
- lib/textbringer/face.rb
Constant Summary collapse
- @@face_table =
{}
- @@next_color_pair =
1
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, **opts) ⇒ Face
constructor
A new instance of Face.
- #update(foreground: -1,, background: -1,, bold: false, underline: false, reverse: false) ⇒ Object
Constructor Details
#initialize(name, **opts) ⇒ Face
Returns a new instance of Face.
26 27 28 29 30 31 |
# File 'lib/textbringer/face.rb', line 26 def initialize(name, **opts) @name = name @color_pair = @@next_color_pair @@next_color_pair += 1 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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/textbringer/face.rb', line 5 def name @name end |
Class Method Details
.[](name) ⇒ Object
10 11 12 |
# File 'lib/textbringer/face.rb', line 10 def self.[](name) @@face_table[name] end |
.define(name, **opts) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/textbringer/face.rb', line 14 def self.define(name, **opts) if @@face_table.key?(name) @@face_table[name].update(**opts) else @@face_table[name] = new(name, **opts) end end |
.delete(name) ⇒ Object
22 23 24 |
# File 'lib/textbringer/face.rb', line 22 def self.delete(name) @@face_table.delete(name) end |
Instance Method Details
#update(foreground: -1,, background: -1,, bold: false, underline: false, reverse: false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/textbringer/face.rb', line 33 def update(foreground: -1, background: -1, bold: false, underline: false, reverse: false) @foreground = foreground @background = background @bold = bold @underline = underline @reverse = reverse Curses.init_pair(@color_pair, Color[foreground], Color[background]) @attributes = 0 @attributes |= Curses.color_pair(@color_pair) @attributes |= Curses::A_BOLD if bold @attributes |= Curses::A_UNDERLINE if underline @attributes |= Curses::A_REVERSE if reverse self end |