class Canis::Chunks::Chunk

A chunk is a piece of text with associated color and attr. Several such chunks make a ChunkLine. 2014-05-24 - 11:52 adding parent, and trying to resolve at time of render

so changes in form;s color can take effect without parsing the tree again.

color is a color pair which is already resolved with parent's color at time of parsing. We need to store bgcolor and color so we can resolve at render time if nil.

Attributes

bgcolor[W]
chunk[R]
color_pair of associated text
text to print
attribute of associated text

attr_accessor :color, :text, :attr

hope no one is accessing chunk since format can change to a hash
color[W]
parent[RW]

Public Class Methods

new(color_pair, text, attr) click to toggle source

earlier color was being resolved at parse time. Now with chunk change 2014-05-24 - 12:41

color should be nil if not specified. Do not use parent's color.
Please set fgcolor and bgcolor if present, so we can resolve later.
# File lib/canis/core/include/colorparser.rb, line 38
def initialize color_pair, text, attr
  @chunk = [ color_pair, text, attr ]
  #@color = color
  #@text  = text
  #@attr = attr
end

Public Instance Methods

attr() click to toggle source
# File lib/canis/core/include/colorparser.rb, line 66
def attr
  @chunk[2] || @parent.attr || NORMAL
end
bgcolor() click to toggle source

this returns the bgcolor of this chunk, else goes up the parents, and finally if none, then returns the default bg color (global) set in colormap.rb NOTE: this is used at the time of rendering, not parsing

# File lib/canis/core/include/colorparser.rb, line 84
def bgcolor
  @bgcolor || @parent.bgcolor || $def_bg_color
end
color() click to toggle source

this returns the color of this chunk, else goes up the parents, and finally if none, then returns the default fg color NOTE: this is used at the time of rendering, not parsing

This is to ensure that any changes in widgets colors are reflected in renderings
without requiring the parse to be done again.
Idiealy, the widget would return the form's color if its own was not set, however,
i see that color has been removed from form. It should be there, so it reflects
in all widgets.
# File lib/canis/core/include/colorparser.rb, line 78
def color
  @color || @parent.color || $def_fg_color
end
color_pair() click to toggle source

This is to be called at runtime by render_all or render to resolve the color. @return [color_pair, nil] color pair for chunk, if nil then substitute with

the default which will be form's color. If the form has set fg and bg, then nil
should not be returned ever.
# File lib/canis/core/include/colorparser.rb, line 50
def color_pair
  #@chunk[0]
  # if the color was set, use return it.
  return @chunk[0] if @chunk[0]
  if @color && @bgcolor
    # color was not set, but fg and bg both were
    @chunk[0] = get_color(nil, @color, @bgcolor)
    return @chunk[0] if @chunk[0]
  end
  # return a resolved color_pair if we can, but do not store it in tree.
  # This will be resolved each time render is called from parent.
  return get_color(nil, self.color(), self.bgcolor())
end
text() click to toggle source
# File lib/canis/core/include/colorparser.rb, line 63
def text
  @chunk[1]
end