class DefaultFileRenderer

a simple file renderer that allows setting of colors per line based on regexps passed to insert_mapping. See tasks.rb for example usage.

Attributes

default_colors[RW]
hash[R]

Public Class Methods

new(source=nil) click to toggle source
# File lib/canis/core/include/defaultfilerenderer.rb, line 19
def initialize source=nil
  @default_colors = [:white, :black, NORMAL]
  @pair = get_color($datacolor, @default_colors.first, @default_colors[1])
end

Public Instance Methods

color_mappings(hash) click to toggle source
# File lib/canis/core/include/defaultfilerenderer.rb, line 24
def color_mappings hash
  @hash = hash
end
insert_mapping(regex, dim) click to toggle source

takes a regexp, and an array of color, bgcolor and attr

# File lib/canis/core/include/defaultfilerenderer.rb, line 28
def insert_mapping regex, dim
  @hash ||= {}
  @hash[regex] = dim
end
match_line(line) click to toggle source

matches given line with each regexp to determine color use Internally used by render.

# File lib/canis/core/include/defaultfilerenderer.rb, line 34
def match_line line
  @hash.each_pair {| k , p|
    if line =~ k
      return p
    end
  }
  return @default_colors
end
render(pad, lineno, text) click to toggle source

render given line in color configured using insert_mapping

# File lib/canis/core/include/defaultfilerenderer.rb, line 43
def render pad, lineno, text
  if @hash
    dim = match_line text
    fg = dim.first
    bg = dim[1] || @default_colors[1]
    if dim.size == 3
      att = dim.last
    else
      att = @default_colors.last
    end
    cp = get_color($datacolor, fg, bg)
  else
    cp = @pair
    att = @default_colors[2]
  end

  FFI::NCurses.wattron(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
  FFI::NCurses.mvwaddstr(pad, lineno, 0, text)
  FFI::NCurses.wattroff(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
end