class Attr
Constants
- ATTRS
- COLORS
- DEFAULTS
- NAME2ATTR
- NAME2COLORS
Public Class Methods
new(args = {})
click to toggle source
# File lib/cless/display.rb, line 36 def initialize(args = {}) # background, foreground, attribute # Sanitize DEFAULTS.each { |k, v| instance_variable_set("@#{k}", args[k].nil? ? v : args[k]) } @background = check_color(@background) @foreground = check_color(@foreground) @attribute = check_attribute(@attribute) update_pair end
Public Instance Methods
names()
click to toggle source
# File lib/cless/display.rb, line 57 def names r = {} r[:foreground] = (NAME2COLORS.find { |n, v| v == @foreground } || ["black"])[0] r[:background] = (NAME2COLORS.find { |n, v| v == @background } || ["white"])[0] r[:attribute] = (NAME2ATTR.find { |n, v| v == @attribute } || ["normal"])[0] r end
next_attribute()
click to toggle source
# File lib/cless/display.rb, line 49 def next_attribute; @attribute = inc(@attribute, ATTRS); end
next_background()
click to toggle source
# File lib/cless/display.rb, line 47 def next_background; @background = inc(@background, COLORS); update_pair; end
next_foreground()
click to toggle source
# File lib/cless/display.rb, line 48 def next_foreground; @foreground = inc(@foreground, COLORS); update_pair; end
off()
click to toggle source
# File lib/cless/display.rb, line 55 def off; Ncurses.attroff(@attribute | @pair); end
on()
click to toggle source
# File lib/cless/display.rb, line 54 def on; Ncurses.attron(@attribute | @pair); end
reset()
click to toggle source
# File lib/cless/display.rb, line 52 def reset; Ncurses.attrset(Ncurses::A_NORMAL); end
set()
click to toggle source
# File lib/cless/display.rb, line 51 def set; Ncurses.attrset(@attribute | @pair); end
Private Instance Methods
check(c, hash, ary)
click to toggle source
# File lib/cless/display.rb, line 66 def check(c, hash, ary) case c when Integer ary.include?(c) ? c : ary.first when String (v = hash[c.downcase.strip]) ? v : ary.first else ary.first end end
check_attribute(a)
click to toggle source
# File lib/cless/display.rb, line 77 def check_attribute(a); check(a, NAME2ATTR, ATTRS); end
check_color(c)
click to toggle source
# File lib/cless/display.rb, line 76 def check_color(c); check(c, NAME2COLORS, COLORS); end
inc(c, ary)
click to toggle source
# File lib/cless/display.rb, line 79 def inc(c, ary); ary[((ary.index(c) || 0)+1) % ary.size]; end
update_pair()
click to toggle source
# File lib/cless/display.rb, line 81 def update_pair Ncurses.use_default_colors Ncurses.init_pair(1, @foreground, @background) @pair = Ncurses.COLOR_PAIR(1) end