render method

  1. @override
void render(
  1. Object view
)
override

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;
  }

  final output = _options.ansiCompress ? compressAnsi(content) : content;

  if (!terminal.supportsAnsi || _lastFrame == null) {
    _renderFullRedraw(output);
    _lastFrame = _parseFrame(output);
  } else {
    final nextFrame = _parseFrame(output);
    _renderDiffFrame(_lastFrame!, nextFrame);
    _lastFrame = nextFrame;
  }

  _lastView = content;
  // Reset and start the stopwatch for next frame timing
  _frameStopwatch.reset();
  _frameStopwatch.start();
  _metrics.endFrame();
}