orchflow_terminal/
protocol.rs1use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(tag = "type", content = "payload")]
11pub enum TerminalMessage {
12 Input(TerminalInput),
13 Output(TerminalOutput),
14 Control(ControlMessage),
15 Status(StatusMessage),
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(tag = "type", content = "data")]
21pub enum TerminalInput {
22 Text(String),
24 Binary(Vec<u8>),
26 SpecialKey(String),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct TerminalOutput {
33 pub data: String,
35 pub timestamp: chrono::DateTime<chrono::Utc>,
37 pub sequence: Option<u64>,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(tag = "command", content = "params")]
44pub enum ControlMessage {
45 Resize { rows: u16, cols: u16 },
47 ModeChange { mode: String },
49 Focus,
51 Blur,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(tag = "status")]
58pub enum StatusMessage {
59 Ready {
61 terminal_id: String,
62 rows: u16,
63 cols: u16,
64 },
65 Exited {
67 terminal_id: String,
68 exit_code: Option<i32>,
69 },
70 Error { terminal_id: String, error: String },
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct CreateTerminalOptions {
77 pub id: String,
79 pub shell: Option<String>,
81 pub rows: u16,
83 pub cols: u16,
85 pub cwd: Option<String>,
87 pub env: Option<std::collections::HashMap<String, String>>,
89 pub command: Option<String>,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct BatchInput {
96 pub terminal_id: String,
97 pub inputs: Vec<TerminalInput>,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
102pub struct TerminalMetadata {
103 pub id: String,
104 pub title: String,
105 pub shell: String,
106 pub rows: u16,
107 pub cols: u16,
108 pub created_at: chrono::DateTime<chrono::Utc>,
109 pub last_activity: chrono::DateTime<chrono::Utc>,
110 pub process_id: Option<u32>,
111}
112
113impl TerminalInput {
114 pub fn text(text: impl Into<String>) -> Self {
116 Self::Text(text.into())
117 }
118
119 pub fn key(key: impl Into<String>) -> Self {
121 Self::SpecialKey(key.into())
122 }
123
124 pub fn paste(text: impl Into<String>) -> Self {
126 let text = text.into();
128 Self::Binary(text.as_bytes().to_vec())
129 }
130}