Class: Muby::Style
- Inherits:
-
Object
- Object
- Muby::Style
- Includes:
- Configurable, Logger
- Defined in:
- lib/muby/style.rb
Overview
The encapsulation of all the ncurses horror.
Defined Under Namespace
Classes: ColorPair
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#color1 ⇒ Object
readonly
Returns the value of attribute color1.
-
#color2 ⇒ Object
readonly
Returns the value of attribute color2.
Class Method Summary collapse
-
.extract(window) ⇒ Object
Get a Style instance from a window (so we can save it and restore it).
Instance Method Summary collapse
-
#affect(window) ⇒ Object
Affect the window, either overwriting its style or adding to it.
- #get_color_value(fg, bg) ⇒ Object
-
#initialize(attributes, color1, color2, toAdd = false) ⇒ Style
constructor
A new instance of Style.
-
#to_int(window) ⇒ Object
Get an int representation of this style, to send to ncurses.
Methods included from Configurable
Methods included from Logger
Constructor Details
#initialize(attributes, color1, color2, toAdd = false) ⇒ Style
Returns a new instance of Style.
65 66 67 68 69 70 |
# File 'lib/muby/style.rb', line 65 def initialize(attributes, color1, color2, toAdd = false) @attributes = attributes @color1 = color1 @color2 = color2 @toAdd = toAdd end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
11 12 13 |
# File 'lib/muby/style.rb', line 11 def attributes @attributes end |
#color1 ⇒ Object (readonly)
Returns the value of attribute color1.
11 12 13 |
# File 'lib/muby/style.rb', line 11 def color1 @color1 end |
#color2 ⇒ Object (readonly)
Returns the value of attribute color2.
11 12 13 |
# File 'lib/muby/style.rb', line 11 def color2 @color2 end |
Class Method Details
.extract(window) ⇒ Object
Get a Style instance from a window (so we can save it and restore it)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/muby/style.rb', line 75 def self.extract(window) tmp = [] oldAttributes = [] oldAttribute = 0 oldColorPair = [] oldColor1 = [] oldColor2 = [] window.wattr_get(oldAttributes,oldColorPair,tmp) oldAttribute = oldAttributes[0] ^ Ncurses.COLOR_PAIR(oldColorPair[0]) Ncurses.pair_content(oldColorPair[0], oldColor1, oldColor2) Muby::Style.new(oldAttribute, oldColor1[0], oldColor2[0]) end |
Instance Method Details
#affect(window) ⇒ Object
Affect the window, either overwriting its style or adding to it.
93 94 95 96 97 98 99 |
# File 'lib/muby/style.rb', line 93 def affect(window) if @toAdd window.wattron(to_int(window)) else window.wattrset(to_int(window)) end end |
#get_color_value(fg, bg) ⇒ Object
101 102 103 |
# File 'lib/muby/style.rb', line 101 def get_color_value(fg, bg) Muby::Style::ColorPair.get_pair(fg, bg).to_i end |
#to_int(window) ⇒ Object
Get an int representation of this style, to send to ncurses.
108 109 110 111 112 113 |
# File 'lib/muby/style.rb', line 108 def to_int(window) oldAttributes = self.class.extract(window) color1 = @color1 == :copy ? oldAttributes.color1 : @color1 || conf.default_colors[0] color2 = @color2 == :copy ? oldAttributes.color2 : @color2 || conf.default_colors[1] @attributes | get_color_value(color1, color2) end |