Class: RubyRich::CacheRender

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_rich/live.rb

Instance Method Summary collapse

Constructor Details

#initializeCacheRender

Returns a new instance of CacheRender.



11
12
13
# File 'lib/ruby_rich/live.rb', line 11

def initialize
  @cache = nil
end

Instance Method Details

#draw(buffer) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_rich/live.rb', line 20

def draw(buffer)
  unless @cache
    RubyRich::Terminal.clear
    draw_full(buffer)
    @cache = buffer
  else
    buffer.each_with_index do |arr, y|
      arr.each_with_index do |char, x|
        if @cache[y][x] != char
          print_with_pos(x + 1 , y + 1 , char)
          @cache[y][x] = char
        end
      end
    end
  end
end


15
16
17
18
# File 'lib/ruby_rich/live.rb', line 15

def print_with_pos(x,y,char)
  print "\e[#{y};#{x}H"   # Move cursor to top-left
  print char
end