Class: Attr

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

Constant Summary collapse

NAME2COLORS =
{
  "none" => -1,
  "black" => Ncurses::COLOR_BLACK,
  "red" =>  Ncurses::COLOR_RED,
  "green" => Ncurses::COLOR_GREEN,
  "yellow" =>  Ncurses::COLOR_YELLOW,
  "blue" =>  Ncurses::COLOR_BLUE,
  "magenta" => Ncurses::COLOR_MAGENTA,
  "white" => Ncurses::COLOR_WHITE,
}
COLORS =
NAME2COLORS.values
NAME2ATTR =
{
  "normal" => Ncurses::A_NORMAL,
  "standout" => Ncurses::A_STANDOUT,
  "underline" => Ncurses::A_UNDERLINE,
  "dim" => Ncurses::A_DIM,
  "bold" => Ncurses::A_BOLD,
}
ATTRS =
NAME2ATTR.values
DEFAULTS =
{
  :background => NAME2COLORS["none"],
  :foreground => NAME2COLORS["none"],
  :attribute => NAME2ATTR["bold"],
}

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Attr

background, foreground, attribute



36
37
38
39
40
41
42
43
44
45
# 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

Instance Method Details

#namesObject



57
58
59
60
61
62
63
# 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_attributeObject



49
# File 'lib/cless/display.rb', line 49

def next_attribute; @attribute = inc(@attribute, ATTRS); end

#next_backgroundObject



47
# File 'lib/cless/display.rb', line 47

def next_background; @background = inc(@background, COLORS); update_pair; end

#next_foregroundObject



48
# File 'lib/cless/display.rb', line 48

def next_foreground; @foreground = inc(@foreground, COLORS); update_pair; end

#offObject



55
# File 'lib/cless/display.rb', line 55

def off; Ncurses.attroff(@attribute | @pair); end

#onObject



54
# File 'lib/cless/display.rb', line 54

def on; Ncurses.attron(@attribute | @pair); end

#resetObject



52
# File 'lib/cless/display.rb', line 52

def reset; Ncurses.attrset(Ncurses::A_NORMAL); end

#setObject



51
# File 'lib/cless/display.rb', line 51

def set; Ncurses.attrset(@attribute | @pair); end