| 1 | use super::ParticipantId; |
| 2 | use serde::{Deserialize, Serialize}; |
| 3 | |
| 4 | /// A monotonically increasing sequence number to identify sequential writes to the pty. |
| 5 | #[derive(Clone, Copy, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)] |
| 6 | pub struct WriteToPtySeqNo(usize); |
| 7 | |
| 8 | impl WriteToPtySeqNo { |
| 9 | pub fn zero() -> Self { |
| 10 | Self(0) |
| 11 | } |
| 12 | |
| 13 | pub fn advance(&mut self) { |
| 14 | self.0 += 1; |
| 15 | } |
| 16 | |
| 17 | pub fn as_usize(&self) -> usize { |
| 18 | self.0 |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | impl From<usize> for WriteToPtySeqNo { |
| 23 | fn from(value: usize) -> Self { |
| 24 | Self(value) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | #[derive(Clone, Debug, Serialize, Deserialize)] |
| 29 | pub struct WriteToPtyRequestId { |
| 30 | pub participant_id: ParticipantId, |
| 31 | pub op_no: WriteToPtySeqNo, |
| 32 | } |
| 33 | |
| 34 | #[derive(Clone, Debug, Serialize, Deserialize)] |
| 35 | pub enum WriteToPtyFailureReason { |
| 36 | /// The viewer does not have sufficient permissions to write to pty. |
| 37 | InsufficientPermissions, |
| 38 | |
| 39 | /// The buffer for which the write to pty was requested is old. |
| 40 | /// Specificaly, there is a new buffer and the command is no longer in-progress. |
| 41 | StaleBuffer, |
| 42 | } |