Class: RubyRich::CacheRender
- Inherits:
-
Object
- Object
- RubyRich::CacheRender
- Defined in:
- lib/ruby_rich/live.rb
Instance Method Summary collapse
- #draw(buffer) ⇒ Object
-
#initialize ⇒ CacheRender
constructor
A new instance of CacheRender.
- #print_with_pos(x, y, char) ⇒ Object
Constructor Details
#initialize ⇒ CacheRender
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 |
#print_with_pos(x, y, char) ⇒ Object
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 |