native macOS codings agent orchestrator prowl.onev.cat
Something went wrong. Try again.
1.3 kB · 36 lines
Swift
12345678910111213141516171819202122232425262728293031323334353637import Foundation
/// Viewport text travels beside the VT frame and becomes visible with that frame's acknowledgement.struct MirrorViewportState { private(set) var text: String? private var pending: MirrorMessage.ViewportPayload? var pendingText: String? { pending?.text } var pendingStyledScrollback: MirrorStyledScrollback? { pending?.styledScrollback } private var receivedSequence: UInt64? private var presentedSequence: UInt64 = 0
mutating func stage(_ payload: MirrorMessage.ViewportPayload) throws { guard pending == nil, payload.sequence > presentedSequence, (payload.text?.utf8.count ?? 0) <= MirrorWire.maximumPayload / 8, payload.styledScrollback?.isValid != false else { throw MirrorProtocolError.invalidMessage } pending = payload }
mutating func receiveFrame(sequence: UInt64) throws { guard pending?.sequence == sequence, receivedSequence == nil else { throw MirrorProtocolError.invalidMessage } receivedSequence = sequence }
mutating func didPresent(sequence: UInt64) throws { guard let pending, pending.sequence == sequence, receivedSequence == sequence else { throw MirrorProtocolError.invalidMessage } text = pending.text presentedSequence = sequence self.pending = nil receivedSequence = nil }}