Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::FrameWriter Class Reference

Bounded owner of last committed and pending frames; never performs I/O in submit. One executor owns every call and destruction; external synchronization is needed for transfer. The output reference must outlive this non-movable writer. No callbacks, background work or implicit destructor flush. Destroying with pending output requires closing that output session before any other writer is used. A deadline/stop without error retains the exact transaction. Any transport error or inconsistent progress permanently poisons this writer and invalidates its committed frame. Recovery requires closing/joining the old transport, then a new writer whose first full transaction sends CAN and the mode baseline. This requires terminal support for CAN abort of this encoder's CSI/UTF-8 prefixes; arbitrary external output requires an owner-established fresh parser instead. Reopening alone does not reset the parser. Never restart output while the old native worker can write. More...

#include <diff.hpp>

Public Member Functions

 FrameWriter (FrameOutput &output, FrameWriterLimits limits={}, std::shared_ptr< Diagnostics > diagnostics={}) noexcept
 Borrow exclusive output.
 FrameWriter (const FrameWriter &)=delete
 Exclusive output cannot be shared by copying.
FrameWriter & operator= (const FrameWriter &)=delete
 Exclusive output cannot be reassigned.
std::expected< void, FrameError > submit (CellBuffer &&frame, DiagnosticContext context={})
 Encode and take frame only on success; reject busy/poisoned/limits without I/O. Semantically unchanged frames commit immediately without output. Accepted frames invalidate caller views through move; rejection retains them. Allocation errors are returned. Submission invalidates any previously borrowed committed-frame view.
TerminalWrite flush (TerminalDeadline deadline, std::stop_token stop={})
 Perform transport I/O; commit only after complete, consistent progress. Must run outside paint/measure/layout. Stop/deadline without errors retain the frame. An accompanying error normalizes the result status to error and preserves its details. Transport exceptions poison state then propagate; no automatic retry occurs.
const CellBuffer * committedFrame () const noexcept
 Borrow last fully transmitted frame; null initially/after error. This is historical during partial output, not the current physical screen. Expires on successful submit, completing/error flush, or writer destruction.
bool pending () const noexcept
 Whether a transaction still requires completion; no allocation/errors.
bool poisoned () const noexcept
 Whether unknown side effects permanently prohibit further output.

Detailed Description

Bounded owner of last committed and pending frames; never performs I/O in submit. One executor owns every call and destruction; external synchronization is needed for transfer. The output reference must outlive this non-movable writer. No callbacks, background work or implicit destructor flush. Destroying with pending output requires closing that output session before any other writer is used. A deadline/stop without error retains the exact transaction. Any transport error or inconsistent progress permanently poisons this writer and invalidates its committed frame. Recovery requires closing/joining the old transport, then a new writer whose first full transaction sends CAN and the mode baseline. This requires terminal support for CAN abort of this encoder's CSI/UTF-8 prefixes; arbitrary external output requires an owner-established fresh parser instead. Reopening alone does not reset the parser. Never restart output while the old native worker can write.

Constructor & Destructor Documentation

◆ FrameWriter()

portals::FrameWriter::FrameWriter ( FrameOutput & output,
FrameWriterLimits limits = {},
std::shared_ptr< Diagnostics > diagnostics = {} )
explicitnoexcept

Borrow exclusive output.

Parameters
outputTransport that outlives the writer and receives no competing submissions.
limitsPer-transaction output and per-frame storage caps; submit reports any excess.
diagnosticsOptional shared metadata recorder; records no terminal bytes.

Member Function Documentation

◆ committedFrame()

const CellBuffer * portals::FrameWriter::committedFrame ( ) const
nodiscardnoexcept

Borrow last fully transmitted frame; null initially/after error. This is historical during partial output, not the current physical screen. Expires on successful submit, completing/error flush, or writer destruction.

Returns
Borrowed last completed frame, or null when no valid committed belief exists.

◆ flush()

TerminalWrite portals::FrameWriter::flush ( TerminalDeadline deadline,
std::stop_token stop = {} )
nodiscard

Perform transport I/O; commit only after complete, consistent progress. Must run outside paint/measure/layout. Stop/deadline without errors retain the frame. An accompanying error normalizes the result status to error and preserves its details. Transport exceptions poison state then propagate; no automatic retry occurs.

Parameters
deadlineAbsolute monotonic deadline passed to the transport.
stopCooperative stop request for this call.
Returns
Completed and pending bytes with the final status; errors mean the committed belief is invalid.
Note
Exceptions from the output adapter propagate only after the writer is poisoned.

◆ pending()

bool portals::FrameWriter::pending ( ) const
nodiscardnoexcept

Whether a transaction still requires completion; no allocation/errors.

Returns
True while a desired frame still has an incomplete transaction.

◆ poisoned()

bool portals::FrameWriter::poisoned ( ) const
nodiscardnoexcept

Whether unknown side effects permanently prohibit further output.

Returns
True after an uncertain or inconsistent transport result; this state cannot be reset.

◆ submit()

std::expected< void, FrameError > portals::FrameWriter::submit ( CellBuffer && frame,
DiagnosticContext context = {} )
nodiscard

Encode and take frame only on success; reject busy/poisoned/limits without I/O. Semantically unchanged frames commit immediately without output. Accepted frames invalidate caller views through move; rejection retains them. Allocation errors are returned. Submission invalidates any previously borrowed committed-frame view.

Parameters
frameDesired owning frame, consumed only after successful validation and encoding.
contextToken from WidgetTree::diagnosticFrame, linking the actual output to invalidation.
Returns
Success when accepted, or pending, poisoned, FRAME_LIMIT, OUTPUT_LIMIT or ALLOCATION_FAILURE.

The documentation for this class was generated from the following file: