CapturedOutputModel class abstract

Optional interface for models that receive captured output automatically.

When a model implements CapturedOutputModel and ProgramOptions.captureOutput is enabled, the runtime automatically appends intercepted print() output to the model's outputLog by calling withOutputLog. The model's update method is not called for CapturedOutputMsg — the runtime handles it entirely.

This follows the same opt-in pattern as FrameTickModel and RenderMetricsModel.

Example

class DebugModel extends Model implements CapturedOutputModel {
  final int count;
  final OutputLog outputLog;

  DebugModel({this.count = 0, this.outputLog = const OutputLog()});

  @override
  DebugModel withOutputLog(OutputLog log) =>
      DebugModel(count: count, outputLog: log);

  @override
  (Model, Cmd?) update(Msg msg) {
    // No need to handle CapturedOutputMsg here —
    // the runtime does it automatically.
    return switch (msg) {
      KeyMsg(key: Key(type: KeyType.runes, runes: [0x71])) =>
        (this, Cmd.quit()),
      _ => (this, null),
    };
  }

  @override
  String view() {
    final buf = StringBuffer('Count: $count\n\n');
    buf.writeln('--- Output Log ---');
    for (final entry in outputLog.entries) {
      buf.writeln(entry);
    }
    return buf.toString();
  }
}

Constructors

CapturedOutputModel()

Properties

hashCode int
The hash code for this object.
no setterinherited
outputLog OutputLog
The current captured output log.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
withOutputLog(OutputLog log) Model
Returns a new model with the given log replacing outputLog.

Operators

operator ==(Object other) bool
The equality operator.
inherited