class Cygnus::DefaultFileRenderer

a test renderer to see how things go

Public Instance Methods

render(pad, lineno, text) click to toggle source
# File lib/cygnus/textpad.rb, line 856
def render pad, lineno, text
  bg = :black
  fg = :white
  att = NORMAL
  #cp = $datacolor
  cp = get_color($datacolor, fg, bg)
  ## XXX believe it or not, the next line can give you "invalid byte sequence in UTF-8
  # even when processing filename at times. Or if its an mp3 or non-text file.
  if text =~ /^\s*# / || text =~ /^\s*## /
    fg = :red
    #att = BOLD
    cp = get_color($datacolor, fg, bg)
  elsif text =~ /^\s*#/
    fg = :blue
    cp = get_color($datacolor, fg, bg)
  elsif text =~ /^\s*(class|module) /
    fg = :cyan
    att = BOLD
    cp = get_color($datacolor, fg, bg)
  elsif text =~ /^\s*def / || text =~ /^\s*function /
    fg = :yellow
    att = BOLD
    cp = get_color($datacolor, fg, bg)
  elsif text =~ /^\s*(end|if |elsif|else|begin|rescue|ensure|include|extend|while|unless|case |when )/
    fg = :magenta
    att = BOLD
    cp = get_color($datacolor, fg, bg)
  elsif text =~ /^\s*=/
    # rdoc case
    fg = :blue
    bg = :white
    cp = get_color($datacolor, fg, bg)
    att = REVERSE
  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