Class: Muby::Style::ColorPair
- Inherits:
-
Object
- Object
- Muby::Style::ColorPair
- Defined in:
- lib/muby/style.rb
Constant Summary collapse
- @@instances =
[]
- @@initialized =
false
Instance Attribute Summary collapse
-
#bg ⇒ Object
Returns the value of attribute bg.
-
#fg ⇒ Object
Returns the value of attribute fg.
-
#number ⇒ Object
Returns the value of attribute number.
-
#used_at ⇒ Object
Returns the value of attribute used_at.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(number) ⇒ ColorPair
constructor
A new instance of ColorPair.
- #to_i ⇒ Object
- #use(fg, bg) ⇒ Object
Constructor Details
#initialize(number) ⇒ ColorPair
Returns a new instance of ColorPair.
46 47 48 49 |
# File 'lib/muby/style.rb', line 46 def initialize(number) @number = number @used_at = Time.new end |
Instance Attribute Details
#bg ⇒ Object
Returns the value of attribute bg.
44 45 46 |
# File 'lib/muby/style.rb', line 44 def bg @bg end |
#fg ⇒ Object
Returns the value of attribute fg.
44 45 46 |
# File 'lib/muby/style.rb', line 44 def fg @fg end |
#number ⇒ Object
Returns the value of attribute number.
44 45 46 |
# File 'lib/muby/style.rb', line 44 def number @number end |
#used_at ⇒ Object
Returns the value of attribute used_at.
44 45 46 |
# File 'lib/muby/style.rb', line 44 def used_at @used_at end |
Class Method Details
.get_pair(fg, bg) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/muby/style.rb', line 24 def self.get_pair(fg, bg) init_pairs found = @@instances.find do |color| color.bg == bg && color.fg == fg end found = @@instances.find do |color| color.bg.nil? && color.fg.nil? end unless found found = @@instances.sort do |c1, c2| c1.used_at <=> c2.used_at end.first unless found found.use(fg, bg) found end |
Instance Method Details
#to_i ⇒ Object
51 52 53 |
# File 'lib/muby/style.rb', line 51 def to_i Ncurses.COLOR_PAIR(@number) end |
#use(fg, bg) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/muby/style.rb', line 55 def use(fg, bg) @used_at = Time.new if (bg != @bg || fg != @fg) @bg = bg @fg = fg Ncurses.init_pair(@number, @fg, @bg) end end |