Skip to main content

exeora_cli/workspace/
mod.rs

1mod git;
2mod terminal;
3
4use crate::error::ExeoraError;
5use serde_json::Value;
6use std::{path::Path, sync::Arc};
7use tokio::sync::mpsc;
8use tokio_util::sync::CancellationToken;
9
10pub struct WorkspaceEngine {
11    git: git::GitWorkspace,
12    terminals: terminal::TerminalRegistry,
13}
14
15impl WorkspaceEngine {
16    pub fn new() -> Self {
17        Self {
18            git: git::GitWorkspace::new(),
19            terminals: terminal::TerminalRegistry::new(),
20        }
21    }
22
23    pub async fn execute(
24        &self,
25        root: &Path,
26        action: Value,
27        cancel: CancellationToken,
28    ) -> Result<Value, ExeoraError> {
29        self.git.execute(root, action, cancel).await
30    }
31
32    pub async fn terminal_open(
33        &self,
34        session_id: String,
35        root: &Path,
36        cols: u16,
37        rows: u16,
38        outgoing: mpsc::Sender<Value>,
39    ) -> Result<(), ExeoraError> {
40        self.terminals
41            .open(session_id, root, cols, rows, outgoing)
42            .await
43    }
44
45    pub async fn terminal_input(&self, session_id: &str, data: &[u8]) -> Result<(), ExeoraError> {
46        self.terminals.input(session_id, data).await
47    }
48
49    pub async fn terminal_resize(
50        &self,
51        session_id: &str,
52        cols: u16,
53        rows: u16,
54    ) -> Result<(), ExeoraError> {
55        self.terminals.resize(session_id, cols, rows).await
56    }
57
58    pub async fn terminal_close(&self, session_id: &str) {
59        self.terminals.close(session_id).await;
60    }
61
62    pub async fn kill_all(&self) {
63        self.terminals.kill_all().await;
64    }
65
66    pub async fn kill_root(&self, root: &Path) {
67        self.terminals.kill_root(root).await;
68    }
69}
70
71impl Default for WorkspaceEngine {
72    fn default() -> Self {
73        Self::new()
74    }
75}
76
77pub type SharedWorkspaceEngine = Arc<WorkspaceEngine>;