Class: RubyCurses::Chunks::ColorParser
- Defined in:
- lib/rbcurse/core/include/chunk.rb
Instance Method Summary collapse
- #color_parser(f) ⇒ Object
- #convert_to_chunk(s, colorp = $datacolor, att = FFI::NCurses::A_NORMAL) ⇒ Object
- #get_default_color_parser ⇒ Object
-
#initialize(cp) ⇒ ColorParser
constructor
A new instance of ColorParser.
Constructor Details
#initialize(cp) ⇒ ColorParser
Returns a new instance of ColorParser.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rbcurse/core/include/chunk.rb', line 96 def initialize cp color_parser cp @color_pair = $datacolor @attrib = FFI::NCurses::A_NORMAL @color_array = [:white] @bgcolor_array = [:black] @attrib_array = [@attrib] @color_pair_array = [@color_pair] @color = :white @bgcolor = :black end |
Instance Method Details
#color_parser(f) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rbcurse/core/include/chunk.rb', line 190 def color_parser f $log.debug "XXX: color_parser setting in CP to #{f} " if f == :tmux @color_parser = get_default_color_parser() elsif f == :ansi require 'rbcurse/core/util/ansiparser' @color_parser = AnsiParser.new else @color_parser = f end end |
#convert_to_chunk(s, colorp = $datacolor, att = FFI::NCurses::A_NORMAL) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/rbcurse/core/include/chunk.rb', line 115 def convert_to_chunk s, colorp=$datacolor, att=FFI::NCurses::A_NORMAL #require 'rbcurse/core/include/chunk' @color_parser ||= get_default_color_parser() ## defaults color_pair = @color_pair attrib = @attrib #res = [] res = ChunkLine.new color = @color bgcolor = @bgcolor # stack the values, so when user issues "/end" we can pop earlier ones @color_parser.parse_format(s) do |p| case p when Array ## got color / attrib info, this starts a new span #color, bgcolor, attrib = *p lc, lb, la = *p if la @attrib = get_attrib la end if lc || lb @color = lc ? lc : @color_array.last @bgcolor = lb ? lb : @bgcolor_array.last @color_array << @color @bgcolor_array << @bgcolor @color_pair = get_color($datacolor, @color, @bgcolor) end @color_pair_array << @color_pair @attrib_array << @attrib #$log.debug "XXX: CHUNK start #{color_pair} , #{attrib} :: c:#{lc} b:#{lb} " #$log.debug "XXX: CHUNK start arr #{@color_pair_array} :: #{@attrib_array} " when :endcolor # end the current (last) span @color_pair_array.pop @color_pair = @color_pair_array.last @attrib_array.pop @attrib = @attrib_array.last #$log.debug "XXX: CHUNK end #{color_pair} , #{attrib} " #$log.debug "XXX: CHUNK end arr #{@color_pair_array} :: #{@attrib_array} " when :reset # ansi has this # end all previous colors @color_pair = $datacolor # @color_pair_array.first @color_pair_array = [@color_pair] @attrib = FFI::NCurses::A_NORMAL #@attrib_array.first @attrib_array = [@attrib] @bgcolor_array = [@bgcolor_array.first] @color_array = [@color_array.first] when String ## create the chunk #$log.debug "XXX: CHUNK using on #{p} : #{@color_pair} , #{@attrib} " # 2011-12-10 12:38:51 #chunk = [color_pair, p, attrib] chunk = Chunk.new @color_pair, p, @attrib if block_given? yield chunk else res << chunk end end end # parse return res unless block_given? end |
#get_default_color_parser ⇒ Object
184 185 186 187 |
# File 'lib/rbcurse/core/include/chunk.rb', line 184 def get_default_color_parser require 'rbcurse/core/util/colorparser' @color_parser || DefaultColorParser.new end |