Class: RubyText::Effects
- Inherits:
-
Object
- Object
- RubyText::Effects
- Defined in:
- effects.rb
Overview
Hande text effects (bold, normal, reverse, underline)
Constant Summary collapse
- Modes =
Text modes
{bold: Curses::A_BOLD, normal: Curses::A_NORMAL, reverse: Curses::A_REVERSE, under: Curses::A_UNDERLINE}
- Others =
Other text modes “of our own”
%[:show, :hide]
Instance Attribute Summary collapse
-
#bg ⇒ Object
readonly
show/hide cursor; more later??.
-
#fg ⇒ Object
readonly
show/hide cursor; more later??.
-
#value ⇒ Object
readonly
show/hide cursor; more later??.
Instance Method Summary collapse
-
#initialize(*args, bg: nil) ⇒ Effects
constructor
Initialize an Effects object.
-
#reset(win) ⇒ Object
“Turn off” effect in specified window.
-
#set(win) ⇒ Object
“Turn on” effect to specified window.
Constructor Details
#initialize(*args, bg: nil) ⇒ Effects
Initialize an Effects object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'effects.rb', line 30 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)
show/hide cursor; more later??
24 25 26 |
# File 'effects.rb', line 24 def bg @bg end |
#fg ⇒ Object (readonly)
show/hide cursor; more later??
24 25 26 |
# File 'effects.rb', line 24 def fg @fg end |
#value ⇒ Object (readonly)
show/hide cursor; more later??
24 25 26 |
# File 'effects.rb', line 24 def value @value end |
Instance Method Details
#reset(win) ⇒ Object
“Turn off” effect in specified window
58 59 60 61 62 |
# File 'effects.rb', line 58 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
“Turn on” effect to specified window
47 48 49 50 51 52 53 54 |
# File 'effects.rb', line 47 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 |