Class: TuiTui::CanvasRenderer
- Inherits:
-
Object
- Object
- TuiTui::CanvasRenderer
- Defined in:
- lib/tui_tui/canvas_renderer.rb
Overview
Terminal-facing row rendering and diff helpers for Canvas.
Instance Method Summary collapse
- #changed_span(previous, row) ⇒ Object
-
#initialize(canvas) ⇒ CanvasRenderer
constructor
A new instance of CanvasRenderer.
- #render_row(row, from: 1, to: @canvas.cols, depth: :ansi256, enabled: true) ⇒ Object
- #same_size?(other_canvas) ⇒ Boolean
Constructor Details
#initialize(canvas) ⇒ CanvasRenderer
Returns a new instance of CanvasRenderer.
6 7 8 |
# File 'lib/tui_tui/canvas_renderer.rb', line 6 def initialize(canvas) @canvas = canvas end |
Instance Method Details
#changed_span(previous, row) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tui_tui/canvas_renderer.rb', line 14 def changed_span(previous, row) mine = @canvas.grid_row(row) theirs = previous.grid_row(row) first = last = nil mine.each_index do |i| next if mine[i] == theirs[i] first ||= i last = i end return nil if first.nil? first -= 1 while first.positive? && mine[first].continuation? [first + 1, last + 1] end |
#render_row(row, from: 1, to: @canvas.cols, depth: :ansi256, enabled: true) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tui_tui/canvas_renderer.rb', line 31 def render_row(row, from: 1, to: @canvas.cols, depth: :ansi256, enabled: true) out = +"" run = +"" run_style = :none @canvas.grid_row(row)[(from - 1)..(to - 1)].each do |cell| next if cell.continuation? if run_style != :none && run_style != cell.style out << paint(run, run_style, depth, enabled) run = +"" end run_style = cell.style run << cell.char end out << paint(run, run_style, depth, enabled) unless run.empty? out end |
#same_size?(other_canvas) ⇒ Boolean
10 11 12 |
# File 'lib/tui_tui/canvas_renderer.rb', line 10 def same_size?(other_canvas) other_canvas.rows == @canvas.rows && other_canvas.cols == @canvas.cols end |