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) {
  _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) {
    // Only skip if the view hasn't changed; otherwise we must render or the
    // terminal can get stuck with stale overlay content.
    if (_frameStopwatch.elapsed < _options.frameTime &&
        content == _pendingView) {
      return;
    }
  }

  _pendingView = _composeView(content);
  _dirty = true;
  // Reset and start the stopwatch for next frame timing
  _frameStopwatch.reset();
  _frameStopwatch.start();

  // Unlike the other renderers, the UV renderer buffers terminal output in
  // its own writer and needs a flush step to emit bytes. Do it immediately
  // so Program doesn't need to coordinate flush ordering with control writes.
  //
  // Also schedule a terminal flush: Program doesn't call TuiRenderer.flush()
  // today, and some terminals won't paint until the underlying sink is
  // flushed.
  _flushInternal();
  unawaited(terminal.flush());
}