Class: Charming::Internal::Renderer::Differential
- Inherits:
-
Object
- Object
- Charming::Internal::Renderer::Differential
- Defined in:
- lib/charming/internal/renderer/differential.rb
Overview
Differential renders frame updates by emitting only the lines that changed since the previous frame. On the first frame it falls back to a full repaint; when no lines changed it returns without writing anything.
Instance Method Summary collapse
-
#initialize(output, full_renderer: FullRepaint.new(output)) ⇒ Differential
constructor
output is the terminal backend (must support ‘write_lines` for the differential path or `write_frame` for the fallback).
-
#render(frame) ⇒ Object
Renders frame.
Constructor Details
#initialize(output, full_renderer: FullRepaint.new(output)) ⇒ Differential
output is the terminal backend (must support ‘write_lines` for the differential path or `write_frame` for the fallback). full_renderer is the FullRepaint used for the initial frame and as a fallback when output doesn’t support partial writes.
13 14 15 16 17 |
# File 'lib/charming/internal/renderer/differential.rb', line 13 def initialize(output, full_renderer: FullRepaint.new(output)) @output = output @full_renderer = full_renderer @previous_frame = nil end |
Instance Method Details
#render(frame) ⇒ Object
Renders frame. The first call performs a full repaint and stores the frame. Subsequent calls compute the per-line diff and emit only changed rows. Returns nil when the frame is identical to the previous one.
22 23 24 25 26 27 28 |
# File 'lib/charming/internal/renderer/differential.rb', line 22 def render(frame) frame = frame.to_s return render_initial(frame) unless @previous_frame return if frame == @previous_frame render_changes(frame) end |