PacedTerminalWriter class

Writes PTY output into a Terminal a frame's worth at a time, so a burst of output cannot hold the UI thread for longer than frameBudget.

Handing every chunk straight to Terminal.write as it arrives parses the whole burst at whatever rate the machine manages, and frames happen in the gaps. On a 170x50 grid, 32 MiB of cat-style output measured 566ms to drain and 37 frames per second while it did. The same burst through this writer with the default budget measured 854ms and 75 frames per second - the display's full refresh rate.

So this is a trade, not a free win: output drains around 50% slower and the terminal stays smooth while it does. Which one is right depends on the application. Nothing in the package uses this by default.

final writer = PacedTerminalWriter(terminal);
pty.output.map(utf8.decode).listen(writer.write);
// ...
writer.dispose();

Ordering is preserved: chunks are parsed in the order they were written, and nothing is dropped. There is no back pressure - pending chunks are held until they can be parsed, exactly as the PTY stream's own buffer would hold them.

Constructors

PacedTerminalWriter(Terminal terminal, {Duration frameBudget = const Duration(milliseconds: 8), Future<void> waitForFrame()?, Stopwatch createStopwatch()?})

Properties

frameBudget Duration
How long a single drain pass may spend inside Terminal.write before yielding to let a frame be produced.
final
hashCode int
The hash code for this object.
no setterinherited
hasPendingOutput bool
Whether output is waiting to be parsed.
no setter
pendingChunks int
Number of chunks waiting to be parsed.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
terminal Terminal
final

Methods

dispose() → void
Drops anything not yet written and stops draining.
flush() → void
Writes everything queued, without pacing.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
write(String data) → void
Queues data to be written to the terminal.

Operators

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