Class: RubyText::Effects
- Inherits:
-
Object
- Object
- RubyText::Effects
- Defined in:
- lib/effects.rb
Overview
dumb name?
Constant Summary collapse
- Modes =
{bold: X::A_BOLD, normal: X::A_NORMAL, reverse: X::A_REVERSE, under: X::A_UNDERLINE}
- Others =
show/hide cursor; more later??
%[:show, :hide]
Instance Attribute Summary collapse
-
#bg ⇒ Object
readonly
Returns the value of attribute bg.
-
#fg ⇒ Object
readonly
Returns the value of attribute fg.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(*args, bg: nil) ⇒ Effects
constructor
TODO rewrite logic to accommodate color pairs.
- #reset(win) ⇒ Object
- #set(win) ⇒ Object
Constructor Details
#initialize(*args, bg: nil) ⇒ Effects
TODO rewrite logic to accommodate color pairs
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/effects.rb', line 21 def initialize(*args, bg: nil) bits = 0 @list = args args.each do |arg| if Modes.keys.include?(arg) val = Modes[arg] bits |= val elsif ::Colors.include?(arg) @fg = arg # symbol end end @bg = bg || @bg @value = bits end |
Instance Attribute Details
#bg ⇒ Object (readonly)
Returns the value of attribute bg.
17 18 19 |
# File 'lib/effects.rb', line 17 def bg @bg end |
#fg ⇒ Object (readonly)
Returns the value of attribute fg.
17 18 19 |
# File 'lib/effects.rb', line 17 def fg @fg end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
17 18 19 |
# File 'lib/effects.rb', line 17 def value @value end |
Instance Method Details
#reset(win) ⇒ Object
45 46 47 48 49 |
# File 'lib/effects.rb', line 45 def reset(win) attr = self.value win.cwin.attroff(attr) win.set_colors(@old_fg, @old_bg) end |
#set(win) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/effects.rb', line 36 def set(win) @old_fg, @old_bg = win.fg, win.bg # Save off current state? attr, fg, bg = self.value, self.fg, self.bg win.cwin.attron(attr) fg ||= win.fg bg ||= win.bg win.set_colors(fg, bg) end |