Class: RubyText::Effects

Inherits:
Object
  • Object
show all
Defined in:
lib/effects.rb

Overview

dumb name?

Constant Summary collapse

Modes =
{bold:    Curses::A_BOLD,
normal:  Curses::A_NORMAL,
reverse: Curses::A_REVERSE, 
under:   Curses::A_UNDERLINE}
Others =

show/hide cursor; more later??

%[:show, :hide]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, bg: nil) ⇒ Effects

TODO rewrite logic to accommodate color pairs



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/effects.rb', line 20

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

#bgObject (readonly)

Returns the value of attribute bg.



16
17
18
# File 'lib/effects.rb', line 16

def bg
  @bg
end

#fgObject (readonly)

Returns the value of attribute fg.



16
17
18
# File 'lib/effects.rb', line 16

def fg
  @fg
end

#valueObject (readonly)

Returns the value of attribute value.



16
17
18
# File 'lib/effects.rb', line 16

def value
  @value
end

Instance Method Details

#reset(win) ⇒ Object



44
45
46
47
48
# File 'lib/effects.rb', line 44

def reset(win)
  attr = self.value
  win.cwin.attroff(attr)
  win.set_colors(@old_fg, @old_bg)  # Does restore logic work?
end

#set(win) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/effects.rb', line 35

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