render method
Renders the view to the terminal.
view is the string representation of the current UI state,
or a View object containing metadata.
Implementation
@override
void render(Object view) {
_metrics.beginFrame();
if (!_initialized) {
initialize();
}
final String content = switch (view) {
String s => s,
View v => v.content,
_ => view.toString(),
};
// Frame rate limiting using Stopwatch (immune to clock adjustments)
if (_frameStopwatch.isRunning) {
if (_frameStopwatch.elapsed < _options.frameTime) {
// Skip this frame
_metrics.endFrame(skipped: true);
return;
}
}
// Skip if view hasn't changed
if (content == _lastView) {
_metrics.endFrame(skipped: true);
return;
}
// Full redraw (future: diff with _lastView and update only changed lines)
terminal.cursorHome();
final output = _options.ansiCompress ? compressAnsi(content) : content;
final mapped = _options.altScreen ? _mapNewlines(output) : output;
terminal.write(mapped);
// Clear any remaining content from previous render
_clearToEndOfScreen(content);
_lastView = content;
// Reset and start the stopwatch for next frame timing
_frameStopwatch.reset();
_frameStopwatch.start();
_metrics.endFrame();
}