1use std::fmt;
4
5use crate::{
6 input::{InputId, InputRequest, InputResult},
7 types::{StateRevision, TerminalDelta, TerminalSnapshot, TerminalState},
8};
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
12pub enum SessionStatus {
13 Connecting,
14 Live,
15 Recovering,
16 Suspended,
17 Closed,
18 Failed,
19}
20
21#[derive(Clone, Copy, Debug, Eq, PartialEq)]
23pub enum SnapshotRequiredReason {
24 NoBase,
25 RevisionGap,
26 InvalidDelta,
27}
28
29#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
31pub struct CommitReceipt(pub(crate) u64);
32
33impl CommitReceipt {
34 pub const fn get(self) -> u64 {
37 self.0
38 }
39}
40
41impl fmt::Debug for CommitReceipt {
42 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
43 formatter.write_str("CommitReceipt(<opaque>)")
44 }
45}
46
47#[derive(Clone, Copy, Debug, Eq, PartialEq)]
49pub enum AcknowledgeResult {
50 Committed,
51 Duplicate,
52 RejectedStale,
53 RejectedUnknown,
54}
55
56#[derive(Clone, Debug, Eq, PartialEq)]
58pub enum TerminalEffect {
59 PrimaryScroll { rows: Vec<crate::PrimaryScrollRow> },
60 Screen { alternate: bool },
61 InputModes { modes: u16 },
62}
63
64#[derive(Clone, Debug, Eq, PartialEq)]
67pub enum SessionEvent {
68 Snapshot {
69 snapshot: TerminalSnapshot,
70 },
71 Delta {
72 delta: TerminalDelta,
73 effects: Vec<TerminalEffect>,
74 receipt: Option<CommitReceipt>,
75 },
76 SnapshotRequired {
77 expected: StateRevision,
78 received: StateRevision,
79 reason: SnapshotRequiredReason,
80 },
81 StatusChanged(SessionStatus),
82 InputQueued {
83 request: InputRequest,
84 },
85 InputCompleted {
86 id: InputId,
87 outcome: crate::InputOutcome,
88 },
89 ConsumerStalled,
90}
91
92impl SessionEvent {
93 pub fn snapshot_state(&self) -> Option<&TerminalState> {
95 match self {
96 Self::Snapshot { snapshot } => Some(&snapshot.state),
97 _ => None,
98 }
99 }
100
101 pub fn input_result(&self) -> Option<InputResult> {
103 match self {
104 Self::InputCompleted { id, outcome } => Some(InputResult {
105 id: *id,
106 outcome: *outcome,
107 }),
108 _ => None,
109 }
110 }
111}