Class: Canis::Chunks::Chunk
- Defined in:
- lib/canis/core/include/colorparser.rb
Overview
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.
Instance Attribute Summary collapse
-
#bgcolor ⇒ Object
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.
-
#chunk ⇒ Object
readonly
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 ⇒ Object
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.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #attr ⇒ Object
-
#color_pair ⇒ color_pair?
This is to be called at runtime by render_all or render to resolve the color.
-
#initialize(color_pair, text, attr) ⇒ Chunk
constructor
earlier color was being resolved at parse time.
- #text ⇒ Object
Constructor Details
#initialize(color_pair, text, attr) ⇒ Chunk
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.
38 39 40 41 42 43 |
# 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 |
Instance Attribute Details
#bgcolor ⇒ Object
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
84 85 86 |
# File 'lib/canis/core/include/colorparser.rb', line 84 def bgcolor @bgcolor || @parent.bgcolor || $def_bg_color end |
#chunk ⇒ Object (readonly)
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
31 32 33 |
# File 'lib/canis/core/include/colorparser.rb', line 31 def chunk @chunk end |
#color ⇒ Object
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.
78 79 80 |
# File 'lib/canis/core/include/colorparser.rb', line 78 def color @color || @parent.color || $def_fg_color end |
#parent ⇒ Object
Returns the value of attribute parent.
32 33 34 |
# File 'lib/canis/core/include/colorparser.rb', line 32 def parent @parent end |
Instance Method Details
#attr ⇒ Object
66 67 68 |
# File 'lib/canis/core/include/colorparser.rb', line 66 def attr @chunk[2] || @parent.attr || NORMAL end |
#color_pair ⇒ color_pair?
This is to be called at runtime by render_all or render to resolve the color.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 ⇒ Object
63 64 65 |
# File 'lib/canis/core/include/colorparser.rb', line 63 def text @chunk[1] end |